diff options
author | Hans Goudey <h.goudey@me.com> | 2021-04-02 20:03:27 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-04-02 20:03:27 +0300 |
commit | 0e8fa1d44bd0b84e090febde2224635cb6be9f69 (patch) | |
tree | 9cb3986969b8b5a7528a60ae236229e081450ea4 /source/blender/nodes | |
parent | bd9c4794751ec7d4ad4989c43e47cb00e21cf1e5 (diff) |
Geometry Nodes: Allow float input for point scale node
This allows easily changing the scale attribute with a uniform scale
within a single simple node.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_point_scale.cc | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc b/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc index d22e63fe6f7..108ac726c84 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc @@ -25,6 +25,7 @@ static bNodeSocketTemplate geo_node_point_scale_in[] = { {SOCK_GEOMETRY, N_("Geometry")}, {SOCK_STRING, N_("Factor")}, {SOCK_VECTOR, N_("Factor"), 1.0f, 1.0f, 1.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_XYZ}, + {SOCK_FLOAT, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX}, {-1, ""}, }; @@ -44,22 +45,42 @@ namespace blender::nodes { static void execute_on_component(GeoNodeExecParams params, GeometryComponent &component) { + /* Note that scale doesn't necessarily need to be created with a vector type-- it could also use + * the highest complexity of the existing attribute's type (if it exists) and the data type used + * for the factor. But for it's simpler to simply always use float3, since that is usually + * expected anyway. */ static const float3 scale_default = float3(1.0f); OutputAttributePtr scale_attribute = component.attribute_try_get_for_output( "scale", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, &scale_default); if (!scale_attribute) { return; } + + const bNode &node = params.node(); + const NodeGeometryPointScale &node_storage = *(const NodeGeometryPointScale *)node.storage; + const GeometryNodeAttributeInputMode input_type = (GeometryNodeAttributeInputMode) + node_storage.input_type; + const CustomDataType data_type = (input_type == GEO_NODE_ATTRIBUTE_INPUT_FLOAT) ? CD_PROP_FLOAT : + CD_PROP_FLOAT3; + ReadAttributePtr attribute = params.get_input_attribute( - "Factor", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr); + "Factor", component, ATTR_DOMAIN_POINT, data_type, nullptr); if (!attribute) { return; } - Span<float3> data = attribute->get_span<float3>(); MutableSpan<float3> scale_span = scale_attribute->get_span<float3>(); - for (const int i : scale_span.index_range()) { - scale_span[i] = scale_span[i] * data[i]; + if (data_type == CD_PROP_FLOAT) { + Span<float> factors = attribute->get_span<float>(); + for (const int i : scale_span.index_range()) { + scale_span[i] = scale_span[i] * factors[i]; + } + } + else if (data_type == CD_PROP_FLOAT3) { + Span<float3> factors = attribute->get_span<float3>(); + for (const int i : scale_span.index_range()) { + scale_span[i] = scale_span[i] * factors[i]; + } } scale_attribute.apply_span_and_save(); |