From 03e3ef7f71f20a370ef4302455f36bc476f3f33a Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Fri, 24 Jul 2020 08:09:38 +0200 Subject: glTF importer: fix regression for skinned mesh normals not being renormalized --- io_scene_gltf2/__init__.py | 2 +- io_scene_gltf2/blender/imp/gltf2_blender_mesh.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 85fdde3c..70a06504 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -15,7 +15,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (1, 3, 42), + "version": (1, 3, 43), 'blender': (2, 90, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py index 175bc920..e393eb86 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py @@ -540,6 +540,7 @@ def skin_into_bind_pose(gltf, skin_idx, vert_joints, vert_weights, locs, vert_no if len(vert_normals) != 0: vert_normals[:] = mul_mats_vecs(skinning_mats_3x3, vert_normals) # Don't translate normals! + normalize_vecs(vert_normals) def mul_mats_vecs(mats, vecs): @@ -547,6 +548,11 @@ def mul_mats_vecs(mats, vecs): return np.matmul(mats, vecs.reshape(len(vecs), 3, 1)).reshape(len(vecs), 3) +def normalize_vecs(vectors): + norms = np.linalg.norm(vectors, axis=1, keepdims=True) + np.divide(vectors, norms, out=vectors, where=norms != 0) + + def merge_duplicate_verts(vert_locs, vert_normals, vert_joints, vert_weights, sk_vert_locs, loop_vidxs, edge_vidxs): # This function attempts to invert the splitting done when exporting to # glTF. Welds together verts with the same per-vert data (but possibly -- cgit v1.2.3