Matrix operations and sockets for geometry nodes #105408
|
@ -1567,6 +1567,10 @@ struct TexResult;
|
|||
#define FN_NODE_INPUT_INT 1220
|
||||
#define FN_NODE_SEPARATE_COLOR 1221
|
||||
#define FN_NODE_COMBINE_COLOR 1222
|
||||
#define FN_NODE_INPUT_MATRIX 1223
|
||||
#define FN_NODE_SEPARATE_MATRIX 1224
|
||||
#define FN_NODE_COMBINE_MATRIX 1225
|
||||
#define FN_NODE_MATRIX_MATH 1226
|
||||
|
||||
/** \} */
|
||||
|
||||
|
|
|
@ -382,6 +382,12 @@ static Vector<NodeLinkItem> ui_node_link_items(NodeLinkArg *arg,
|
|||
else if (dynamic_cast<const decl::Vector *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_VECTOR;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Matrix3x3 *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_MATRIX3x3;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Matrix4x4 *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_MATRIX4x4;
|
||||
}
|
||||
else if (dynamic_cast<const decl::Color *>(&socket_decl)) {
|
||||
item.socket_type = SOCK_RGBA;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "RNA_types.h"
|
||||
|
||||
#include "BLI_color.hh"
|
||||
#include "BLI_float3x3.hh"
|
||||
#include "BLI_float4x4.hh"
|
||||
#include "BLI_math_vec_types.hh"
|
||||
|
||||
namespace blender::nodes::decl {
|
||||
|
@ -96,6 +98,58 @@ class VectorBuilder : public SocketDeclarationBuilder<Vector> {
|
|||
VectorBuilder &compact();
|
||||
};
|
||||
|
||||
class Matrix3x3Builder;
|
||||
|
||||
class Matrix3x3 : public SocketDeclaration {
|
||||
private:
|
||||
float3x3 default_value_ = float3x3::identity();
|
||||
float soft_min_value_ = -FLT_MAX;
|
||||
float soft_max_value_ = FLT_MAX;
|
||||
|
||||
friend Matrix3x3Builder;
|
||||
|
||||
public:
|
||||
using Builder = Matrix3x3Builder;
|
||||
|
||||
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
|
||||
bool matches(const bNodeSocket &socket) const override;
|
||||
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
|
||||
bool can_connect(const bNodeSocket &socket) const override;
|
||||
};
|
||||
|
||||
class Matrix3x3Builder : public SocketDeclarationBuilder<Matrix3x3> {
|
||||
public:
|
||||
Matrix3x3Builder &default_value(const float3x3 value);
|
||||
Matrix3x3Builder &min(float min);
|
||||
Matrix3x3Builder &max(float max);
|
||||
};
|
||||
|
||||
class Matrix4x4Builder;
|
||||
|
||||
class Matrix4x4 : public SocketDeclaration {
|
||||
private:
|
||||
float4x4 default_value_ = float4x4::identity();
|
||||
float soft_min_value_ = -FLT_MAX;
|
||||
float soft_max_value_ = FLT_MAX;
|
||||
|
||||
friend Matrix4x4Builder;
|
||||
|
||||
public:
|
||||
using Builder = Matrix4x4Builder;
|
||||
|
||||
bNodeSocket &build(bNodeTree &ntree, bNode &node) const override;
|
||||
bool matches(const bNodeSocket &socket) const override;
|
||||
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;
|
||||
bool can_connect(const bNodeSocket &socket) const override;
|
||||
};
|
||||
|
||||
class Matrix4x4Builder : public SocketDeclarationBuilder<Matrix4x4> {
|
||||
public:
|
||||
Matrix4x4Builder &default_value(const float4x4 value);
|
||||
Matrix4x4Builder &min(float min);
|
||||
Matrix4x4Builder &max(float max);
|
||||
};
|
||||
|
||||
class BoolBuilder;
|
||||
|
||||
class Bool : public SocketDeclaration {
|
||||
|
|
|
@ -279,6 +279,10 @@ DefNode(FunctionNode, FN_NODE_SEPARATE_COLOR, def_fn_combsep_color, "SEPARATE_CO
|
|||
DefNode(FunctionNode, FN_NODE_SLICE_STRING, 0, "SLICE_STRING", SliceString, "Slice String", "")
|
||||
DefNode(FunctionNode, FN_NODE_STRING_LENGTH, 0, "STRING_LENGTH", StringLength, "String Length", "")
|
||||
DefNode(FunctionNode, FN_NODE_VALUE_TO_STRING, 0, "VALUE_TO_STRING", ValueToString, "Value to String", "")
|
||||
DefNode(FunctionNode, FN_NODE_INPUT_MATRIX, 0, "INPUT_MATRIX", InputMatrix, "Matrix", "")
|
||||
DefNode(FunctionNode, FN_NODE_SEPARATE_MATRIX, 0, "SEPARATE_MATRIX", SeparateMatrix, "Separate Matrix", "")
|
||||
DefNode(FunctionNode, FN_NODE_COMBINE_MATRIX, 0, "COMBINE_MATRIX", CombineMatrix, "Combine Matrix", "")
|
||||
DefNode(FunctionNode, FN_NODE_MATRIX_MATH, 0, "MATRIX_MATH", MatrixMath, "Matrix Math", "")
|
||||
|
||||
DefNode(GeometryNode, GEO_NODE_ACCUMULATE_FIELD, def_geo_accumulate_field, "ACCUMULATE_FIELD", AccumulateField, "Accumulate Field", "Add the values of an evaluated field together and output the running total for each element")
|
||||
DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_DOMAIN_SIZE, def_geo_attribute_domain_size, "ATTRIBUTE_DOMAIN_SIZE", AttributeDomainSize, "Domain Size", "Retrieve the number of elements in a geometry for each attribute domain")
|
||||
|
|
|
@ -21,18 +21,22 @@ set(SRC
|
|||
nodes/node_fn_align_euler_to_vector.cc
|
||||
nodes/node_fn_boolean_math.cc
|
||||
nodes/node_fn_combine_color.cc
|
||||
nodes/node_fn_combine_matrix.cc
|
||||
nodes/node_fn_compare.cc
|
||||
nodes/node_fn_float_to_int.cc
|
||||
nodes/node_fn_input_bool.cc
|
||||
nodes/node_fn_input_color.cc
|
||||
nodes/node_fn_input_int.cc
|
||||
nodes/node_fn_input_matrix.cc
|
||||
nodes/node_fn_input_special_characters.cc
|
||||
nodes/node_fn_input_string.cc
|
||||
nodes/node_fn_input_vector.cc
|
||||
nodes/node_fn_matrix_math.cc
|
||||
nodes/node_fn_random_value.cc
|
||||
nodes/node_fn_replace_string.cc
|
||||
nodes/node_fn_rotate_euler.cc
|
||||
nodes/node_fn_separate_color.cc
|
||||
nodes/node_fn_separate_matrix.cc
|
||||
nodes/node_fn_slice_string.cc
|
||||
nodes/node_fn_string_length.cc
|
||||
nodes/node_fn_value_to_string.cc
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "node_function_util.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
namespace blender::nodes::node_fn_combine_color_cc {
|
||||
|
||||
NODE_STORAGE_FUNCS(NodeCombSepColor)
|
||||
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.is_function_node();
|
||||
b.add_input<decl::Float>(N_("Red")).default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Green"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Blue"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Alpha"))
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_output<decl::Color>(N_("Color"));
|
||||
};
|
||||
|
||||
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_update(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(*node);
|
||||
node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
|
||||
}
|
||||
|
||||
static void node_init(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
|
||||
data->mode = NODE_COMBSEP_COLOR_RGB;
|
||||
node->storage = data;
|
||||
}
|
||||
|
||||
static const fn::MultiFunction *get_multi_function(const bNode &bnode)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(bnode);
|
||||
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> rgba_fn{
|
||||
"RGB", [](float r, float g, float b, float a) { return ColorGeometry4f(r, g, b, a); }};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsva_fn{
|
||||
"HSV", [](float h, float s, float v, float a) {
|
||||
ColorGeometry4f r_color;
|
||||
hsv_to_rgb(h, s, v, &r_color.r, &r_color.g, &r_color.b);
|
||||
r_color.a = a;
|
||||
return r_color;
|
||||
}};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsla_fn{
|
||||
"HSL", [](float h, float s, float l, float a) {
|
||||
ColorGeometry4f color;
|
||||
hsl_to_rgb(h, s, l, &color.r, &color.g, &color.b);
|
||||
color.a = a;
|
||||
return color;
|
||||
}};
|
||||
|
||||
switch (storage.mode) {
|
||||
case NODE_COMBSEP_COLOR_RGB:
|
||||
return &rgba_fn;
|
||||
case NODE_COMBSEP_COLOR_HSV:
|
||||
return &hsva_fn;
|
||||
case NODE_COMBSEP_COLOR_HSL:
|
||||
return &hsla_fn;
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
const fn::MultiFunction *fn = get_multi_function(builder.node());
|
||||
builder.set_matching_fn(fn);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_fn_combine_color_cc
|
||||
|
||||
void register_node_type_fn_combine_color(void)
|
||||
{
|
||||
namespace file_ns = blender::nodes::node_fn_combine_color_cc;
|
||||
|
||||
static bNodeType ntype;
|
||||
|
||||
fn_node_type_base(&ntype, FN_NODE_COMBINE_COLOR, "Combine Color", NODE_CLASS_CONVERTER);
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.updatefunc = file_ns::node_update;
|
||||
ntype.initfunc = file_ns::node_init;
|
||||
node_type_storage(
|
||||
&ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
|
||||
ntype.build_multi_function = file_ns::node_build_multi_function;
|
||||
ntype.draw_buttons = file_ns::node_layout;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "node_function_util.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
namespace blender::nodes::node_fn_combine_color_cc {
|
||||
|
||||
NODE_STORAGE_FUNCS(NodeCombSepColor)
|
||||
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.is_function_node();
|
||||
b.add_input<decl::Float>(N_("Red")).default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Green"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Blue"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Alpha"))
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_output<decl::Color>(N_("Color"));
|
||||
};
|
||||
|
||||
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_update(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(*node);
|
||||
node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
|
||||
}
|
||||
|
||||
static void node_init(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
|
||||
data->mode = NODE_COMBSEP_COLOR_RGB;
|
||||
node->storage = data;
|
||||
}
|
||||
|
||||
static const fn::MultiFunction *get_multi_function(const bNode &bnode)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(bnode);
|
||||
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> rgba_fn{
|
||||
"RGB", [](float r, float g, float b, float a) { return ColorGeometry4f(r, g, b, a); }};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsva_fn{
|
||||
"HSV", [](float h, float s, float v, float a) {
|
||||
ColorGeometry4f r_color;
|
||||
hsv_to_rgb(h, s, v, &r_color.r, &r_color.g, &r_color.b);
|
||||
r_color.a = a;
|
||||
return r_color;
|
||||
}};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsla_fn{
|
||||
"HSL", [](float h, float s, float l, float a) {
|
||||
ColorGeometry4f color;
|
||||
hsl_to_rgb(h, s, l, &color.r, &color.g, &color.b);
|
||||
color.a = a;
|
||||
return color;
|
||||
}};
|
||||
|
||||
switch (storage.mode) {
|
||||
case NODE_COMBSEP_COLOR_RGB:
|
||||
return &rgba_fn;
|
||||
case NODE_COMBSEP_COLOR_HSV:
|
||||
return &hsva_fn;
|
||||
case NODE_COMBSEP_COLOR_HSL:
|
||||
return &hsla_fn;
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
const fn::MultiFunction *fn = get_multi_function(builder.node());
|
||||
builder.set_matching_fn(fn);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_fn_combine_color_cc
|
||||
|
||||
void register_node_type_fn_combine_color(void)
|
||||
{
|
||||
namespace file_ns = blender::nodes::node_fn_combine_color_cc;
|
||||
|
||||
static bNodeType ntype;
|
||||
|
||||
fn_node_type_base(&ntype, FN_NODE_COMBINE_COLOR, "Combine Color", NODE_CLASS_CONVERTER);
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.updatefunc = file_ns::node_update;
|
||||
ntype.initfunc = file_ns::node_init;
|
||||
node_type_storage(
|
||||
&ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
|
||||
ntype.build_multi_function = file_ns::node_build_multi_function;
|
||||
ntype.draw_buttons = file_ns::node_layout;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "node_function_util.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
namespace blender::nodes::node_fn_combine_color_cc {
|
||||
|
||||
NODE_STORAGE_FUNCS(NodeCombSepColor)
|
||||
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.is_function_node();
|
||||
b.add_input<decl::Float>(N_("Red")).default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Green"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Blue"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Alpha"))
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_output<decl::Color>(N_("Color"));
|
||||
};
|
||||
|
||||
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_update(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(*node);
|
||||
node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
|
||||
}
|
||||
|
||||
static void node_init(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
|
||||
data->mode = NODE_COMBSEP_COLOR_RGB;
|
||||
node->storage = data;
|
||||
}
|
||||
|
||||
static const fn::MultiFunction *get_multi_function(const bNode &bnode)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(bnode);
|
||||
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> rgba_fn{
|
||||
"RGB", [](float r, float g, float b, float a) { return ColorGeometry4f(r, g, b, a); }};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsva_fn{
|
||||
"HSV", [](float h, float s, float v, float a) {
|
||||
ColorGeometry4f r_color;
|
||||
hsv_to_rgb(h, s, v, &r_color.r, &r_color.g, &r_color.b);
|
||||
r_color.a = a;
|
||||
return r_color;
|
||||
}};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsla_fn{
|
||||
"HSL", [](float h, float s, float l, float a) {
|
||||
ColorGeometry4f color;
|
||||
hsl_to_rgb(h, s, l, &color.r, &color.g, &color.b);
|
||||
color.a = a;
|
||||
return color;
|
||||
}};
|
||||
|
||||
switch (storage.mode) {
|
||||
case NODE_COMBSEP_COLOR_RGB:
|
||||
return &rgba_fn;
|
||||
case NODE_COMBSEP_COLOR_HSV:
|
||||
return &hsva_fn;
|
||||
case NODE_COMBSEP_COLOR_HSL:
|
||||
return &hsla_fn;
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
const fn::MultiFunction *fn = get_multi_function(builder.node());
|
||||
builder.set_matching_fn(fn);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_fn_combine_color_cc
|
||||
|
||||
void register_node_type_fn_combine_color(void)
|
||||
{
|
||||
namespace file_ns = blender::nodes::node_fn_combine_color_cc;
|
||||
|
||||
static bNodeType ntype;
|
||||
|
||||
fn_node_type_base(&ntype, FN_NODE_COMBINE_COLOR, "Combine Color", NODE_CLASS_CONVERTER);
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.updatefunc = file_ns::node_update;
|
||||
ntype.initfunc = file_ns::node_init;
|
||||
node_type_storage(
|
||||
&ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
|
||||
ntype.build_multi_function = file_ns::node_build_multi_function;
|
||||
ntype.draw_buttons = file_ns::node_layout;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "node_function_util.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
namespace blender::nodes::node_fn_combine_color_cc {
|
||||
|
||||
NODE_STORAGE_FUNCS(NodeCombSepColor)
|
||||
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.is_function_node();
|
||||
b.add_input<decl::Float>(N_("Red")).default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Green"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Blue"))
|
||||
.default_value(0.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("Alpha"))
|
||||
.default_value(1.0f)
|
||||
.min(0.0f)
|
||||
.max(1.0f)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_output<decl::Color>(N_("Color"));
|
||||
};
|
||||
|
||||
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_update(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(*node);
|
||||
node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
|
||||
}
|
||||
|
||||
static void node_init(bNodeTree * /*tree*/, bNode *node)
|
||||
{
|
||||
NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
|
||||
data->mode = NODE_COMBSEP_COLOR_RGB;
|
||||
node->storage = data;
|
||||
}
|
||||
|
||||
static const fn::MultiFunction *get_multi_function(const bNode &bnode)
|
||||
{
|
||||
const NodeCombSepColor &storage = node_storage(bnode);
|
||||
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> rgba_fn{
|
||||
"RGB", [](float r, float g, float b, float a) { return ColorGeometry4f(r, g, b, a); }};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsva_fn{
|
||||
"HSV", [](float h, float s, float v, float a) {
|
||||
ColorGeometry4f r_color;
|
||||
hsv_to_rgb(h, s, v, &r_color.r, &r_color.g, &r_color.b);
|
||||
r_color.a = a;
|
||||
return r_color;
|
||||
}};
|
||||
static fn::CustomMF_SI_SI_SI_SI_SO<float, float, float, float, ColorGeometry4f> hsla_fn{
|
||||
"HSL", [](float h, float s, float l, float a) {
|
||||
ColorGeometry4f color;
|
||||
hsl_to_rgb(h, s, l, &color.r, &color.g, &color.b);
|
||||
color.a = a;
|
||||
return color;
|
||||
}};
|
||||
|
||||
switch (storage.mode) {
|
||||
case NODE_COMBSEP_COLOR_RGB:
|
||||
return &rgba_fn;
|
||||
case NODE_COMBSEP_COLOR_HSV:
|
||||
return &hsva_fn;
|
||||
case NODE_COMBSEP_COLOR_HSL:
|
||||
return &hsla_fn;
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
const fn::MultiFunction *fn = get_multi_function(builder.node());
|
||||
builder.set_matching_fn(fn);
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_fn_combine_color_cc
|
||||
|
||||
void register_node_type_fn_combine_color(void)
|
||||
{
|
||||
namespace file_ns = blender::nodes::node_fn_combine_color_cc;
|
||||
|
||||
static bNodeType ntype;
|
||||
|
||||
fn_node_type_base(&ntype, FN_NODE_COMBINE_COLOR, "Combine Color", NODE_CLASS_CONVERTER);
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.updatefunc = file_ns::node_update;
|
||||
ntype.initfunc = file_ns::node_init;
|
||||
node_type_storage(
|
||||
&ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
|
||||
ntype.build_multi_function = file_ns::node_build_multi_function;
|
||||
ntype.draw_buttons = file_ns::node_layout;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
|
@ -248,6 +248,118 @@ bNodeSocket &Vector::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name #Matrix3x3
|
||||
* \{ */
|
||||
|
||||
bNodeSocket &Matrix3x3::build(bNodeTree &ntree, bNode &node) const
|
||||
{
|
||||
bNodeSocket &socket = *nodeAddStaticSocket(
|
||||
&ntree, &node, in_out_, SOCK_MATRIX3x3, PROP_MATRIX, identifier_.c_str(), name_.c_str());
|
||||
this->set_common_flags(socket);
|
||||
bNodeSocketValueMatrix3x3 &value = *(bNodeSocketValueMatrix3x3 *)socket.default_value;
|
||||
copy_m3_m3(value.value, default_value_.ptr());
|
||||
value.min = soft_min_value_;
|
||||
value.max = soft_max_value_;
|
||||
return socket;
|
||||
}
|
||||
|
||||
bool Matrix3x3::matches(const bNodeSocket &socket) const
|
||||
{
|
||||
if (!this->matches_common_data(socket)) {
|
||||
return false;
|
||||
}
|
||||
if (socket.type != SOCK_MATRIX3x3) {
|
||||
return false;
|
||||
}
|
||||
if (socket.typeinfo->subtype != PROP_MATRIX) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Matrix3x3::can_connect(const bNodeSocket &socket) const
|
||||
{
|
||||
if (!sockets_can_connect(*this, socket)) {
|
||||
return false;
|
||||
}
|
||||
return basic_types_can_connect(*this, socket);
|
||||
}
|
||||
|
||||
bNodeSocket &Matrix3x3::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const
|
||||
{
|
||||
if (socket.type != SOCK_MATRIX3x3) {
|
||||
BLI_assert(socket.in_out == in_out_);
|
||||
return this->build(ntree, node);
|
||||
}
|
||||
if (socket.typeinfo->subtype != PROP_MATRIX) {
|
||||
modify_subtype_except_for_storage(socket, PROP_MATRIX);
|
||||
}
|
||||
this->set_common_flags(socket);
|
||||
bNodeSocketValueMatrix3x3 &value = *(bNodeSocketValueMatrix3x3 *)socket.default_value;
|
||||
value.subtype = PROP_MATRIX;
|
||||
STRNCPY(socket.name, name_.c_str());
|
||||
return socket;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name #Matrix4x4
|
||||
* \{ */
|
||||
|
||||
bNodeSocket &Matrix4x4::build(bNodeTree &ntree, bNode &node) const
|
||||
{
|
||||
bNodeSocket &socket = *nodeAddStaticSocket(
|
||||
&ntree, &node, in_out_, SOCK_MATRIX4x4, PROP_MATRIX, identifier_.c_str(), name_.c_str());
|
||||
this->set_common_flags(socket);
|
||||
bNodeSocketValueMatrix4x4 &value = *(bNodeSocketValueMatrix4x4 *)socket.default_value;
|
||||
copy_m4_m4(value.value, default_value_.ptr());
|
||||
value.min = soft_min_value_;
|
||||
value.max = soft_max_value_;
|
||||
return socket;
|
||||
}
|
||||
|
||||
bool Matrix4x4::matches(const bNodeSocket &socket) const
|
||||
{
|
||||
if (!this->matches_common_data(socket)) {
|
||||
return false;
|
||||
}
|
||||
if (socket.type != SOCK_MATRIX4x4) {
|
||||
return false;
|
||||
}
|
||||
if (socket.typeinfo->subtype != PROP_MATRIX) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Matrix4x4::can_connect(const bNodeSocket &socket) const
|
||||
{
|
||||
if (!sockets_can_connect(*this, socket)) {
|
||||
return false;
|
||||
}
|
||||
return basic_types_can_connect(*this, socket);
|
||||
}
|
||||
|
||||
bNodeSocket &Matrix4x4::update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const
|
||||
{
|
||||
if (socket.type != SOCK_MATRIX4x4) {
|
||||
BLI_assert(socket.in_out == in_out_);
|
||||
return this->build(ntree, node);
|
||||
}
|
||||
if (socket.typeinfo->subtype != PROP_MATRIX) {
|
||||
modify_subtype_except_for_storage(socket, PROP_MATRIX);
|
||||
}
|
||||
this->set_common_flags(socket);
|
||||
bNodeSocketValueMatrix4x4 &value = *(bNodeSocketValueMatrix4x4 *)socket.default_value;
|
||||
value.subtype = PROP_MATRIX;
|
||||
STRNCPY(socket.name, name_.c_str());
|
||||
return socket;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name #Bool
|
||||
* \{ */
|
||||
|
|
Loading…
Reference in New Issue