From 40c3b8836b7a36303ea9c78b0932758cbf277f93 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 20 Oct 2021 10:54:54 -0500 Subject: Geometry Nodes: Make Random ID a builtin attribute, remove sockets In order to address feedback that the "Stable ID" was not easy enough to use, remove the "Stable ID" output from the distribution node and the input from the instance on points node. Instead, the nodes write or read a builtin named attribute called `id`. In the future we may add more attributes like `edge_id` and `face_id`. The downside is that more behavior is invisible, which is les expected now that most attributes are passed around with node links. This behavior will have to be explained in the manual. The random value node's "ID" input that had an implicit index input is converted to a special implicit input that uses the `id` attribute if possible, but otherwise defaults to the index. There is no way to tell in the UI which it uses, except by knowing that rule and checking in the spreadsheet for the id attribute. Because it isn't always possible to create stable randomness, this attribute does not always exist, and it will be possible to remove it when we have the attribute remove node back, to improve performance. Differential Revision: https://developer.blender.org/D12903 --- .../nodes/node_geo_distribute_points_on_faces.cc | 35 ++++++++-------------- .../geometry/nodes/node_geo_instance_on_points.cc | 8 +---- 2 files changed, 13 insertions(+), 30 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc index 44beead86ad..0d481011f00 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc @@ -58,7 +58,6 @@ static void geo_node_point_distribute_points_on_faces_declare(NodeDeclarationBui b.add_output("Points"); b.add_output("Normal").field_source(); b.add_output("Rotation").subtype(PROP_EULER).field_source(); - b.add_output("Stable ID").field_source(); } static void geo_node_point_distribute_points_on_faces_layout(uiLayout *layout, @@ -329,7 +328,6 @@ namespace { struct AttributeOutputs { StrongAnonymousAttributeID normal_id; StrongAnonymousAttributeID rotation_id; - StrongAnonymousAttributeID stable_id_id; }; } // namespace @@ -339,19 +337,16 @@ BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_com const Span looptri_indices, const AttributeOutputs &attribute_outputs) { - OutputAttribute_Typed id_attribute; + OutputAttribute_Typed id_attribute = point_component.attribute_try_get_for_output_only( + "id", ATTR_DOMAIN_POINT); + MutableSpan ids = id_attribute.as_span(); + OutputAttribute_Typed normal_attribute; OutputAttribute_Typed rotation_attribute; - MutableSpan ids; MutableSpan normals; MutableSpan rotations; - if (attribute_outputs.stable_id_id) { - id_attribute = point_component.attribute_try_get_for_output_only( - attribute_outputs.stable_id_id.get(), ATTR_DOMAIN_POINT); - ids = id_attribute.as_span(); - } if (attribute_outputs.normal_id) { normal_attribute = point_component.attribute_try_get_for_output_only( attribute_outputs.normal_id.get(), ATTR_DOMAIN_POINT); @@ -379,9 +374,8 @@ BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_com const float3 v1_pos = float3(mesh.mvert[v1_index].co); const float3 v2_pos = float3(mesh.mvert[v2_index].co); - if (!ids.is_empty()) { - ids[i] = noise::hash(noise::hash_float(bary_coord), looptri_index); - } + ids[i] = noise::hash(noise::hash_float(bary_coord), looptri_index); + float3 normal; if (!normals.is_empty() || !rotations.is_empty()) { normal_tri_v3(normal, v0_pos, v1_pos, v2_pos); @@ -394,9 +388,8 @@ BLI_NOINLINE static void compute_attribute_outputs(const MeshComponent &mesh_com } } - if (id_attribute) { - id_attribute.save(); - } + id_attribute.save(); + if (normal_attribute) { normal_attribute.save(); } @@ -512,6 +505,10 @@ static void point_distribution_calculate(GeometrySet &geometry_set, } } + if (positions.is_empty()) { + return; + } + PointCloud *pointcloud = BKE_pointcloud_new_nomain(positions.size()); memcpy(pointcloud->co, positions.data(), sizeof(float3) * positions.size()); uninitialized_fill_n(pointcloud->radius, pointcloud->totpoint, 0.05f); @@ -551,9 +548,6 @@ static void geo_node_point_distribute_points_on_faces_exec(GeoNodeExecParams par if (params.output_is_required("Rotation")) { attribute_outputs.rotation_id = StrongAnonymousAttributeID("rotation"); } - if (params.output_is_required("Stable ID")) { - attribute_outputs.stable_id_id = StrongAnonymousAttributeID("stable id"); - } geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { point_distribution_calculate( @@ -575,11 +569,6 @@ static void geo_node_point_distribute_points_on_faces_exec(GeoNodeExecParams par "Rotation", AnonymousAttributeFieldInput::Create(std::move(attribute_outputs.rotation_id))); } - if (attribute_outputs.stable_id_id) { - params.set_output( - "Stable ID", - AnonymousAttributeFieldInput::Create(std::move(attribute_outputs.stable_id_id))); - } } } // namespace blender::nodes diff --git a/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc b/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc index c7235fb2c29..78399fad2c0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc @@ -48,11 +48,6 @@ static void geo_node_instance_on_points_declare(NodeDeclarationBuilder &b) .subtype(PROP_XYZ) .supports_field() .description("Scale of the instances"); - b.add_input("Stable ID") - .supports_field() - .description( - "ID for every instance that is used to identify it over time even when the number of " - "instances changes. Used for example for motion blur"); b.add_output("Instances"); } @@ -91,12 +86,11 @@ static void add_instances_from_component(InstancesComponent &dst_component, const VArray *scales = nullptr; /* The evaluator could use the component's stable IDs as a destination directly, but only the * selected indices should be copied. */ - const VArray *stable_ids = nullptr; + GVArray_Typed stable_ids = src_component.attribute_get_for_read("id", ATTR_DOMAIN_POINT, 0); field_evaluator.add(params.get_input>("Pick Instance"), &pick_instance); field_evaluator.add(params.get_input>("Instance Index"), &indices); field_evaluator.add(params.get_input>("Rotation"), &rotations); field_evaluator.add(params.get_input>("Scale"), &scales); - field_evaluator.add(params.get_input>("Stable ID"), &stable_ids); field_evaluator.evaluate(); GVArray_Typed positions = src_component.attribute_get_for_read( -- cgit v1.2.3