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
This commit is contained in:
Julien Duroure 2019-02-21 14:47:23 +01:00
parent 62af5c6886
commit a6df2542ba
3 changed files with 24 additions and 9 deletions

View File

@ -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

View File

@ -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:

View File

@ -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.