diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-02-22 02:34:18 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-02-22 02:34:18 +0300 |
commit | b7769e098a6d4539a3017ab58567f348385f63ea (patch) | |
tree | 43e3b49ce120fdb7a98edf78d9832dc5f3b40063 /io_scene_gltf2 | |
parent | 2ee886c25b107bd716591a12c74fb180997af2c8 (diff) |
glTF importer: fix importing too much vertices when indices tab has no same length than data
Diffstat (limited to 'io_scene_gltf2')
-rwxr-xr-x | io_scene_gltf2/blender/imp/gltf2_blender_primitive.py | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py index 59e13391..76f49697 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py @@ -41,7 +41,23 @@ class BlenderPrimitive(): for i in indices_: indices.append((i,)) - prim_verts = [loc_gltf_to_blender(vert) for vert in pos] + 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] pyprimitive.vertices_length = len(prim_verts) verts.extend(prim_verts) prim_faces = [] @@ -49,7 +65,10 @@ class BlenderPrimitive(): vals = indices[i:i + 3] new_vals = [] for y in vals: - new_vals.append(y[0] + current_length) + if len(indices) != len(pos): + new_vals.append(indice_equivalents[y[0]] + current_length) + else: + new_vals.append(y[0] + current_length) prim_faces.append(tuple(new_vals)) faces.extend(prim_faces) pyprimitive.faces_length = len(prim_faces) @@ -75,7 +94,17 @@ class BlenderPrimitive(): def set_normals(gltf, pyprimitive, mesh, offset, custom_normals): """Set Normal.""" if 'NORMAL' in pyprimitive.attributes.keys(): - normal_data = BinaryData.get_data_from_accessor(gltf, pyprimitive.attributes['NORMAL']) + original_normal_data = BinaryData.get_data_from_accessor(gltf, pyprimitive.attributes['NORMAL']) + + tmp_indices = {} + tmp_idx = 0 + normal_data = [] + for i in pyprimitive.tmp_indices: + if i[0] not in tmp_indices.keys(): + tmp_indices[i[0]] = tmp_idx + tmp_idx += 1 + normal_data.append(original_normal_data[i[0]]) + for poly in mesh.polygons: if gltf.import_settings['import_shading'] == "NORMALS": calc_norm_vertices = [] @@ -120,7 +149,18 @@ class BlenderPrimitive(): mesh.uv_layers.new(name=texcoord) pyprimitive.blender_texcoord[int(texcoord[9:])] = texcoord - texcoord_data = BinaryData.get_data_from_accessor(gltf, pyprimitive.attributes[texcoord]) + original_texcoord_data = BinaryData.get_data_from_accessor(gltf, pyprimitive.attributes[texcoord]) + + + tmp_indices = {} + tmp_idx = 0 + texcoord_data = [] + for i in pyprimitive.tmp_indices: + if i[0] not in tmp_indices.keys(): + tmp_indices[i[0]] = tmp_idx + tmp_idx += 1 + texcoord_data.append(original_texcoord_data[i[0]]) + for poly in mesh.polygons: for loop_idx in range(poly.loop_start, poly.loop_start + poly.loop_total): vert_idx = mesh.loops[loop_idx].vertex_index |