Geometry Nodes: Matrix socket type, attribute type, and initial nodes #116166

Merged
Hans Goudey merged 47 commits from HooglyBoogly/blender:nodes-matrix-socket into main 2024-02-13 18:59:46 +01:00
2 changed files with 48 additions and 5 deletions
Showing only changes of commit 974f2f6a96 - Show all commits

View File

@ -6,6 +6,11 @@
#include "DNA_object_types.h"
#include "NOD_rna_define.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_object_transform_cc {
@ -16,6 +21,11 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Matrix>("Transform");
}
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
}
static void node_geo_exec(GeoNodeExecParams params)
{
const Object *object = params.get_input<Object *>("Object");
@ -23,9 +33,40 @@ static void node_geo_exec(GeoNodeExecParams params)
params.set_default_remaining_outputs();
return;
}
const Object *self_object = params.self_object();
params.set_output("Transform",
float4x4(self_object->world_to_object) * float4x4(object->object_to_world));
if (params.node().custom1 == GEO_NODE_TRANSFORM_SPACE_RELATIVE) {
params.set_output("Transform",
float4x4(params.self_object()->world_to_object) *
float4x4(object->object_to_world));
}
else {
params.set_output("Transform", float4x4(object->object_to_world));
}
}
static void node_rna(StructRNA *srna)
{
static const EnumPropertyItem rna_node_geometry_object_info_transform_space_items[] = {
{GEO_NODE_TRANSFORM_SPACE_ORIGINAL,
"ORIGINAL",
0,
"Original",
"Output the transform relative to the world origin"},
{GEO_NODE_TRANSFORM_SPACE_RELATIVE,
"RELATIVE",
0,
"Relative",
"Bring the object's transform into the modified object's space, "
"maintaining the relative position between the two objects"},
{0, nullptr, 0, nullptr, nullptr},
};
RNA_def_node_enum(srna,
"transform_space",
"Transform Space",
"",
rna_node_geometry_object_info_transform_space_items,
NOD_inline_enum_accessors(custom1),
GEO_NODE_TRANSFORM_SPACE_ORIGINAL);
}
static void node_register()
@ -34,7 +75,10 @@ static void node_register()
geo_node_type_base(&ntype, GEO_NODE_OBJECT_TRANSFORM, "Object Transform", NODE_CLASS_INPUT);
ntype.geometry_node_execute = node_geo_exec;
ntype.declare = node_declare;
ntype.draw_buttons = node_layout;
nodeRegisterType(&ntype);
node_rna(ntype.rna_ext.srna);
}
NOD_REGISTER_NODE(node_register)

View File

@ -90,9 +90,8 @@ static bool node_needs_own_transform_relation(const bNode &node)
node.storage);
return storage.transform_space == GEO_NODE_TRANSFORM_SPACE_RELATIVE;
}
if (node.type == GEO_NODE_OBJECT_TRANSFORM) {
return true;
return node.custom1 == GEO_NODE_TRANSFORM_SPACE_RELATIVE;
}
if (node.type == GEO_NODE_SELF_OBJECT) {
return true;