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-09-26 17:35:44 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-09-26 17:36:19 +0300
commit06bb353c848921a3f68f928aea154d471555e2dc (patch)
treecdc7b31572513f298a0217797354d07a45b4738c /io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
parenta89261a31c6c109b735d06c025ab15a950b14c40 (diff)
glTF importer: big perf improvement
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_gltf.py')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_gltf.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
index 0f603bf3..c0507c03 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
@@ -109,10 +109,6 @@ class BlenderGlTF():
# Init is to False, and will be set to True during creation
gltf.animation_object = False
- # Store shapekeys equivalent between target & shapekey index
- # For example when no POSITION on target
- gltf.shapekeys = {}
-
# Blender material
if gltf.data.materials:
for material in gltf.data.materials:
@@ -281,6 +277,33 @@ class BlenderGlTF():
mesh.blender_name = None
mesh.is_weight_animated = False
+ # Calculate names for each mesh's shapekeys
+ for mesh in gltf.data.meshes:
+ 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
+
+ # 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):
"""Finds a name not in haystack and <= 63 UTF-8 bytes.