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:
authorHans Goudey <h.goudey@me.com>2021-10-20 18:54:54 +0300
committerHans Goudey <h.goudey@me.com>2021-10-20 18:54:54 +0300
commit40c3b8836b7a36303ea9c78b0932758cbf277f93 (patch)
tree84cf99f5f726384def64e79333b7566e36ff1156 /source/blender/nodes
parent1a96045eec96e0c6f52ded6fd40040c4b88524d9 (diff)
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
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc35
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc8
2 files changed, 13 insertions, 30 deletions
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<decl::Geometry>("Points");
b.add_output<decl::Vector>("Normal").field_source();
b.add_output<decl::Vector>("Rotation").subtype(PROP_EULER).field_source();
- b.add_output<decl::Int>("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<int> looptri_indices,
const AttributeOutputs &attribute_outputs)
{
- OutputAttribute_Typed<int> id_attribute;
+ OutputAttribute_Typed<int> id_attribute = point_component.attribute_try_get_for_output_only<int>(
+ "id", ATTR_DOMAIN_POINT);
+ MutableSpan<int> ids = id_attribute.as_span();
+
OutputAttribute_Typed<float3> normal_attribute;
OutputAttribute_Typed<float3> rotation_attribute;
- MutableSpan<int> ids;
MutableSpan<float3> normals;
MutableSpan<float3> rotations;
- if (attribute_outputs.stable_id_id) {
- id_attribute = point_component.attribute_try_get_for_output_only<int>(
- 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<float3>(
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<float3>(std::move(attribute_outputs.rotation_id)));
}
- if (attribute_outputs.stable_id_id) {
- params.set_output(
- "Stable ID",
- AnonymousAttributeFieldInput::Create<int>(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<decl::Int>("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<decl::Geometry>("Instances");
}
@@ -91,12 +86,11 @@ static void add_instances_from_component(InstancesComponent &dst_component,
const VArray<float3> *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<int> *stable_ids = nullptr;
+ GVArray_Typed<int> stable_ids = src_component.attribute_get_for_read("id", ATTR_DOMAIN_POINT, 0);
field_evaluator.add(params.get_input<Field<bool>>("Pick Instance"), &pick_instance);
field_evaluator.add(params.get_input<Field<int>>("Instance Index"), &indices);
field_evaluator.add(params.get_input<Field<float3>>("Rotation"), &rotations);
field_evaluator.add(params.get_input<Field<float3>>("Scale"), &scales);
- field_evaluator.add(params.get_input<Field<int>>("Stable ID"), &stable_ids);
field_evaluator.evaluate();
GVArray_Typed<float3> positions = src_component.attribute_get_for_read<float3>(