diff options
author | Johnny Matthews <johnny.matthews@gmail.com> | 2022-06-06 20:02:59 +0300 |
---|---|---|
committer | Johnny Matthews <johnny.matthews@gmail.com> | 2022-06-06 20:02:59 +0300 |
commit | 14fc89f38f0e3ce00e4fd6fffd72eea5d998af5a (patch) | |
tree | d0904854d8fbbab0f4b8ab2b238e43b7a55d7f20 /source/blender/nodes/geometry | |
parent | 3a57f5a9cff5ccdc3a7732529fe0c9bfd2ba30bb (diff) |
Geometry Nodes: Add Instance Scale Input Node
A field input node for the scale of each top-level instance transform.
The scale can be set with the "Scale Instances" node, but previously
could not be retrieved.
Differential Revision: https://developer.blender.org/D15132
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r-- | source/blender/nodes/geometry/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index c3cfd07d4b0..54fda328ca8 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -72,6 +72,7 @@ set(SRC nodes/node_geo_input_id.cc nodes/node_geo_input_index.cc nodes/node_geo_input_instance_rotation.cc + nodes/node_geo_input_instance_scale.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_scale.cc b/source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc new file mode 100644 index 00000000000..f2abc592f72 --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_input_instance_scale.cc @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "node_geometry_util.hh" + +namespace blender::nodes::node_geo_input_instance_scale_cc { + +static void node_declare(NodeDeclarationBuilder &b) +{ + b.add_output<decl::Vector>(N_("Scale")).field_source(); +} + +class VectorFieldInput final : public GeometryFieldInput { + public: + VectorFieldInput() : GeometryFieldInput(CPPType::get<float3>(), "Scale") + { + } + + 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<const InstancesComponent &>( + component); + + auto scale_fn = [&](const int i) -> float3 { + return instance_component.instance_transforms()[i].scale(); + }; + + return VArray<float3>::ForFunc(instance_component.instances_num(), scale_fn); + } + + uint64_t hash() const override + { + return 8346343; + } + + bool is_equal_to(const fn::FieldNode &other) const override + { + return dynamic_cast<const VectorFieldInput *>(&other) != nullptr; + } +}; + +static void node_geo_exec(GeoNodeExecParams params) +{ + Field<float3> scale{std::make_shared<VectorFieldInput>()}; + params.set_output("Scale", std::move(scale)); +} + +} // namespace blender::nodes::node_geo_input_instance_scale_cc + +void register_node_type_geo_input_instance_scale() +{ + namespace file_ns = blender::nodes::node_geo_input_instance_scale_cc; + + static bNodeType ntype; + geo_node_type_base(&ntype, GEO_NODE_INPUT_INSTANCE_SCALE, "Instance Scale", NODE_CLASS_INPUT); + ntype.geometry_node_execute = file_ns::node_geo_exec; + ntype.declare = file_ns::node_declare; + nodeRegisterType(&ntype); +} |