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:
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_gltf.py')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_gltf.py38
1 files changed, 27 insertions, 11 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
index 33713b97..b1587ae2 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
@@ -158,22 +158,36 @@ class BlenderGlTF():
mesh.shapekey_names = []
used_names = set(['Basis']) #Be sure to not use 'Basis' name at import, this is a reserved name
- # 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:
+ # Look for primitive with morph targets
+ for prim in (mesh.primitives or []):
+ if not prim.targets:
+ continue
+
+ for sk, _ in enumerate(prim.targets):
+ # Skip shape key for target that doesn't morph POSITION
+ morphs_position = any(
+ (prim.targets and 'POSITION' in prim.targets[sk])
+ for prim in mesh.primitives
+ )
+ if not morphs_position:
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]
+
+ # Try to use name from extras.targetNames
+ try:
+ shapekey_name = str(mesh.extras['targetNames'][sk])
+ except Exception:
+ pass
+
+ # Try to get name from first primitive's POSITION accessor
if shapekey_name is None:
- if gltf.data.accessors[target['POSITION']].name is not None:
- shapekey_name = gltf.data.accessors[target['POSITION']].name
+ try:
+ shapekey_name = gltf.data.accessors[mesh.primitives[0].targets[sk]['POSITION']].name
+ except Exception:
+ pass
+
if shapekey_name is None:
shapekey_name = "target_" + str(sk)
@@ -182,6 +196,8 @@ class BlenderGlTF():
mesh.shapekey_names.append(shapekey_name)
+ break
+
# Manage KHR_materials_variants
BlenderGlTF.manage_material_variants(gltf)