[Bf-blender-cvs] [359d0029fe7] master: Fix T85763: Align Rotation to Vector node fails for collinear vectors

Wannes Malfait noreply at git.blender.org
Fri Feb 19 11:37:56 CET 2021


Commit: 359d0029fe7601163c449730d42f12d84163fcd8
Author: Wannes Malfait
Date:   Fri Feb 19 11:37:15 2021 +0100
Branches: master
https://developer.blender.org/rB359d0029fe7601163c449730d42f12d84163fcd8

Fix T85763: Align Rotation to Vector node fails for collinear vectors

If the axes are aligned in auto pivot mode then the rotation axis would be (0,0,0).
We now fall back to the x axis in this case. If that fails, we fall back to the y axis.

Differential Revision: https://developer.blender.org/D10466

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc

===================================================================

diff --git a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
index a81adbbd754..3da447af98a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
@@ -65,7 +65,15 @@ static void align_rotations_auto_pivot(const Float3ReadAttribute &vectors,
     mul_v3_m3v3(old_axis, old_rotation, local_main_axis);
 
     const float3 new_axis = vector.normalized();
-    const float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis);
+    float3 rotation_axis = float3::cross_high_precision(old_axis, new_axis);
+    if (is_zero_v3(rotation_axis)) {
+      /* The vectors are linearly dependent, so we fall back to another axis. */
+      rotation_axis = float3::cross_high_precision(old_axis, float3(1, 0, 0));
+      if (is_zero_v3(rotation_axis))
+        /* This is now guaranteed to not be zero. */
+        rotation_axis = float3::cross_high_precision(old_axis, float3(0, 1, 0));
+    }
+
     const float full_angle = angle_normalized_v3v3(old_axis, new_axis);
     const float angle = factors[i] * full_angle;



More information about the Bf-blender-cvs mailing list