diff options
-rw-r--r-- | source/blender/blenkernel/BKE_geometry_set.hh | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/geometry_set.cc | 10 | ||||
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_transform.cc | 12 |
3 files changed, 22 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index 391bd243edf..ad5a5d57045 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -456,6 +456,8 @@ class InstancesComponent : public GeometryComponent { blender::Span<blender::float3> scales() const; blender::Span<int> ids() const; blender::MutableSpan<blender::float3> positions(); + blender::MutableSpan<blender::float3> rotations(); + blender::MutableSpan<blender::float3> scales(); int instances_amount() const; bool is_empty() const final; diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc index 5d2b82dcc5f..81958b81213 100644 --- a/source/blender/blenkernel/intern/geometry_set.cc +++ b/source/blender/blenkernel/intern/geometry_set.cc @@ -540,6 +540,16 @@ MutableSpan<float3> InstancesComponent::positions() return positions_; } +MutableSpan<float3> InstancesComponent::rotations() +{ + return rotations_; +} + +MutableSpan<float3> InstancesComponent::scales() +{ + return scales_; +} + int InstancesComponent::instances_amount() const { const int size = instanced_data_.size(); diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index abfa603b584..4fe61dff72d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -92,6 +92,8 @@ static void transform_instances(InstancesComponent &instances, const float3 scale) { MutableSpan<float3> positions = instances.positions(); + MutableSpan<float3> rotations = instances.rotations(); + MutableSpan<float3> scales = instances.scales(); /* Use only translation if rotation and scale don't apply. */ if (use_translate(rotation, scale)) { @@ -101,9 +103,15 @@ static void transform_instances(InstancesComponent &instances, } else { float mat[4][4]; + float instance_mat[4][4]; + float quaternion[4]; + loc_eul_size_to_mat4(mat, translation, rotation, scale); - for (float3 &position : positions) { - mul_m4_v3(mat, position); + for (int i = 0; i < positions.size(); i++) { + loc_eul_size_to_mat4(instance_mat, positions[i], rotations[i], scales[i]); + mul_m4_m4_post(instance_mat, mat); + mat4_decompose(positions[i], quaternion, scales[i], instance_mat); + quat_to_eul(rotations[i], quaternion); } } } |