blob: ddbceab480e1cca9c3e63647b3542905351c10d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# Copyright 2018-2021 The glTF-Blender-IO authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import skdriverdiscovercache, skdrivervalues
from io_scene_gltf2.blender.com.gltf2_blender_data_path import get_target_object_path
@skdriverdiscovercache
def get_sk_drivers(blender_armature):
drivers = []
for child in blender_armature.children:
if not child.data:
continue
# child.data can be an armature - which has no shapekeys
if not hasattr(child.data, 'shape_keys'):
continue
if not child.data.shape_keys:
continue
if not child.data.shape_keys.animation_data:
continue
if not child.data.shape_keys.animation_data.drivers:
continue
if len(child.data.shape_keys.animation_data.drivers) <= 0:
continue
shapekeys_idx = {}
cpt_sk = 0
for sk in child.data.shape_keys.key_blocks:
if sk == sk.relative_key:
continue
if sk.mute is True:
continue
shapekeys_idx[sk.name] = cpt_sk
cpt_sk += 1
# Note: channels will have some None items only for SK if some SK are not animated
idx_channel_mapping = []
all_sorted_channels = []
for sk_c in child.data.shape_keys.animation_data.drivers:
sk_name = child.data.shape_keys.path_resolve(get_target_object_path(sk_c.data_path)).name
idx = shapekeys_idx[sk_name]
idx_channel_mapping.append((shapekeys_idx[sk_name], sk_c))
existing_idx = dict(idx_channel_mapping)
for i in range(0, cpt_sk):
if i not in existing_idx.keys():
all_sorted_channels.append(None)
else:
all_sorted_channels.append(existing_idx[i])
drivers.append((child, tuple(all_sorted_channels)))
return tuple(drivers)
@skdrivervalues
def get_sk_driver_values(blender_object, frame, fcurves):
sk_values = []
for f in [f for f in fcurves if f is not None]:
sk_values.append(blender_object.data.shape_keys.path_resolve(get_target_object_path(f.data_path)).value)
return tuple(sk_values)
|