[Bf-extensions-cvs] [0852abc7] master: glTF importer: fix skinning for meshes where indices doesn't match data

Julien Duroure noreply at git.blender.org
Fri Feb 22 09:46:17 CET 2019


Commit: 0852abc7a99457032e3aeb3328da9d0ad48cdfa9
Author: Julien Duroure
Date:   Fri Feb 22 09:44:59 2019 +0100
Branches: master
https://developer.blender.org/rBA0852abc7a99457032e3aeb3328da9d0ad48cdfa9

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

This was a regression from previous commit

===================================================================

M	io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
M	io_scene_gltf2/blender/imp/gltf2_blender_skin.py

===================================================================

diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
index 76f49697..5f6eaaba 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
@@ -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
-
-            prim_verts = [loc_gltf_to_blender(vert) for vert in new_pos]
-        else:
-            prim_verts = [loc_gltf_to_blender(vert) for vert in 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
+
+        prim_verts = [loc_gltf_to_blender(vert) for vert in new_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)
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_skin.py b/io_scene_gltf2/blender/imp/gltf2_blender_skin.py
index 2419b73e..b2b39a2b 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_skin.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_skin.py
@@ -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):



More information about the Bf-extensions-cvs mailing list