forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOPESHEET_MT_key.py
112 lines (97 loc) · 3.78 KB
/
DOPESHEET_MT_key.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 「ドープシート」エリア > 「キー」メニュー
# "Dope Sheet" Area > "Key" Menu
import bpy
from bpy.props import *
################
# オペレーター #
################
class DeleteUnmessage(bpy.types.Operator):
bl_idname = "action.delete_unmessage"
bl_label = "Delete KeyFrames (without confirming)"
bl_description = "Remove all selected keyframes without displaying the confirmation message"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.action.delete()
return {'FINISHED'}
class CreanEX(bpy.types.Operator):
bl_idname = "action.crean_ex"
bl_label = "Delete Value-overlapping Keyframes"
bl_description = "Remove Value-overlapping keyframes of the displayed objects' actions"
bl_options = {'REGISTER', 'UNDO'}
keep_fcurves : BoolProperty(name="Keep At Least One Key", default=False)
threshold : FloatProperty(name="Threshold", default=0.00001, min=0, max=1, soft_min=0, soft_max=1, step=0.001, precision=5)
def execute(self, context):
threshold = self.threshold
animations = [ob.animation_data for ob in bpy.data.objects if ob.hide_get() == False]
action_datas = [an.action for an in animations if an != None and an.action != None]
for action in action_datas:
for fcurve in action.fcurves[:]:
if (not fcurve.modifiers):
delete_points = []
for i in reversed(range(len(fcurve.keyframe_points))):
now_point = fcurve.keyframe_points[i].co[1]
if (0 < i):
pre_point = fcurve.keyframe_points[i-1].co[1]
else:
#pre_point = now_point
pre_point = fcurve.keyframe_points[i+1].co[1]
try:
next_point = fcurve.keyframe_points[i+1].co[1]
except IndexError:
#next_point = now_point
next_point = fcurve.keyframe_points[i-1].co[1]
now_pre = (now_point-threshold <= pre_point <= now_point+threshold)
now_next = (now_point-threshold <= next_point <= now_point+threshold)
#pre_next = (pre_point-threshold <= next_point <= pre_point+threshold)
if (now_pre or now_next):#(now_pre and pre_next):
handle_left = fcurve.keyframe_points[i].handle_left[1]
handle_right = fcurve.keyframe_points[i].handle_right[1]
if (handle_left-threshold <= handle_right <= handle_left+threshold):
delete_points.append(fcurve.keyframe_points[i])
if self.keep_fcurves:
delete_points = delete_points[:-1]
for point in delete_points:
fcurve.keyframe_points.remove(point)
if len(fcurve.keyframe_points) == 0:
action.fcurves.remove(fcurve)
else:
nam = action.name + "'s " + fcurve.data_path + " "
self.report(type={'ERROR'}, message= nam + "is ignored")
for area in context.screen.areas:
area.tag_redraw()
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
################
# クラスの登録 #
################
classes = [
DeleteUnmessage,
CreanEX
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
################
# メニュー追加 #
################
# メニューのオン/オフの判定
def IsMenuEnable(self_id):
for id in bpy.context.preferences.addons[__name__.partition('.')[0]].preferences.disabled_menu.split(','):
if (id == self_id):
return False
else:
return True
# メニューを登録する関数
def menu(self, context):
if (IsMenuEnable(__name__.split('.')[-1])):
self.layout.separator()
self.layout.operator(DeleteUnmessage.bl_idname, icon="PLUGIN")
self.layout.separator()
self.layout.operator(CreanEX.bl_idname, icon="PLUGIN")
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.separator()
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]