Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2019-10-08 23:02:44 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-10-08 23:02:44 +0300
commita1dbf26e376ce6b7772c46eb68365008ec144bf9 (patch)
tree8bc50fe34821b9c6fd3c775e150fa8864b0ac35d /io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
parentcb4e5b248c8a1c438b1228380bbf41b9ddf6fd90 (diff)
glTF importer: check that primitive exists (some invalid glTF files don't have any)
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_gltf.py')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_gltf.py42
1 files changed, 22 insertions, 20 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
index 6d2181fc..5904a974 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
@@ -282,27 +282,29 @@ class BlenderGlTF():
mesh.shapekey_names = []
used_names = set()
- for sk, target in enumerate(mesh.primitives[0].targets or []):
- if 'POSITION' not in target:
- mesh.shapekey_names.append(None)
- continue
+ # Some invalid glTF files has empty primitive tab
+ if len(mesh.primitives) > 0:
+ for sk, target in enumerate(mesh.primitives[0].targets or []):
+ if 'POSITION' not in target:
+ mesh.shapekey_names.append(None)
+ continue
- # Check if glTF file has some extras with targetNames. Otherwise
- # use the name of the POSITION accessor on the first primitive.
- shapekey_name = None
- if mesh.extras is not None:
- if 'targetNames' in mesh.extras and sk < len(mesh.extras['targetNames']):
- shapekey_name = mesh.extras['targetNames'][sk]
- if shapekey_name is None:
- if gltf.data.accessors[target['POSITION']].name is not None:
- shapekey_name = gltf.data.accessors[target['POSITION']].name
- if shapekey_name is None:
- shapekey_name = "target_" + str(sk)
-
- shapekey_name = BlenderGlTF.find_unused_name(used_names, shapekey_name)
- used_names.add(shapekey_name)
-
- mesh.shapekey_names.append(shapekey_name)
+ # Check if glTF file has some extras with targetNames. Otherwise
+ # use the name of the POSITION accessor on the first primitive.
+ shapekey_name = None
+ if mesh.extras is not None:
+ if 'targetNames' in mesh.extras and sk < len(mesh.extras['targetNames']):
+ shapekey_name = mesh.extras['targetNames'][sk]
+ if shapekey_name is None:
+ if gltf.data.accessors[target['POSITION']].name is not None:
+ shapekey_name = gltf.data.accessors[target['POSITION']].name
+ if shapekey_name is None:
+ shapekey_name = "target_" + str(sk)
+
+ shapekey_name = BlenderGlTF.find_unused_name(used_names, shapekey_name)
+ used_names.add(shapekey_name)
+
+ mesh.shapekey_names.append(shapekey_name)
@staticmethod
def find_unused_name(haystack, desired_name):