Skip to content

Commit

Permalink
Downgraded numpy
Browse files Browse the repository at this point in the history
Downgraded from numpy 2.x to numy 1.x for compatibility
  • Loading branch information
JoeBell committed Mar 5, 2025
1 parent 8eeecef commit adb4ab8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Raytrace/TriangleMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def triangle_ray_intersection(triangle, ray:Ray, epsilon = 1e-10) -> float:
return -1
@staticmethod
def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) -> np.ndarray:
vecdot = lambda a, b : np.sum(a*b, axis=-1)
# Translated from https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm#C++_implementation

triangle_array_comp = triangle_array.swapaxes(0, 1)
Expand All @@ -91,16 +92,16 @@ def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) ->
v2 = v2 - v0

ray_cross_e2 = np.cross(ray.direction, v2)
det = np.vecdot(v1, ray_cross_e2)
det = vecdot(v1, ray_cross_e2)
# if -epsilon < det < epsilon:
# return None # This ray is parallel to this triangle.
old_error_state = np.seterr(divide='ignore', invalid='ignore')
inv_det = 1.0 / det
s = ray.origin - v0
u = inv_det * np.vecdot(s, ray_cross_e2)
u = inv_det * vecdot(s, ray_cross_e2)

s_cross_e1 = np.cross(s, v1)
v = inv_det * np.vecdot(ray.direction, s_cross_e1)
v = inv_det * vecdot(ray.direction, s_cross_e1)

valid = u < -epsilon
np.logical_or(valid, 1 < u, out=valid)
Expand All @@ -111,7 +112,7 @@ def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) ->
t = np.empty(triangle_array.shape[0], dtype=np.float64)
t.fill(-1)

np.multiply(inv_det, np.vecdot(v2, s_cross_e1), out = t, where = valid)
np.multiply(inv_det, vecdot(v2, s_cross_e1), out = t, where = valid)

np.seterr(**old_error_state)
return t
Expand Down

0 comments on commit adb4ab8

Please sign in to comment.