Nodes: support accessing socket type directly from declaration #119691
|
@ -373,54 +373,7 @@ static Vector<NodeLinkItem> ui_node_link_items(NodeLinkArg *arg,
|
|||
const SocketDeclaration &socket_decl = *socket_decl_ptr;
|
||||
NodeLinkItem item;
|
||||
item.socket_index = index++;
|
||||
if (dynamic_cast<const decl::Float *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_FLOAT;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Int *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_INT;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Bool *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_BOOLEAN;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Vector *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_VECTOR;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Color *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_RGBA;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Rotation *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_ROTATION;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Matrix *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_MATRIX;
|
||||
}
|
||||
else if (dynamic_cast<const decl::String *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_STRING;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Menu *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_MENU;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Image *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_IMAGE;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Texture *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_TEXTURE;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Material *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_MATERIAL;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Shader *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_SHADER;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Collection *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_COLLECTION;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Object *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_OBJECT;
|
||||
}
|
||||
else {
|
||||
item.socket_type = SOCK_CUSTOM;
|
||||
}
|
||||
item.socket_type = socket_decl.socket_type;
|
||||
item.socket_name = socket_decl.name.c_str();
|
||||
item.node_name = arg->node_type->ui_name;
|
||||
items.append(item);
|
||||
|
|
|
@ -171,6 +171,8 @@ class SocketDeclaration : public ItemDeclaration {
|
|||
/** Defined by whether the socket is part of the node's input or
|
||||
* output socket declaration list. Included here for convenience. */
|
||||
eNodeSocketInOut in_out;
|
||||
/** Socket type that corresponds to this socket declaration. */
|
||||
eNodeSocketDatatype socket_type;
|
||||
bool hide_label = false;
|
||||
bool hide_value = false;
|
||||
bool compact = false;
|
||||
|
@ -682,6 +684,7 @@ inline typename DeclType::Builder &NodeDeclarationBuilder::add_socket(StringRef
|
|||
socket_decl->name = name;
|
||||
socket_decl->identifier = identifier_in.is_empty() ? name : identifier_in;
|
||||
socket_decl->in_out = SOCK_IN;
|
||||
socket_decl->socket_type = DeclType::static_socket_type;
|
||||
socket_decl_builder->index_ = declaration_.inputs.append_and_get_index(socket_decl.get());
|
||||
declaration_.items.append(std::move(socket_decl));
|
||||
input_socket_builders_.append(&*socket_decl_builder);
|
||||
|
@ -693,6 +696,7 @@ inline typename DeclType::Builder &NodeDeclarationBuilder::add_socket(StringRef
|
|||
socket_decl->name = name;
|
||||
socket_decl->identifier = identifier_out.is_empty() ? name : identifier_out;
|
||||
socket_decl->in_out = SOCK_OUT;
|
||||
socket_decl->socket_type = DeclType::static_socket_type;
|
||||
socket_decl_builder->index_ = declaration_.outputs.append_and_get_index(socket_decl.get());
|
||||
declaration_.items.append(std::move(socket_decl));
|
||||
output_socket_builders_.append(&*socket_decl_builder);
|
||||
|
|
|
@ -18,6 +18,8 @@ class FloatBuilder;
|
|||
|
||||
class Float : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_FLOAT;
|
||||
|
||||
float default_value = 0.0f;
|
||||
float soft_min_value = -FLT_MAX;
|
||||
float soft_max_value = FLT_MAX;
|
||||
|
@ -45,6 +47,8 @@ class IntBuilder;
|
|||
|
||||
class Int : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_INT;
|
||||
|
||||
int default_value = 0;
|
||||
int soft_min_value = INT32_MIN;
|
||||
int soft_max_value = INT32_MAX;
|
||||
|
@ -72,6 +76,8 @@ class VectorBuilder;
|
|||
|
||||
class Vector : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_VECTOR;
|
||||
|
||||
float3 default_value = {0, 0, 0};
|
||||
float soft_min_value = -FLT_MAX;
|
||||
float soft_max_value = FLT_MAX;
|
||||
|
@ -100,6 +106,8 @@ class BoolBuilder;
|
|||
|
||||
class Bool : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_BOOLEAN;
|
||||
|
||||
bool default_value = false;
|
||||
friend BoolBuilder;
|
||||
|
||||
|
@ -120,6 +128,8 @@ class ColorBuilder;
|
|||
|
||||
class Color : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_RGBA;
|
||||
|
||||
ColorGeometry4f default_value{0.8f, 0.8f, 0.8f, 1.0f};
|
||||
|
||||
friend ColorBuilder;
|
||||
|
@ -141,6 +151,8 @@ class RotationBuilder;
|
|||
|
||||
class Rotation : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_ROTATION;
|
||||
|
||||
math::EulerXYZ default_value;
|
||||
|
||||
friend RotationBuilder;
|
||||
|
@ -162,6 +174,8 @@ class MatrixBuilder;
|
|||
|
||||
class Matrix : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_MATRIX;
|
||||
|
||||
friend MatrixBuilder;
|
||||
|
||||
using Builder = MatrixBuilder;
|
||||
|
@ -178,6 +192,8 @@ class StringBuilder;
|
|||
|
||||
class String : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_STRING;
|
||||
|
||||
std::string default_value;
|
||||
|
||||
friend StringBuilder;
|
||||
|
@ -199,6 +215,8 @@ class MenuBuilder;
|
|||
|
||||
class Menu : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_MENU;
|
||||
|
||||
int32_t default_value;
|
||||
|
||||
friend MenuBuilder;
|
||||
|
@ -237,6 +255,8 @@ class IDSocketDeclaration : public SocketDeclaration {
|
|||
|
||||
class Object : public IDSocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_OBJECT;
|
||||
|
||||
using Builder = SocketDeclarationBuilder<Object>;
|
||||
|
||||
Object();
|
||||
|
@ -244,6 +264,8 @@ class Object : public IDSocketDeclaration {
|
|||
|
||||
class Material : public IDSocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_MATERIAL;
|
||||
|
||||
using Builder = SocketDeclarationBuilder<Material>;
|
||||
|
||||
Material();
|
||||
|
@ -251,6 +273,8 @@ class Material : public IDSocketDeclaration {
|
|||
|
||||
class Collection : public IDSocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_COLLECTION;
|
||||
|
||||
using Builder = SocketDeclarationBuilder<Collection>;
|
||||
|
||||
Collection();
|
||||
|
@ -258,6 +282,8 @@ class Collection : public IDSocketDeclaration {
|
|||
|
||||
class Texture : public IDSocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_TEXTURE;
|
||||
|
||||
using Builder = SocketDeclarationBuilder<Texture>;
|
||||
|
||||
Texture();
|
||||
|
@ -265,6 +291,8 @@ class Texture : public IDSocketDeclaration {
|
|||
|
||||
class Image : public IDSocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_IMAGE;
|
||||
|
||||
using Builder = SocketDeclarationBuilder<Image>;
|
||||
|
||||
Image();
|
||||
|
@ -274,6 +302,8 @@ class ShaderBuilder;
|
|||
|
||||
class Shader : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_SHADER;
|
||||
|
||||
friend ShaderBuilder;
|
||||
|
||||
using Builder = ShaderBuilder;
|
||||
|
@ -292,6 +322,8 @@ class Extend : public SocketDeclaration {
|
|||
friend ExtendBuilder;
|
||||
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_CUSTOM;
|
||||
|
||||
using Builder = ExtendBuilder;
|
||||
|
||||
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
|
||||
|
@ -304,6 +336,8 @@ class ExtendBuilder : public SocketDeclarationBuilder<Extend> {};
|
|||
|
||||
class Custom : public SocketDeclaration {
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_CUSTOM;
|
||||
|
||||
const char *idname_;
|
||||
std::function<void(bNode &node, bNodeSocket &socket, const char *data_path)> init_socket_fn;
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ class Geometry : public SocketDeclaration {
|
|||
friend GeometryBuilder;
|
||||
|
||||
public:
|
||||
static constexpr eNodeSocketDatatype static_socket_type = SOCK_GEOMETRY;
|
||||
|
||||
using Builder = GeometryBuilder;
|
||||
|
||||
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
|
||||
|
|
|
@ -368,7 +368,7 @@ static PanelDeclarationPtr declaration_for_interface_panel(const bNodeTree & /*n
|
|||
|
||||
static void set_default_input_field(const bNodeTreeInterfaceSocket &input, SocketDeclaration &decl)
|
||||
{
|
||||
if (dynamic_cast<decl::Vector *>(&decl)) {
|
||||
if (decl.socket_type == SOCK_VECTOR) {
|
||||
if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_NORMAL_FIELD) {
|
||||
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
|
||||
implicit_field_inputs::normal);
|
||||
|
@ -380,7 +380,7 @@ static void set_default_input_field(const bNodeTreeInterfaceSocket &input, Socke
|
|||
decl.hide_value = true;
|
||||
}
|
||||
}
|
||||
else if (dynamic_cast<decl::Int *>(&decl)) {
|
||||
else if (decl.socket_type == SOCK_INT) {
|
||||
if (input.default_input == GEO_NODE_DEFAULT_FIELD_INPUT_INDEX_FIELD) {
|
||||
decl.implicit_input_fn = std::make_unique<ImplicitInputValueFn>(
|
||||
implicit_field_inputs::index);
|
||||
|
|
|
@ -277,60 +277,6 @@ static void refresh_node_panel(const PanelDeclaration &panel_decl,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not great to have this here, but this is only for forward compatibility, so this code shouldn't
|
||||
* in the `main` branch.
|
||||
*/
|
||||
static std::optional<eNodeSocketDatatype> decl_to_data_type(const SocketDeclaration &socket_decl)
|
||||
{
|
||||
if (dynamic_cast<const decl::Float *>(&socket_decl)) {
|
||||
return SOCK_FLOAT;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Int *>(&socket_decl)) {
|
||||
return SOCK_INT;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Bool *>(&socket_decl)) {
|
||||
return SOCK_BOOLEAN;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Vector *>(&socket_decl)) {
|
||||
return SOCK_VECTOR;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Color *>(&socket_decl)) {
|
||||
return SOCK_RGBA;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Rotation *>(&socket_decl)) {
|
||||
return SOCK_ROTATION;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Matrix *>(&socket_decl)) {
|
||||
return SOCK_MATRIX;
|
||||
}
|
||||
else if (dynamic_cast<const decl::String *>(&socket_decl)) {
|
||||
return SOCK_STRING;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Image *>(&socket_decl)) {
|
||||
return SOCK_IMAGE;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Texture *>(&socket_decl)) {
|
||||
return SOCK_TEXTURE;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Material *>(&socket_decl)) {
|
||||
return SOCK_MATERIAL;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Shader *>(&socket_decl)) {
|
||||
return SOCK_SHADER;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Collection *>(&socket_decl)) {
|
||||
return SOCK_COLLECTION;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Object *>(&socket_decl)) {
|
||||
return SOCK_OBJECT;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Geometry *>(&socket_decl)) {
|
||||
return SOCK_GEOMETRY;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static const char *get_identifier_from_decl(const char *identifier_prefix,
|
||||
const bNodeSocket &socket,
|
||||
const Span<const SocketDeclaration *> socket_decls)
|
||||
|
@ -340,7 +286,7 @@ static const char *get_identifier_from_decl(const char *identifier_prefix,
|
|||
}
|
||||
for (const SocketDeclaration *socket_decl : socket_decls) {
|
||||
if (BLI_str_startswith(socket_decl->identifier.c_str(), identifier_prefix)) {
|
||||
if (socket.type == decl_to_data_type(*socket_decl)) {
|
||||
if (socket.type == socket_decl->socket_type) {
|
||||
return socket_decl->identifier.c_str();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue