diff options
author | Wannes Malfait <Wannes> | 2021-02-19 13:37:15 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-02-19 13:37:35 +0300 |
commit | 359d0029fe7601163c449730d42f12d84163fcd8 (patch) | |
tree | 53178dbccb51369110b26945225206920e67c041 /source/blender/nodes | |
parent | 47fc1e11db68e2d4c565156552beb87f98bbb927 (diff) |
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
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc | 10 |
1 files changed, 9 insertions, 1 deletions
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; |