From d9fa14b17cf2e61d06b6bcd8c68eb6a178c9b248 Mon Sep 17 00:00:00 2001 From: Salad Dais Date: Thu, 8 Sep 2022 18:27:01 +0000 Subject: [PATCH] Faster vec3 normalization --- hippolyzer/lib/base/gltftools.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hippolyzer/lib/base/gltftools.py b/hippolyzer/lib/base/gltftools.py index 041bdeb..ef812e6 100644 --- a/hippolyzer/lib/base/gltftools.py +++ b/hippolyzer/lib/base/gltftools.py @@ -106,9 +106,10 @@ def sl_weights_to_gltf(sl_weights: List[List[VertexWeight]]) -> Tuple[np.ndarray def normalize_vec3(a): - l2 = np.atleast_1d(np.linalg.norm(a, 2, axis=-1)) - l2[l2 == 0] = 1 - return (a / np.expand_dims(l2, axis=-1))[0] + norm = np.linalg.norm(a) + if norm == 0: + return a + return a / norm def apply_bind_shape_matrix(bind_shape_matrix: np.ndarray, verts: np.ndarray, norms: np.ndarray) \