glTF importer: fix skinning for meshes where indices doesn't match data

This was a regression from previous commit
This commit is contained in:
Julien Duroure 2019-02-22 09:44:59 +01:00
parent b7769e098a
commit 0852abc7a9
2 changed files with 31 additions and 18 deletions

View File

@ -44,20 +44,17 @@ class BlenderPrimitive():
pyprimitive.tmp_indices = indices
# Manage only vertices that are in indices tab
if len(indices) != len(pos):
indice_equivalents = {}
new_pos = []
new_pos_idx = 0
for i in indices:
if i[0] not in indice_equivalents.keys():
indice_equivalents[i[0]] = new_pos_idx
new_pos.append(pos[i[0]])
new_pos_idx += 1
indice_equivalents = {}
new_pos = []
new_pos_idx = 0
for i in indices:
if i[0] not in indice_equivalents.keys():
indice_equivalents[i[0]] = new_pos_idx
new_pos.append(pos[i[0]])
new_pos_idx += 1
prim_verts = [loc_gltf_to_blender(vert) for vert in new_pos]
prim_verts = [loc_gltf_to_blender(vert) for vert in new_pos]
else:
prim_verts = [loc_gltf_to_blender(vert) for vert in pos]
pyprimitive.vertices_length = len(prim_verts)
verts.extend(prim_verts)
prim_faces = []
@ -65,10 +62,7 @@ class BlenderPrimitive():
vals = indices[i:i + 3]
new_vals = []
for y in vals:
if len(indices) != len(pos):
new_vals.append(indice_equivalents[y[0]] + current_length)
else:
new_vals.append(y[0] + current_length)
new_vals.append(indice_equivalents[y[0]] + current_length)
prim_faces.append(tuple(new_vals))
faces.extend(prim_faces)
pyprimitive.faces_length = len(prim_faces)

View File

@ -153,8 +153,27 @@ class BlenderSkin():
idx_already_done = {}
if 'JOINTS_0' in prim.attributes.keys() and 'WEIGHTS_0' in prim.attributes.keys():
joint_ = BinaryData.get_data_from_accessor(gltf, prim.attributes['JOINTS_0'])
weight_ = BinaryData.get_data_from_accessor(gltf, prim.attributes['WEIGHTS_0'])
original_joint_ = BinaryData.get_data_from_accessor(gltf, prim.attributes['JOINTS_0'])
original_weight_ = BinaryData.get_data_from_accessor(gltf, prim.attributes['WEIGHTS_0'])
tmp_indices = {}
tmp_idx = 0
weight_ = []
for i in prim.tmp_indices:
if i[0] not in tmp_indices.keys():
tmp_indices[i[0]] = tmp_idx
tmp_idx += 1
weight_.append(original_weight_[i[0]])
tmp_indices = {}
tmp_idx = 0
joint_ = []
for i in prim.tmp_indices:
if i[0] not in tmp_indices.keys():
tmp_indices[i[0]] = tmp_idx
tmp_idx += 1
joint_.append(original_joint_[i[0]])
for poly in obj.data.polygons:
for loop_idx in range(poly.loop_start, poly.loop_start + poly.loop_total):