diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-02-21 16:47:23 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-02-21 16:47:23 +0300 |
commit | a6df2542ba1031416e792cc978fbe7796f450818 (patch) | |
tree | 90beaadb6213511111eaaeeb4c74f7dd5b5be02d | |
parent | 62af5c68867f187a2c05463890d90eae415c99ba (diff) |
glTF importer: Fix bug importing some morph targsts with no POSITION
Do not create a shapekey in that case, ignoring animation on this morph target too
-rwxr-xr-x | io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py | 13 | ||||
-rwxr-xr-x | io_scene_gltf2/blender/imp/gltf2_blender_gltf.py | 4 | ||||
-rwxr-xr-x | io_scene_gltf2/blender/imp/gltf2_blender_mesh.py | 16 |
3 files changed, 24 insertions, 9 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py index d8aa33a7..0be98a06 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py @@ -140,12 +140,13 @@ class BlenderNodeAnim(): for idx, key in enumerate(keys): for sk in range(nb_targets): - obj.data.shape_keys.key_blocks[sk + 1].value = values[idx * nb_targets + sk][0] - obj.data.shape_keys.key_blocks[sk + 1].keyframe_insert( - "value", - frame=key[0] * fps, - group='ShapeKeys' - ) + if gltf.shapekeys[sk] is not None: # Do not animate shapekeys not created + obj.data.shape_keys.key_blocks[gltf.shapekeys[sk]].value = values[idx * nb_targets + sk][0] + obj.data.shape_keys.key_blocks[gltf.shapekeys[sk]].keyframe_insert( + "value", + frame=key[0] * fps, + group='ShapeKeys' + ) if action.name not in gltf.current_animation_names.keys(): gltf.current_animation_names[name] = action.name diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py index bdf8e7f6..3f55f933 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py @@ -86,6 +86,10 @@ 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: diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py index c083d8d6..4439a05c 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py @@ -108,9 +108,16 @@ class BlenderMesh(): if max_shape_to_create > 0: obj.shape_key_add(name="Basis") + current_shapekey_index = 0 for i in range(max_shape_to_create): + # Check if this target has POSITION + if 'POSITION' not in prim.targets[i].keys(): + gltf.shapekeys[i] = None + continue + obj.shape_key_add(name="target_" + str(i)) + current_shapekey_index += 1 offset_idx = 0 for prim in pymesh.primitives: @@ -122,7 +129,8 @@ class BlenderMesh(): bm = bmesh.new() bm.from_mesh(mesh) - shape_layer = bm.verts.layers.shape[i + 1] + shape_layer = bm.verts.layers.shape[current_shapekey_index] + gltf.shapekeys[i] = current_shapekey_index pos = BinaryData.get_data_from_accessor(gltf, prim.targets[i]['POSITION']) @@ -145,9 +153,11 @@ class BlenderMesh(): if pymesh.weights is not None: for i in range(max_shape_to_create): if i < len(pymesh.weights): - obj.data.shape_keys.key_blocks[i + 1].value = pymesh.weights[i] + if gltf.shapekeys[i] is None: # No default value if shapekeys was not created + continue + obj.data.shape_keys.key_blocks[gltf.shapekeys[i]].value = pymesh.weights[i] if gltf.data.accessors[pymesh.primitives[0].targets[i]['POSITION']].name is not None: - obj.data.shape_keys.key_blocks[i + 1].name = \ + obj.data.shape_keys.key_blocks[gltf.shapekeys[i]].name = \ gltf.data.accessors[pymesh.primitives[0].targets[i]['POSITION']].name # Apply vertex color. |