Nodes: Panels integration with blend files and UI #111348

Merged
Lukas Tönne merged 96 commits from LukasTonne/blender:node-panels-final into main 2023-08-30 12:37:28 +02:00
1 changed files with 115 additions and 47 deletions
Showing only changes of commit f9e5cb7424 - Show all commits

View File

@ -78,57 +78,125 @@ template<typename T> const T *get_item_as(const bNodeTreeInterfaceItem *item)
namespace socket_types {
constexpr const char *node_socket_data_float = "NodeSocketFloat";
constexpr const char *node_socket_data_int = "NodeSocketInt";
constexpr const char *node_socket_data_bool = "NodeSocketBool";
constexpr const char *node_socket_data_rotation = "NodeSocketRotation";
constexpr const char *node_socket_data_vector = "NodeSocketVector";
constexpr const char *node_socket_data_color = "NodeSocketColor";
constexpr const char *node_socket_data_string = "NodeSocketString";
constexpr const char *node_socket_data_object = "NodeSocketObject";
constexpr const char *node_socket_data_image = "NodeSocketImage";
constexpr const char *node_socket_data_collection = "NodeSocketCollection";
constexpr const char *node_socket_data_texture = "NodeSocketTexture";
constexpr const char *node_socket_data_material = "NodeSocketMaterial";
/* Info for generating static subtypes. */
struct bNodeSocketStaticTypeInfo {
const char *socket_identifier;
const char *interface_identifier;
eNodeSocketDatatype type;
PropertySubType subtype;
const char *label;
};
template<typename Fn> void socket_data_to_static_type(const char *socket_type, const Fn &fn)
/* Note: Socket and interface subtypes could be defined from a single central list,
* but makesrna cannot have a dependency on BKE, so this list would have to live in RNA itself,
* with BKE etc. accessing the RNA API to get the subtypes info. */
static const bNodeSocketStaticTypeInfo node_socket_subtypes[] = {
{"NodeSocketFloat", "NodeTreeInterfaceSocketFloat", SOCK_FLOAT, PROP_NONE},
{"NodeSocketFloatUnsigned", "NodeTreeInterfaceSocketFloatUnsigned", SOCK_FLOAT, PROP_UNSIGNED},
{"NodeSocketFloatPercentage",
"NodeTreeInterfaceSocketFloatPercentage",
SOCK_FLOAT,
PROP_PERCENTAGE},
{"NodeSocketFloatFactor", "NodeTreeInterfaceSocketFloatFactor", SOCK_FLOAT, PROP_FACTOR},
{"NodeSocketFloatAngle", "NodeTreeInterfaceSocketFloatAngle", SOCK_FLOAT, PROP_ANGLE},
{"NodeSocketFloatTime", "NodeTreeInterfaceSocketFloatTime", SOCK_FLOAT, PROP_TIME},
{"NodeSocketFloatTimeAbsolute",
"NodeTreeInterfaceSocketFloatTimeAbsolute",
SOCK_FLOAT,
PROP_TIME_ABSOLUTE},
{"NodeSocketFloatDistance", "NodeTreeInterfaceSocketFloatDistance", SOCK_FLOAT, PROP_DISTANCE},
{"NodeSocketInt", "NodeTreeInterfaceSocketInt", SOCK_INT, PROP_NONE},
{"NodeSocketIntUnsigned", "NodeTreeInterfaceSocketIntUnsigned", SOCK_INT, PROP_UNSIGNED},
{"NodeSocketIntPercentage", "NodeTreeInterfaceSocketIntPercentage", SOCK_INT, PROP_PERCENTAGE},
{"NodeSocketIntFactor", "NodeTreeInterfaceSocketIntFactor", SOCK_INT, PROP_FACTOR},
{"NodeSocketBool", "NodeTreeInterfaceSocketBool", SOCK_BOOLEAN, PROP_NONE},
{"NodeSocketRotation", "NodeTreeInterfaceSocketRotation", SOCK_ROTATION, PROP_NONE},
{"NodeSocketVector", "NodeTreeInterfaceSocketVector", SOCK_VECTOR, PROP_NONE},
{"NodeSocketVectorTranslation",
"NodeTreeInterfaceSocketVectorTranslation",
SOCK_VECTOR,
PROP_TRANSLATION},
{"NodeSocketVectorDirection",
"NodeTreeInterfaceSocketVectorDirection",
SOCK_VECTOR,
PROP_DIRECTION},
{"NodeSocketVectorVelocity",
"NodeTreeInterfaceSocketVectorVelocity",
SOCK_VECTOR,
PROP_VELOCITY},
{"NodeSocketVectorAcceleration",
"NodeTreeInterfaceSocketVectorAcceleration",
SOCK_VECTOR,
PROP_ACCELERATION},
{"NodeSocketVectorEuler", "NodeTreeInterfaceSocketVectorEuler", SOCK_VECTOR, PROP_EULER},
{"NodeSocketVectorXYZ", "NodeTreeInterfaceSocketVectorXYZ", SOCK_VECTOR, PROP_XYZ},
{"NodeSocketColor", "NodeTreeInterfaceSocketColor", SOCK_RGBA, PROP_NONE},
{"NodeSocketString", "NodeTreeInterfaceSocketString", SOCK_STRING, PROP_NONE},
{"NodeSocketShader", "NodeTreeInterfaceSocketShader", SOCK_SHADER, PROP_NONE},
{"NodeSocketObject", "NodeTreeInterfaceSocketObject", SOCK_OBJECT, PROP_NONE},
{"NodeSocketImage", "NodeTreeInterfaceSocketImage", SOCK_IMAGE, PROP_NONE},
{"NodeSocketGeometry", "NodeTreeInterfaceSocketGeometry", SOCK_GEOMETRY, PROP_NONE},
{"NodeSocketCollection", "NodeTreeInterfaceSocketCollection", SOCK_COLLECTION, PROP_NONE},
{"NodeSocketTexture", "NodeTreeInterfaceSocketTexture", SOCK_TEXTURE, PROP_NONE},
{"NodeSocketMaterial", "NodeTreeInterfaceSocketMaterial", SOCK_MATERIAL, PROP_NONE},
};
template<typename Fn> bool socket_data_to_static_type(const eNodeSocketDatatype type, const Fn &fn)
{
if (STREQ(socket_type, socket_types::node_socket_data_float)) {
fn.template operator()<bNodeSocketValueFloat>();
switch (type) {
case SOCK_FLOAT:
fn.template operator()<bNodeSocketValueFloat>();
return true;
case SOCK_INT:
fn.template operator()<bNodeSocketValueInt>();
return true;
case SOCK_BOOLEAN:
fn.template operator()<bNodeSocketValueBoolean>();
return true;
case SOCK_ROTATION:
fn.template operator()<bNodeSocketValueRotation>();
return true;
case SOCK_VECTOR:
fn.template operator()<bNodeSocketValueVector>();
return true;
case SOCK_RGBA:
fn.template operator()<bNodeSocketValueRGBA>();
return true;
case SOCK_STRING:
fn.template operator()<bNodeSocketValueString>();
return true;
case SOCK_OBJECT:
fn.template operator()<bNodeSocketValueObject>();
return true;
case SOCK_IMAGE:
fn.template operator()<bNodeSocketValueImage>();
return true;
case SOCK_COLLECTION:
fn.template operator()<bNodeSocketValueCollection>();
return true;
case SOCK_TEXTURE:
fn.template operator()<bNodeSocketValueTexture>();
return true;
case SOCK_MATERIAL:
fn.template operator()<bNodeSocketValueMaterial>();
return true;
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
return true;
}
else if (STREQ(socket_type, socket_types::node_socket_data_int)) {
fn.template operator()<bNodeSocketValueInt>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_bool)) {
fn.template operator()<bNodeSocketValueBoolean>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_rotation)) {
fn.template operator()<bNodeSocketValueRotation>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_vector)) {
fn.template operator()<bNodeSocketValueVector>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_color)) {
fn.template operator()<bNodeSocketValueRGBA>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_string)) {
fn.template operator()<bNodeSocketValueString>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_object)) {
fn.template operator()<bNodeSocketValueObject>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_image)) {
fn.template operator()<bNodeSocketValueImage>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_collection)) {
fn.template operator()<bNodeSocketValueCollection>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_texture)) {
fn.template operator()<bNodeSocketValueTexture>();
}
else if (STREQ(socket_type, socket_types::node_socket_data_material)) {
fn.template operator()<bNodeSocketValueMaterial>();
return false;
}
template<typename Fn> bool socket_data_to_static_type(const char *socket_type, const Fn &fn)
{
for (const bNodeSocketStaticTypeInfo &info : node_socket_subtypes) {
if (STREQ(socket_type, info.socket_identifier)) {
return socket_data_to_static_type(info.type, fn);
}
}
return false;
}
namespace detail {