1
1

Compare commits

...

6 Commits

Author SHA1 Message Date
b25697b884 cleanup and fix 2021-09-15 13:51:49 +02:00
608c4d40a1 cleanup 2021-09-15 14:33:10 +02:00
d021d633ff cleanup 2021-09-15 13:54:04 +02:00
0c2c2af0aa update remaining node 2021-09-15 13:37:57 +02:00
2ffa956983 cleanup 2021-09-15 13:19:36 +02:00
19d2f7d9cf separate declaration from buildrs 2021-09-15 12:43:49 +02:00
8 changed files with 382 additions and 329 deletions

View File

@@ -27,12 +27,19 @@ namespace blender::nodes {
class NodeDeclarationBuilder;
/**
* Describes a single input or output socket. This is subclassed for different socket types.
*/
class SocketDeclaration {
protected:
std::string name_;
std::string identifier_;
bool hide_label_ = false;
bool hide_value_ = false;
bool is_multi_input_ = false;
friend NodeDeclarationBuilder;
template<typename SocketDecl> friend class SocketDeclarationBuilder;
public:
virtual ~SocketDeclaration() = default;
@@ -43,6 +50,49 @@ class SocketDeclaration {
StringRefNull name() const;
StringRefNull identifier() const;
protected:
void set_common_flags(bNodeSocket &socket) const;
bool matches_common_data(const bNodeSocket &socket) const;
};
class BaseSocketDeclarationBuilder {
public:
virtual ~BaseSocketDeclarationBuilder() = default;
};
/**
* Wraps a #SocketDeclaration and provides methods to set it up correctly.
* This is separate from #SocketDeclaration, because it allows separating the API used by nodes to
* declare themselves from how the declaration is stored internally.
*/
template<typename SocketDecl>
class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
protected:
using Self = typename SocketDecl::Builder;
static_assert(std::is_base_of_v<SocketDeclaration, SocketDecl>);
SocketDecl *decl_;
friend class NodeDeclarationBuilder;
public:
Self &hide_label(bool value)
{
decl_->hide_label_ = value;
return *(Self *)this;
}
Self &hide_value(bool value)
{
decl_->hide_value_ = value;
return *(Self *)this;
}
Self &multi_input(bool value)
{
decl_->is_multi_input_ = value;
return *(Self *)this;
}
};
using SocketDeclarationPtr = std::unique_ptr<SocketDeclaration>;
@@ -67,12 +117,21 @@ class NodeDeclaration {
class NodeDeclarationBuilder {
private:
NodeDeclaration &declaration_;
Vector<std::unique_ptr<BaseSocketDeclarationBuilder>> builders_;
public:
NodeDeclarationBuilder(NodeDeclaration &declaration);
template<typename DeclType> DeclType &add_input(StringRef name, StringRef identifier = "");
template<typename DeclType> DeclType &add_output(StringRef name, StringRef identifier = "");
template<typename DeclType>
typename DeclType::Builder &add_input(StringRef name, StringRef identifier = "");
template<typename DeclType>
typename DeclType::Builder &add_output(StringRef name, StringRef identifier = "");
private:
template<typename DeclType>
typename DeclType::Builder &add_socket(StringRef name,
StringRef identifier,
Vector<SocketDeclarationPtr> &r_decls);
};
/* --------------------------------------------------------------------
@@ -99,27 +158,34 @@ inline NodeDeclarationBuilder::NodeDeclarationBuilder(NodeDeclaration &declarati
}
template<typename DeclType>
inline DeclType &NodeDeclarationBuilder::add_input(StringRef name, StringRef identifier)
inline typename DeclType::Builder &NodeDeclarationBuilder::add_input(StringRef name,
StringRef identifier)
{
static_assert(std::is_base_of_v<SocketDeclaration, DeclType>);
std::unique_ptr<DeclType> socket_decl = std::make_unique<DeclType>();
DeclType &ref = *socket_decl;
ref.name_ = name;
ref.identifier_ = identifier.is_empty() ? name : identifier;
declaration_.inputs_.append(std::move(socket_decl));
return ref;
return this->add_socket<DeclType>(name, identifier, declaration_.inputs_);
}
template<typename DeclType>
inline DeclType &NodeDeclarationBuilder::add_output(StringRef name, StringRef identifier)
inline typename DeclType::Builder &NodeDeclarationBuilder::add_output(StringRef name,
StringRef identifier)
{
return this->add_socket<DeclType>(name, identifier, declaration_.outputs_);
}
template<typename DeclType>
inline typename DeclType::Builder &NodeDeclarationBuilder::add_socket(
StringRef name, StringRef identifier, Vector<SocketDeclarationPtr> &r_decls)
{
static_assert(std::is_base_of_v<SocketDeclaration, DeclType>);
using Builder = typename DeclType::Builder;
std::unique_ptr<DeclType> socket_decl = std::make_unique<DeclType>();
DeclType &ref = *socket_decl;
ref.name_ = name;
ref.identifier_ = identifier.is_empty() ? name : identifier;
declaration_.outputs_.append(std::move(socket_decl));
return ref;
std::unique_ptr<Builder> socket_decl_builder = std::make_unique<Builder>();
socket_decl_builder->decl_ = &*socket_decl;
socket_decl->name_ = name;
socket_decl->identifier_ = identifier.is_empty() ? name : identifier;
r_decls.append(std::move(socket_decl));
Builder &socket_decl_builder_ref = *socket_decl_builder;
builders_.append(std::move(socket_decl_builder));
return socket_decl_builder_ref;
}
/* --------------------------------------------------------------------

View File

@@ -25,6 +25,8 @@
namespace blender::nodes::decl {
class FloatBuilder;
class Float : public SocketDeclaration {
private:
float default_value_ = 0.0f;
@@ -32,36 +34,45 @@ class Float : public SocketDeclaration {
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
friend FloatBuilder;
public:
Float &min(const float value)
{
soft_min_value_ = value;
return *this;
}
Float &max(const float value)
{
soft_max_value_ = value;
return *this;
}
Float &default_value(const float value)
{
default_value_ = value;
return *this;
}
Float &subtype(PropertySubType subtype)
{
subtype_ = subtype;
return *this;
}
using Builder = FloatBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
class FloatBuilder : public SocketDeclarationBuilder<Float> {
public:
FloatBuilder &min(const float value)
{
decl_->soft_min_value_ = value;
return *this;
}
FloatBuilder &max(const float value)
{
decl_->soft_max_value_ = value;
return *this;
}
FloatBuilder &default_value(const float value)
{
decl_->default_value_ = value;
return *this;
}
FloatBuilder &subtype(PropertySubType subtype)
{
decl_->subtype_ = subtype;
return *this;
}
};
class IntBuilder;
class Int : public SocketDeclaration {
private:
int default_value_ = 0;
@@ -69,36 +80,45 @@ class Int : public SocketDeclaration {
int soft_max_value_ = INT32_MAX;
PropertySubType subtype_ = PROP_NONE;
friend IntBuilder;
public:
Int &min(const int value)
{
soft_min_value_ = value;
return *this;
}
Int &max(const int value)
{
soft_max_value_ = value;
return *this;
}
Int &default_value(const int value)
{
default_value_ = value;
return *this;
}
Int &subtype(PropertySubType subtype)
{
subtype_ = subtype;
return *this;
}
using Builder = IntBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
class IntBuilder : public SocketDeclarationBuilder<Int> {
public:
IntBuilder &min(const int value)
{
decl_->soft_min_value_ = value;
return *this;
}
IntBuilder &max(const int value)
{
decl_->soft_max_value_ = value;
return *this;
}
IntBuilder &default_value(const int value)
{
decl_->default_value_ = value;
return *this;
}
IntBuilder &subtype(PropertySubType subtype)
{
decl_->subtype_ = subtype;
return *this;
}
};
class VectorBuilder;
class Vector : public SocketDeclaration {
private:
float3 default_value_ = {0, 0, 0};
@@ -106,160 +126,152 @@ class Vector : public SocketDeclaration {
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
friend VectorBuilder;
public:
Vector &default_value(const float3 value)
using Builder = VectorBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
class VectorBuilder : public SocketDeclarationBuilder<Vector> {
public:
VectorBuilder &default_value(const float3 value)
{
default_value_ = value;
decl_->default_value_ = value;
return *this;
}
Vector &subtype(PropertySubType subtype)
VectorBuilder &subtype(PropertySubType subtype)
{
subtype_ = subtype;
decl_->subtype_ = subtype;
return *this;
}
Vector &min(const float min)
VectorBuilder &min(const float min)
{
soft_min_value_ = min;
decl_->soft_min_value_ = min;
return *this;
}
Vector &max(const float max)
VectorBuilder &max(const float max)
{
soft_max_value_ = max;
decl_->soft_max_value_ = max;
return *this;
}
};
class BoolBuilder;
class Bool : public SocketDeclaration {
private:
bool default_value_ = false;
friend BoolBuilder;
public:
using Builder = BoolBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
class BoolBuilder : public SocketDeclarationBuilder<Bool> {
public:
BoolBuilder &default_value(const bool value)
{
decl_->default_value_ = value;
return *this;
}
};
class ColorBuilder;
class Color : public SocketDeclaration {
private:
ColorGeometry4f default_value_;
friend ColorBuilder;
public:
using Builder = ColorBuilder;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
class ColorBuilder : public SocketDeclarationBuilder<Color> {
public:
ColorBuilder &default_value(const ColorGeometry4f value)
{
decl_->default_value_ = value;
return *this;
}
};
class String : public SocketDeclaration {
public:
using Builder = SocketDeclarationBuilder<String>;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
class IDSocketDeclaration : public SocketDeclaration {
private:
const char *idname_;
public:
IDSocketDeclaration(const char *idname) : idname_(idname)
{
}
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
};
class Bool : public SocketDeclaration {
private:
bool default_value_ = false;
class Object : public IDSocketDeclaration {
public:
Bool &default_value(const bool value)
{
default_value_ = value;
return *this;
}
using Builder = SocketDeclarationBuilder<Object>;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
class Color : public SocketDeclaration {
private:
ColorGeometry4f default_value_;
public:
Color &default_value(const ColorGeometry4f value)
{
default_value_ = value;
return *this;
}
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
class String : public SocketDeclaration {
public:
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};
namespace detail {
struct CommonIDSocketData {
const char *idname;
bool hide_label = false;
};
bNodeSocket &build_id_socket(bNodeTree &ntree,
bNode &node,
eNodeSocketInOut in_out,
const CommonIDSocketData &data,
StringRefNull name,
StringRefNull identifier);
bool matches_id_socket(const bNodeSocket &socket,
const CommonIDSocketData &data,
StringRefNull name,
StringRefNull identifier);
template<typename Subtype> class IDSocketDeclaration : public SocketDeclaration {
private:
CommonIDSocketData data_;
public:
IDSocketDeclaration(const char *idname) : data_({idname})
{
}
Subtype &hide_label(bool value)
{
data_.hide_label = value;
return *(Subtype *)this;
}
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override
{
return build_id_socket(ntree, node, in_out, data_, name_, identifier_);
}
bool matches(const bNodeSocket &socket) const override
{
return matches_id_socket(socket, data_, name_, identifier_);
}
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override
{
if (StringRef(socket.idname) != data_.idname) {
return this->build(ntree, node, (eNodeSocketInOut)socket.in_out);
}
if (data_.hide_label) {
socket.flag |= SOCK_HIDE_LABEL;
}
else {
socket.flag &= ~SOCK_HIDE_LABEL;
}
return socket;
}
};
} // namespace detail
class Object : public detail::IDSocketDeclaration<Object> {
public:
Object() : detail::IDSocketDeclaration<Object>("NodeSocketObject")
Object() : IDSocketDeclaration("NodeSocketObject")
{
}
};
class Material : public detail::IDSocketDeclaration<Material> {
class Material : public IDSocketDeclaration {
public:
Material() : detail::IDSocketDeclaration<Material>("NodeSocketMaterial")
using Builder = SocketDeclarationBuilder<Material>;
Material() : IDSocketDeclaration("NodeSocketMaterial")
{
}
};
class Collection : public detail::IDSocketDeclaration<Collection> {
class Collection : public IDSocketDeclaration {
public:
Collection() : detail::IDSocketDeclaration<Collection>("NodeSocketCollection")
using Builder = SocketDeclarationBuilder<Collection>;
Collection() : IDSocketDeclaration("NodeSocketCollection")
{
}
};
class Texture : public detail::IDSocketDeclaration<Texture> {
class Texture : public IDSocketDeclaration {
public:
Texture() : detail::IDSocketDeclaration<Texture>("NodeSocketTexture")
using Builder = SocketDeclarationBuilder<Texture>;
Texture() : IDSocketDeclaration("NodeSocketTexture")
{
}
};
class Geometry : public SocketDeclaration {
public:
using Builder = SocketDeclarationBuilder<Geometry>;
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
};

View File

@@ -16,28 +16,15 @@
#include "node_geometry_util.hh"
static bNodeSocketTemplate geo_node_attribute_remove_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING,
N_("Attribute"),
0.0f,
0.0f,
0.0f,
1.0f,
-1.0f,
1.0f,
PROP_NONE,
SOCK_MULTI_INPUT},
{-1, ""},
};
static bNodeSocketTemplate geo_node_attribute_remove_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{-1, ""},
};
namespace blender::nodes {
static void geo_node_attribute_remove_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Geometry");
b.add_input<decl::String>("Attribute").multi_input(true);
b.add_output<decl::Geometry>("Geometry");
}
static void remove_attribute(GeometryComponent &component,
GeoNodeExecParams &params,
Span<std::string> attribute_names)
@@ -85,7 +72,7 @@ void register_node_type_geo_attribute_remove()
geo_node_type_base(
&ntype, GEO_NODE_ATTRIBUTE_REMOVE, "Attribute Remove", NODE_CLASS_ATTRIBUTE, 0);
node_type_socket_templates(&ntype, geo_node_attribute_remove_in, geo_node_attribute_remove_out);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_remove_exec;
ntype.declare = blender::nodes::geo_node_attribute_remove_declare;
nodeRegisterType(&ntype);
}

View File

@@ -21,27 +21,26 @@
#include "UI_interface.h"
#include "UI_resources.h"
static bNodeSocketTemplate geo_node_attribute_vector_rotate_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING, N_("Vector")},
{SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
{SOCK_STRING, N_("Center")},
{SOCK_VECTOR, N_("Center"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_XYZ},
{SOCK_STRING, N_("Axis")},
{SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_XYZ, PROP_NONE},
{SOCK_STRING, N_("Angle")},
{SOCK_FLOAT, N_("Angle"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_ANGLE, PROP_NONE},
{SOCK_STRING, N_("Rotation")},
{SOCK_VECTOR, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER},
{SOCK_BOOLEAN, N_("Invert")},
{SOCK_STRING, N_("Result")},
{-1, ""},
};
namespace blender::nodes {
static bNodeSocketTemplate geo_node_attribute_vector_rotate_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{-1, ""},
};
static void geo_node_attribute_vector_rotate_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Geometry");
b.add_input<decl::String>("Vector");
b.add_input<decl::Vector>("Vector", "Vector_001").min(0.0f).max(1.0f).hide_value(true);
b.add_input<decl::String>("Center");
b.add_input<decl::Vector>("Center", "Center_001").subtype(PROP_XYZ);
b.add_input<decl::String>("Axis");
b.add_input<decl::Vector>("Axis", "Axis_001").min(-1.0f).max(1.0f).subtype(PROP_XYZ);
b.add_input<decl::String>("Angle");
b.add_input<decl::Float>("Angle", "Angle_001").subtype(PROP_ANGLE);
b.add_input<decl::String>("Rotation");
b.add_input<decl::Vector>("Rotation", "Rotation_001").subtype(PROP_EULER);
b.add_input<decl::Bool>("Invert");
b.add_input<decl::String>("Result");
b.add_output<decl::Geometry>("Geometry");
}
static void geo_node_attribute_vector_rotate_layout(uiLayout *layout,
bContext *UNUSED(C),
@@ -71,8 +70,6 @@ static void geo_node_attribute_vector_rotate_layout(uiLayout *layout,
}
}
namespace blender::nodes {
static void geo_node_attribute_vector_rotate_update(bNodeTree *UNUSED(ntree), bNode *node)
{
const NodeAttributeVectorRotate *node_storage = (NodeAttributeVectorRotate *)node->storage;
@@ -339,14 +336,13 @@ void register_node_type_geo_attribute_vector_rotate()
"Attribute Vector Rotate",
NODE_CLASS_ATTRIBUTE,
0);
node_type_socket_templates(
&ntype, geo_node_attribute_vector_rotate_in, geo_node_attribute_vector_rotate_out);
node_type_update(&ntype, blender::nodes::geo_node_attribute_vector_rotate_update);
node_type_init(&ntype, blender::nodes::geo_node_attribute_vector_rotate_init);
node_type_size(&ntype, 165, 100, 600);
node_type_storage(
&ntype, "NodeAttributeVectorRotate", node_free_standard_storage, node_copy_standard_storage);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_vector_rotate_exec;
ntype.draw_buttons = geo_node_attribute_vector_rotate_layout;
ntype.draw_buttons = blender::nodes::geo_node_attribute_vector_rotate_layout;
ntype.declare = blender::nodes::geo_node_attribute_vector_rotate_declare;
nodeRegisterType(&ntype);
}

View File

@@ -23,27 +23,16 @@
#include "node_geometry_util.hh"
static bNodeSocketTemplate geo_node_boolean_in[] = {
{SOCK_GEOMETRY, N_("Geometry 1")},
{SOCK_GEOMETRY,
N_("Geometry 2"),
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
PROP_NONE,
SOCK_MULTI_INPUT},
{SOCK_BOOLEAN, N_("Self Intersection")},
{SOCK_BOOLEAN, N_("Hole Tolerant")},
{-1, ""},
};
namespace blender::nodes {
static bNodeSocketTemplate geo_node_boolean_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{-1, ""},
};
static void geo_node_boolean_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Geometry 1");
b.add_input<decl::Geometry>("Geometry 2").multi_input(true);
b.add_input<decl::Bool>("Self Intersection");
b.add_input<decl::Bool>("Hole Tolerant");
b.add_output<decl::Geometry>("Geometry");
}
static void geo_node_boolean_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
@@ -77,8 +66,6 @@ static void geo_node_boolean_init(bNodeTree *UNUSED(tree), bNode *node)
node->custom1 = GEO_NODE_BOOLEAN_DIFFERENCE;
}
namespace blender::nodes {
static void geo_node_boolean_exec(GeoNodeExecParams params)
{
GeometryNodeBooleanOperation operation = (GeometryNodeBooleanOperation)params.node().custom1;
@@ -138,10 +125,10 @@ void register_node_type_geo_boolean()
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_BOOLEAN, "Boolean", NODE_CLASS_GEOMETRY, 0);
node_type_socket_templates(&ntype, geo_node_boolean_in, geo_node_boolean_out);
ntype.draw_buttons = geo_node_boolean_layout;
ntype.updatefunc = geo_node_boolean_update;
node_type_init(&ntype, geo_node_boolean_init);
ntype.declare = blender::nodes::geo_node_boolean_declare;
ntype.draw_buttons = blender::nodes::geo_node_boolean_layout;
ntype.updatefunc = blender::nodes::geo_node_boolean_update;
node_type_init(&ntype, blender::nodes::geo_node_boolean_init);
ntype.geometry_node_execute = blender::nodes::geo_node_boolean_exec;
nodeRegisterType(&ntype);
}

View File

@@ -29,27 +29,14 @@
using blender::fn::GVArray_For_GSpan;
static bNodeSocketTemplate geo_node_join_geometry_in[] = {
{SOCK_GEOMETRY,
N_("Geometry"),
0.0f,
0.0f,
0.0f,
1.0f,
-1.0f,
1.0f,
PROP_NONE,
SOCK_MULTI_INPUT},
{-1, ""},
};
static bNodeSocketTemplate geo_node_join_geometry_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{-1, ""},
};
namespace blender::nodes {
static void geo_node_join_geometry_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Geometry").multi_input(true);
b.add_output<decl::Geometry>("Geometry");
}
static Mesh *join_mesh_topology_and_builtin_attributes(Span<const MeshComponent *> src_components)
{
int totverts = 0;
@@ -508,7 +495,7 @@ void register_node_type_geo_join_geometry()
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_JOIN_GEOMETRY, "Join Geometry", NODE_CLASS_GEOMETRY, 0);
node_type_socket_templates(&ntype, geo_node_join_geometry_in, geo_node_join_geometry_out);
ntype.geometry_node_execute = blender::nodes::geo_node_join_geometry_exec;
ntype.declare = blender::nodes::geo_node_join_geometry_declare;
nodeRegisterType(&ntype);
}

View File

@@ -16,6 +16,8 @@
#include "NOD_node_declaration.hh"
#include "BKE_node.h"
namespace blender::nodes {
void NodeDeclaration::build(bNodeTree &ntree, bNode &node) const
@@ -62,4 +64,31 @@ bNodeSocket &SocketDeclaration::update_or_build(bNodeTree &ntree,
return this->build(ntree, node, (eNodeSocketInOut)socket.in_out);
}
void SocketDeclaration::set_common_flags(bNodeSocket &socket) const
{
SET_FLAG_FROM_TEST(socket.flag, hide_value_, SOCK_HIDE_VALUE);
SET_FLAG_FROM_TEST(socket.flag, hide_label_, SOCK_HIDE_LABEL);
SET_FLAG_FROM_TEST(socket.flag, is_multi_input_, SOCK_MULTI_INPUT);
}
bool SocketDeclaration::matches_common_data(const bNodeSocket &socket) const
{
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
if (((socket.flag & SOCK_HIDE_VALUE) != 0) != hide_value_) {
return false;
}
if (((socket.flag & SOCK_HIDE_LABEL) != 0) != hide_label_) {
return false;
}
if (((socket.flag & SOCK_MULTI_INPUT) != 0) != is_multi_input_) {
return false;
}
return true;
}
} // namespace blender::nodes

View File

@@ -38,6 +38,7 @@ bNodeSocket &Float::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_FLOAT, subtype_, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -47,18 +48,15 @@ bNodeSocket &Float::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
bool Float::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_FLOAT) {
return false;
}
if (socket.typeinfo->subtype != subtype_) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
if (value.min != soft_min_value_) {
return false;
@@ -77,6 +75,7 @@ bNodeSocket &Float::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
}
this->set_common_flags(socket);
bNodeSocketValueFloat &value = *(bNodeSocketValueFloat *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -92,6 +91,7 @@ bNodeSocket &Int::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_INT, subtype_, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -101,18 +101,15 @@ bNodeSocket &Int::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
bool Int::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_INT) {
return false;
}
if (socket.typeinfo->subtype != subtype_) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
if (value.min != soft_min_value_) {
return false;
@@ -131,6 +128,7 @@ bNodeSocket &Int::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &so
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
}
this->set_common_flags(socket);
bNodeSocketValueInt &value = *(bNodeSocketValueInt *)socket.default_value;
value.min = soft_min_value_;
value.max = soft_max_value_;
@@ -146,6 +144,7 @@ bNodeSocket &Vector::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_VECTOR, subtype_, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
copy_v3_v3(value.value, default_value_);
value.min = soft_min_value_;
@@ -155,18 +154,15 @@ bNodeSocket &Vector::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
bool Vector::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_VECTOR) {
return false;
}
if (socket.typeinfo->subtype != subtype_) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
return true;
}
@@ -178,6 +174,7 @@ bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket
if (socket.typeinfo->subtype != subtype_) {
modify_subtype_except_for_storage(socket, subtype_);
}
this->set_common_flags(socket);
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
value.subtype = subtype_;
STRNCPY(socket.name, name_.c_str());
@@ -192,6 +189,7 @@ bNodeSocket &Bool::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_BOOLEAN, PROP_NONE, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
bNodeSocketValueBoolean &value = *(bNodeSocketValueBoolean *)socket.default_value;
value.value = default_value_;
return socket;
@@ -199,15 +197,12 @@ bNodeSocket &Bool::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
bool Bool::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_BOOLEAN) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
return true;
}
@@ -219,6 +214,7 @@ bNodeSocket &Color::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_RGBA, PROP_NONE, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
bNodeSocketValueRGBA &value = *(bNodeSocketValueRGBA *)socket.default_value;
copy_v4_v4(value.value, default_value_);
return socket;
@@ -226,15 +222,17 @@ bNodeSocket &Color::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out
bool Color::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
}
if (socket.type != SOCK_RGBA) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
return true;
}
@@ -246,20 +244,18 @@ bNodeSocket &String::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
{
bNodeSocket &socket = *nodeAddStaticSocket(
&ntree, &node, in_out, SOCK_STRING, PROP_NONE, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
return socket;
}
bool String::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_STRING) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
return true;
}
@@ -267,42 +263,37 @@ bool String::matches(const bNodeSocket &socket) const
* IDSocketDeclaration.
*/
namespace detail {
bNodeSocket &build_id_socket(bNodeTree &ntree,
bNode &node,
eNodeSocketInOut in_out,
const CommonIDSocketData &data,
StringRefNull name,
StringRefNull identifier)
bNodeSocket &IDSocketDeclaration::build(bNodeTree &ntree,
bNode &node,
eNodeSocketInOut in_out) const
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out, data.idname, identifier.c_str(), name.c_str());
if (data.hide_label) {
socket.flag |= SOCK_HIDE_LABEL;
}
&ntree, &node, in_out, idname_, identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
return socket;
}
bool matches_id_socket(const bNodeSocket &socket,
const CommonIDSocketData &data,
StringRefNull name,
StringRefNull identifier)
bool IDSocketDeclaration::matches(const bNodeSocket &socket) const
{
if (!STREQ(socket.idname, data.idname)) {
if (!this->matches_common_data(socket)) {
return false;
}
if (data.hide_label != ((socket.flag & SOCK_HIDE_LABEL) != 0)) {
return false;
}
if (socket.name != name) {
return false;
}
if (socket.identifier != identifier) {
if (!STREQ(socket.idname, idname_)) {
return false;
}
return true;
}
} // namespace detail
bNodeSocket &IDSocketDeclaration::update_or_build(bNodeTree &ntree,
bNode &node,
bNodeSocket &socket) const
{
if (StringRef(socket.idname) != idname_) {
return this->build(ntree, node, (eNodeSocketInOut)socket.in_out);
}
this->set_common_flags(socket);
return socket;
}
/* --------------------------------------------------------------------
* Geometry.
@@ -312,20 +303,18 @@ bNodeSocket &Geometry::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
{
bNodeSocket &socket = *nodeAddSocket(
&ntree, &node, in_out, "NodeSocketGeometry", identifier_.c_str(), name_.c_str());
this->set_common_flags(socket);
return socket;
}
bool Geometry::matches(const bNodeSocket &socket) const
{
if (!this->matches_common_data(socket)) {
return false;
}
if (socket.type != SOCK_GEOMETRY) {
return false;
}
if (socket.name != name_) {
return false;
}
if (socket.identifier != identifier_) {
return false;
}
return true;
}