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
This commit is contained in:
Wannes Malfait 2021-02-19 11:37:15 +01:00 committed by Jacques Lucke
parent 47fc1e11db
commit 359d0029fe
Notes: blender-bot 2023-02-14 09:43:37 +01:00
Referenced by issue #85763, Geometry Nodes: Align rotation to vector node doesn't flip rotation when vector is multiplied by -1
1 changed files with 9 additions and 1 deletions

View File

@ -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;