Blender V4.3
node_geo_transform_geometry.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_matrix.hh"
7#include "BLI_task.hh"
8
9#include "NOD_rna_define.hh"
10
11#include "GEO_transform.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "node_geometry_util.hh"
17
19
21{
22 auto enable_components = [](bNode &node) { node.custom1 = GEO_NODE_TRANSFORM_MODE_COMPONENTS; };
23 auto enable_matrix = [](bNode &node) { node.custom1 = GEO_NODE_TRANSFORM_MODE_MATRIX; };
24
25 b.add_input<decl::Geometry>("Geometry");
26 auto &translation = b.add_input<decl::Vector>("Translation")
27 .subtype(PROP_TRANSLATION)
28 .make_available(enable_components);
29 auto &rotation = b.add_input<decl::Rotation>("Rotation").make_available(enable_components);
30 auto &scale =
31 b.add_input<decl::Vector>("Scale").default_value({1, 1, 1}).subtype(PROP_XYZ).make_available(
32 enable_components);
33 auto &transform = b.add_input<decl::Matrix>("Transform").make_available(enable_matrix);
34 b.add_output<decl::Geometry>("Geometry").propagate_all();
35
36 const bNode *node = b.node_or_null();
37 if (node != nullptr) {
38 const bool use_matrix = node->custom1 == GEO_NODE_TRANSFORM_MODE_MATRIX;
39
40 translation.available(!use_matrix);
41 rotation.available(!use_matrix);
42 scale.available(!use_matrix);
43 transform.available(use_matrix);
44 }
45}
46
47static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
48{
49 uiLayoutSetPropSep(layout, true);
50 uiLayoutSetPropDecorate(layout, false);
51 uiItemR(layout, ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
52}
53
54static bool use_translate(const math::Quaternion &rotation, const float3 scale)
55{
56 if (math::angle_of(rotation).radian() > 1e-7f) {
57 return false;
58 }
59 if (compare_ff(scale.x, 1.0f, 1e-9f) != 1 || compare_ff(scale.y, 1.0f, 1e-9f) != 1 ||
60 compare_ff(scale.z, 1.0f, 1e-9f) != 1)
61 {
62 return false;
63 }
64 return true;
65}
66
69{
70 if (errors.volume_too_small) {
71 params.error_message_add(NodeWarningType::Warning,
72 TIP_("Volume scale is lower than permitted by OpenVDB"));
73 }
74}
75
77{
78 const bool use_matrix = params.node().custom1 == GEO_NODE_TRANSFORM_MODE_MATRIX;
79 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
80
81 if (use_matrix) {
82 const float4x4 transform = params.extract_input<float4x4>("Transform");
83 if (auto errors = geometry::transform_geometry(geometry_set, transform)) {
84 report_errors(params, *errors);
85 }
86 }
87 else {
88 const float3 translation = params.extract_input<float3>("Translation");
89 const math::Quaternion rotation = params.extract_input<math::Quaternion>("Rotation");
90 const float3 scale = params.extract_input<float3>("Scale");
91
92 /* Use only translation if rotation and scale don't apply. */
93 if (use_translate(rotation, scale)) {
94 geometry::translate_geometry(geometry_set, translation);
95 }
96 else {
97 if (auto errors = geometry::transform_geometry(
98 geometry_set, math::from_loc_rot_scale<float4x4>(translation, rotation, scale)))
99 {
100 report_errors(params, *errors);
101 }
102 }
103 }
104
105 params.set_output("Geometry", std::move(geometry_set));
106}
107
108static void node_rna(StructRNA *srna)
109{
110 static EnumPropertyItem mode_items[] = {
112 "COMPONENTS",
113 0,
114 "Components",
115 "Provide separate location, rotation and scale"},
116 {GEO_NODE_TRANSFORM_MODE_MATRIX, "MATRIX", 0, "Matrix", "Use a transformation matrix"},
117 {0, nullptr, 0, nullptr, nullptr},
118 };
119
121 "mode",
122 "Mode",
123 "How the transformation is specified",
124 mode_items,
126}
127
128static void register_node()
129{
130 static blender::bke::bNodeType ntype;
131
133 &ntype, GEO_NODE_TRANSFORM_GEOMETRY, "Transform Geometry", NODE_CLASS_GEOMETRY);
134 ntype.declare = node_declare;
138
139 node_rna(ntype.rna_ext.srna);
140}
142
143} // namespace blender::nodes::node_geo_transform_geometry_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
MINLINE int compare_ff(float a, float b, float max_diff)
#define TIP_(msgid)
@ GEO_NODE_TRANSFORM_MODE_MATRIX
@ GEO_NODE_TRANSFORM_MODE_COMPONENTS
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
@ PROP_XYZ
Definition RNA_types.hh:172
@ PROP_TRANSLATION
Definition RNA_types.hh:164
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
void make_available(bNode &node) const
local_group_size(16, 16) .push_constant(Type b
OperationNode * node
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void translate_geometry(bke::GeometrySet &geometry, const float3 translation)
std::optional< TransformGeometryErrors > transform_geometry(bke::GeometrySet &geometry, const float4x4 &transform)
AngleRadianBase< T > angle_of(const QuaternionBase< T > &q)
MatT from_loc_rot_scale(const typename MatT::loc_type &location, const RotationT &rotation, const VecBase< typename MatT::base_type, ScaleDim > &scale)
static bool use_translate(const math::Quaternion &rotation, const float3 scale)
static void node_declare(NodeDeclarationBuilder &b)
static void report_errors(GeoNodeExecParams &params, const geometry::TransformGeometryErrors &errors)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
StructRNA * srna
Definition RNA_types.hh:780
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126