From 3a57f5a9cff5ccdc3a7732529fe0c9bfd2ba30bb Mon Sep 17 00:00:00 2001 From: Johnny Matthews Date: Mon, 6 Jun 2022 11:50:13 -0500 Subject: Geometry Nodes: Instance Rotation Node A field input node for the rotation of each top-level instance transform. The rotation can be set with the "Rotate Instances" node, but previously could not be retrieved. Differential Revision: https://developer.blender.org/D15131 --- source/blender/blenkernel/BKE_node.h | 1 + source/blender/blenkernel/intern/node.cc | 1 + source/blender/nodes/NOD_geometry.h | 1 + source/blender/nodes/NOD_static_types.h | 1 + source/blender/nodes/geometry/CMakeLists.txt | 1 + .../nodes/node_geo_input_instance_rotation.cc | 65 ++++++++++++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc (limited to 'source') diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 1ff10d06b00..bd0565f4227 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1493,6 +1493,7 @@ struct TexResult; #define GEO_NODE_STORE_NAMED_ATTRIBUTE 1156 #define GEO_NODE_INPUT_NAMED_ATTRIBUTE 1157 #define GEO_NODE_REMOVE_ATTRIBUTE 1158 +#define GEO_NODE_INPUT_INSTANCE_ROTATION 1159 /** \} */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index cf50e8a3b43..f37539afe55 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -4764,6 +4764,7 @@ static void registerGeometryNodes() register_node_type_geo_input_curve_tilt(); register_node_type_geo_input_id(); register_node_type_geo_input_index(); + register_node_type_geo_input_instance_rotation(); register_node_type_geo_input_material_index(); register_node_type_geo_input_material(); register_node_type_geo_input_mesh_edge_angle(); diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h index 064112b7efd..13ae1ac2724 100644 --- a/source/blender/nodes/NOD_geometry.h +++ b/source/blender/nodes/NOD_geometry.h @@ -62,6 +62,7 @@ void register_node_type_geo_input_curve_handles(void); void register_node_type_geo_input_curve_tilt(void); void register_node_type_geo_input_id(void); void register_node_type_geo_input_index(void); +void register_node_type_geo_input_instance_rotation(void); void register_node_type_geo_input_material_index(void); void register_node_type_geo_input_material(void); void register_node_type_geo_input_mesh_edge_angle(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index e0a4d241b3b..60422462173 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -318,6 +318,7 @@ DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_HANDLES, 0, "INPUT_CURVE_HANDLES", In DefNode(GeometryNode, GEO_NODE_INPUT_CURVE_TILT, 0, "INPUT_CURVE_TILT", InputCurveTilt, "Curve Tilt", "") DefNode(GeometryNode, GEO_NODE_INPUT_ID, 0, "INPUT_ID", InputID, "ID", "") DefNode(GeometryNode, GEO_NODE_INPUT_INDEX, 0, "INDEX", InputIndex, "Index", "") +DefNode(GeometryNode, GEO_NODE_INPUT_INSTANCE_ROTATION, 0, "INPUT_INSTANCE_ROTATION", InputInstanceRotation, "Instance Rotation", "") DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL_INDEX, 0, "INPUT_MATERIAL_INDEX", InputMaterialIndex, "Material Index", "") DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "") DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_ANGLE, 0, "MESH_EDGE_ANGLE", InputMeshEdgeAngle, "Edge Angle", "") diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 84280c0889a..c3cfd07d4b0 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -71,6 +71,7 @@ set(SRC nodes/node_geo_input_curve_tilt.cc nodes/node_geo_input_id.cc nodes/node_geo_input_index.cc + nodes/node_geo_input_instance_rotation.cc nodes/node_geo_input_material.cc nodes/node_geo_input_material_index.cc nodes/node_geo_input_mesh_edge_angle.cc diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc b/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc new file mode 100644 index 00000000000..a6d6722ae2a --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_input_instance_rotation.cc @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "node_geometry_util.hh" + +namespace blender::nodes::node_geo_input_instance_rotation_cc { + +static void node_declare(NodeDeclarationBuilder &b) +{ + b.add_output(N_("Rotation")).field_source(); +} + +class VectorFieldInput final : public GeometryFieldInput { + public: + VectorFieldInput() : GeometryFieldInput(CPPType::get(), "Rotation") + { + } + + GVArray get_varray_for_context(const GeometryComponent &component, + const eAttrDomain domain, + IndexMask mask) const final + { + if (component.type() != GEO_COMPONENT_TYPE_INSTANCES) { + return {}; + } + + const InstancesComponent &instance_component = static_cast( + component); + + auto rotation_fn = [&](const int i) -> float3 { + return instance_component.instance_transforms()[i].to_euler(); + }; + + return VArray::ForFunc(instance_component.instances_num(), rotation_fn); + } + + uint64_t hash() const override + { + return 22374372; + } + + bool is_equal_to(const fn::FieldNode &other) const override + { + return dynamic_cast(&other) != nullptr; + } +}; + +static void node_geo_exec(GeoNodeExecParams params) +{ + Field rotation{std::make_shared()}; + params.set_output("Rotation", std::move(rotation)); +} + +} // namespace blender::nodes::node_geo_input_instance_rotation_cc + +void register_node_type_geo_input_instance_rotation() +{ + namespace file_ns = blender::nodes::node_geo_input_instance_rotation_cc; + + static bNodeType ntype; + geo_node_type_base( + &ntype, GEO_NODE_INPUT_INSTANCE_ROTATION, "Instance Rotation", NODE_CLASS_INPUT); + ntype.geometry_node_execute = file_ns::node_geo_exec; + ntype.declare = file_ns::node_declare; + nodeRegisterType(&ntype); +} -- cgit v1.2.3