glTF importer: fix regression for skinned mesh normals not being renormalized

This commit is contained in:
Julien Duroure 2020-07-24 08:09:38 +02:00
parent 2c9bc1e642
commit 03e3ef7f71
2 changed files with 7 additions and 1 deletions

View File

@ -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',

View File

@ -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