From adb4ab89737b4f3dc5da47fffdc42177034f2afc Mon Sep 17 00:00:00 2001 From: JoeBell Date: Tue, 4 Mar 2025 20:03:31 -0500 Subject: [PATCH] Downgraded numpy Downgraded from numpy 2.x to numy 1.x for compatibility --- Raytrace/TriangleMesh.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Raytrace/TriangleMesh.py b/Raytrace/TriangleMesh.py index d1b8898..50be840 100644 --- a/Raytrace/TriangleMesh.py +++ b/Raytrace/TriangleMesh.py @@ -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) @@ -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) @@ -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