Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnny Matthews <johnny.matthews@gmail.com>2021-10-14 07:33:46 +0300
committerJohnny Matthews <johnny.matthews@gmail.com>2021-10-14 07:33:46 +0300
commita059d16f65c50fe8200fa4f730da42a86cda92d0 (patch)
tree7a7f0e9fd5c20c92d1ff0ae13d2d1995ae58be02 /source/blender
parent5401fda41244175b491ab5aad8c9693b3eb09f33 (diff)
Geometry Nodes: Add Offset Option to Set Postion
Add a boolean field to the Set Position Node. This value allows for each point to either have its position set to the input position value or have the input value added to the current position. Differential Revision: https://developer.blender.org/D12773
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_position.cc25
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
index 8caf961fc04..15930508e78 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
@@ -23,14 +23,16 @@ namespace blender::nodes {
static void geo_node_set_position_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Geometry");
- b.add_input<decl::Vector>("Position").implicit_field();
b.add_input<decl::Bool>("Selection").default_value(true).hide_value().supports_field();
+ b.add_input<decl::Vector>("Position").implicit_field();
+ b.add_input<decl::Bool>("Offset").default_value(false).supports_field();
b.add_output<decl::Geometry>("Geometry");
}
static void set_position_in_component(GeometryComponent &component,
const Field<bool> &selection_field,
- const Field<float3> &position_field)
+ const Field<float3> &position_field,
+ const Field<bool> &offset_field)
{
GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT};
const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT);
@@ -45,9 +47,23 @@ static void set_position_in_component(GeometryComponent &component,
OutputAttribute_Typed<float3> positions = component.attribute_try_get_for_output<float3>(
"position", ATTR_DOMAIN_POINT, {0, 0, 0});
+ MutableSpan<float3> position_mutable = positions.as_span();
+
fn::FieldEvaluator position_evaluator{field_context, &selection};
- position_evaluator.add_with_destination(position_field, positions.varray());
+ position_evaluator.add(position_field);
+ position_evaluator.add(offset_field);
position_evaluator.evaluate();
+
+ /* TODO: We could have different code paths depending on whether the offset input is a single
+ * value or not */
+
+ const VArray<float3> &positions_input = position_evaluator.get_evaluated<float3>(0);
+ const VArray<bool> &offsets_input = position_evaluator.get_evaluated<bool>(1);
+
+ for (int i : selection) {
+ position_mutable[i] = offsets_input[i] ? position_mutable[i] + positions_input[i] :
+ positions_input[i];
+ }
positions.save();
}
@@ -55,6 +71,7 @@ static void geo_node_set_position_exec(GeoNodeExecParams params)
{
GeometrySet geometry = params.extract_input<GeometrySet>("Geometry");
Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
+ Field<bool> offset_field = params.extract_input<Field<bool>>("Offset");
Field<float3> position_field = params.extract_input<Field<float3>>("Position");
for (const GeometryComponentType type : {GEO_COMPONENT_TYPE_MESH,
@@ -63,7 +80,7 @@ static void geo_node_set_position_exec(GeoNodeExecParams params)
GEO_COMPONENT_TYPE_INSTANCES}) {
if (geometry.has(type)) {
set_position_in_component(
- geometry.get_component_for_write(type), selection_field, position_field);
+ geometry.get_component_for_write(type), selection_field, position_field, offset_field);
}
}