[Bf-blender-cvs] [b33d839162b] blender-v2.92-release: Fix T84867: Transform node does not rotate/scale instances
Sebastian Parborg
noreply at git.blender.org
Wed Jan 20 18:18:17 CET 2021
Commit: b33d839162b6d4b8b85937eb095b661ac93cbddd
Author: Sebastian Parborg
Date: Wed Jan 20 18:17:25 2021 +0100
Branches: blender-v2.92-release
https://developer.blender.org/rBb33d839162b6d4b8b85937eb095b661ac93cbddd
Fix T84867: Transform node does not rotate/scale instances
The manipulation of rot/scale was simply not implemented.
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/geometry_set.cc
M source/blender/nodes/geometry/nodes/node_geo_transform.cc
===================================================================
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);
}
}
}
More information about the Bf-blender-cvs
mailing list