diff options
author | Hans Goudey <h.goudey@me.com> | 2021-01-07 18:27:42 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-01-07 18:27:42 +0300 |
commit | 3db975f30dd327381dc1a0e08305460a1a12eba4 (patch) | |
tree | f6e2f3a004e8a7c6b055af8c56652ae707ab942e /source/blender/blenkernel/intern/geometry_set.cc | |
parent | 4c0fc60105d7b7ff3f5c926510d77bb261e71977 (diff) |
Fix T84326: No ID for geometry nodes instances after scattering
Instances are created with an "index" parameter used for persistence over
time through animation. Currently the geometry nodes instancer passes
the index in the array for this value, but the arrays created by the
"Point Distribution" node aren't necessarily stable in this way when
the input mesh is deformed. In D9832 we already mostly solved this
problem with an `id` attribute. The solution here is to create instances
with this attribute as well.
It's important to note that deforming the instanced points *after*
distribution will usually be a better solution for this problem. This
solution is likely still important though.
Differential Revision: https://developer.blender.org/D10024
Diffstat (limited to 'source/blender/blenkernel/intern/geometry_set.cc')
-rw-r--r-- | source/blender/blenkernel/intern/geometry_set.cc | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc index 2a21a60ccc6..5d2b82dcc5f 100644 --- a/source/blender/blenkernel/intern/geometry_set.cc +++ b/source/blender/blenkernel/intern/geometry_set.cc @@ -476,34 +476,38 @@ void InstancesComponent::clear() void InstancesComponent::add_instance(Object *object, blender::float3 position, blender::float3 rotation, - blender::float3 scale) + blender::float3 scale, + const int id) { InstancedData data; data.type = INSTANCE_DATA_TYPE_OBJECT; data.data.object = object; - this->add_instance(data, position, rotation, scale); + this->add_instance(data, position, rotation, scale, id); } void InstancesComponent::add_instance(Collection *collection, blender::float3 position, blender::float3 rotation, - blender::float3 scale) + blender::float3 scale, + const int id) { InstancedData data; data.type = INSTANCE_DATA_TYPE_COLLECTION; data.data.collection = collection; - this->add_instance(data, position, rotation, scale); + this->add_instance(data, position, rotation, scale, id); } void InstancesComponent::add_instance(InstancedData data, blender::float3 position, blender::float3 rotation, - blender::float3 scale) + blender::float3 scale, + const int id) { instanced_data_.append(data); positions_.append(position); rotations_.append(rotation); scales_.append(scale); + ids_.append(id); } Span<InstancedData> InstancesComponent::instanced_data() const @@ -516,16 +520,21 @@ Span<float3> InstancesComponent::positions() const return positions_; } -blender::Span<blender::float3> InstancesComponent::rotations() const +Span<float3> InstancesComponent::rotations() const { return rotations_; } -blender::Span<blender::float3> InstancesComponent::scales() const +Span<float3> InstancesComponent::scales() const { return scales_; } +Span<int> InstancesComponent::ids() const +{ + return ids_; +} + MutableSpan<float3> InstancesComponent::positions() { return positions_; @@ -565,6 +574,7 @@ int BKE_geometry_set_instances(const GeometrySet *geometry_set, float (**r_positions)[3], float (**r_rotations)[3], float (**r_scales)[3], + int **r_ids, InstancedData **r_instanced_data) { const InstancesComponent *component = geometry_set->get_component_for_read<InstancesComponent>(); @@ -574,6 +584,8 @@ int BKE_geometry_set_instances(const GeometrySet *geometry_set, *r_positions = (float(*)[3])component->positions().data(); *r_rotations = (float(*)[3])component->rotations().data(); *r_scales = (float(*)[3])component->scales().data(); + *r_ids = (int *)component->ids().data(); + *r_instanced_data = (InstancedData *)component->instanced_data().data(); *r_instanced_data = (InstancedData *)component->instanced_data().data(); return component->instances_amount(); } |