Skip to content

Commit

Permalink
make non-invertible fallback more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
Theverat committed Feb 16, 2018
1 parent 211981a commit 52078a0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def matrix_to_list(matrix, scene=None, apply_worldscale=False, invert=False):
matrix = get_scaled_to_world(matrix, scene)

if invert:
matrix = matrix.copy()
matrix.invert_safe()

l = [matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0],
Expand All @@ -148,12 +149,13 @@ def matrix_to_list(matrix, scene=None, apply_worldscale=False, invert=False):

if matrix.determinant() == 0:
# The matrix is non-invertible. This can happen if e.g. the scale on one axis is 0.
# Prevent a RuntimeError from LuxCore by adding a small epsilon.
# Prevent a RuntimeError from LuxCore by adding a small random epsilon.
msg = "Non-invertible matrix. Can happen if e.g. an object has scale 0"
bpy.context.scene.luxcore.errorlog.add_warning(msg)

epsilon = 1e-5
return [float(i) + epsilon for i in l]
# TODO maybe look for a better way to handle this
from random import random
return [float(i) + (1e-5 + random() * 1e-5) for i in l]
else:
return [float(i) for i in l]

Expand Down

0 comments on commit 52078a0

Please sign in to comment.