Skip to content

Commit

Permalink
Changed use of some Matrix.invert() to Matrix.invert_safe() to preven…
Browse files Browse the repository at this point in the history
…t crashes:

- This is used when the child transformations need to be calculated in the parent space.
- This prevent crashes when the parent scale is 0.
- The solution is not perfect. Calculating transformations in a space scaled to 0 is meaningless, the transformations won't be visible anyway. The child transformations shouldn't really be exported at all in that case. This will cause imperfect results during interpolation from 0 scaled frame to the next frame.
  • Loading branch information
Nusiq committed Aug 24, 2024
1 parent 61bd9e4 commit 2ee9e41
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mcblend/operator_func/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,13 @@ def get_local_matrix(
if normalize:
p_matrix.normalize()
c_matrix.normalize()
return p_matrix.inverted() @ c_matrix
# The inver_safe() function is used to avoid errors when the parent
# matrix is scaled to zero on some axis (which makes it non-invertible)
# It's not perfect becuase the child transformations will be incorrect
# but it prevents crashes and in theory the child transformations on
# that axis shouldn't be visible anyway (they are during interpolation
# between keyframes).
return p_matrix.inverted_safe() @ c_matrix

def get_mcrotation(
self, other: Optional[McblendObject] = None
Expand All @@ -323,7 +329,7 @@ def local_rotation(
Returns Euler rotation of a child matrix in relation to parent matrix
'''
child_q = child_matrix.normalized().to_quaternion()
parent_q = parent_matrix.inverted().normalized().to_quaternion()
parent_q = parent_matrix.inverted_safe().normalized().to_quaternion()
return (parent_q @ child_q).to_euler('XZY')

if other is not None:
Expand Down

0 comments on commit 2ee9e41

Please sign in to comment.