-
Notifications
You must be signed in to change notification settings - Fork 33
/
ops_shapekey.py
98 lines (73 loc) · 2.97 KB
/
ops_shapekey.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# SPDX-FileCopyrightText: 2014-2024 Mikhail Rachinskiy
# SPDX-License-Identifier: GPL-3.0-or-later
from bpy.props import EnumProperty
from bpy.types import Operator
class OBJECT_OT_sk_coll_refresh(Operator):
bl_label = "Refresh"
bl_description = "Refresh shape key list for active object"
bl_idname = "object.commotion_sk_coll_refresh"
bl_options = {"REGISTER", "UNDO", "INTERNAL"}
def execute(self, context):
skcoll = context.window_manager.commotion.skcoll
skcoll.clear()
for kb in context.object.data.shape_keys.key_blocks:
skcoll.add()
return {"FINISHED"}
def invoke(self, context, event):
try:
context.object.data.shape_keys.key_blocks
except AttributeError:
self.report({"ERROR"}, "Object has no Shape Keys")
return {"CANCELLED"}
return self.execute(context)
class OBJECT_OT_sk_interpolation_set(Operator):
bl_label = "Set Interpolation"
bl_description = "Set interpolation type for selected shape keys"
bl_idname = "object.commotion_sk_interpolation_set"
bl_options = {"REGISTER", "UNDO", "INTERNAL"}
interp: EnumProperty(
name="Interpolation",
description="Interpolation type for absolute shape keys",
items=(
("KEY_LINEAR", "Linear", ""),
("KEY_CARDINAL", "Cardinal", ""),
("KEY_CATMULL_ROM", "Catmull-Rom", ""),
("KEY_BSPLINE", "BSpline", ""),
),
)
def execute(self, context):
skcoll = context.window_manager.commotion.skcoll
for ob in context.selected_objects:
try:
kbs = ob.data.shape_keys.key_blocks
except AttributeError:
continue
for i, kb in enumerate(kbs):
if skcoll[i].selected:
kb.interpolation = self.interp
return {"FINISHED"}
class ANIM_OT_sk_generate_keyframes(Operator):
bl_label = "Shape Key Generate Keyframes"
bl_description = (
"Create keyframes for absolute shape keys on selected objects, "
"based on the current frame and shape keys timings"
)
bl_idname = "anim.commotion_sk_generate_keyframes"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
frame_start = context.scene.frame_current
for ob in context.selected_objects:
try:
sk = ob.data.shape_keys
kbs = sk.key_blocks
except AttributeError:
continue
if not sk.use_relative:
sk.eval_time = int(kbs[1].frame)
sk.keyframe_insert(data_path="eval_time", frame=frame_start)
frame_end = int(kbs[-1].frame)
sk.eval_time = frame_end
sk.keyframe_insert(data_path="eval_time", frame=frame_start + frame_end)
for fcu in sk.animation_data.action.fcurves:
fcu.color_mode = "AUTO_RAINBOW"
return {"FINISHED"}