forked from samytichadou/fcurve_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator_add_modifier.py
107 lines (89 loc) · 5.44 KB
/
operator_add_modifier.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
import bpy
from .draw_functions import *
from .functions import getSelectedObjects, getSelectedBonesFCurves, getSelectedFCurves, setPropertiesFromDataset, redrawContextAreas
from .startup_handler import createDummyProperties
#operator to add modifier if needed
class FCurveHelperAddModifier(bpy.types.Operator):
"""Add or Modify Modifiers to selected FCurves"""
bl_idname = "fcurvehelper.add_modifier"
bl_label = "Add Modifiers"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
return True
def __init__(self):
createDummyProperties()
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
wm = context.window_manager
layout = self.layout
common_props = wm.fcurvehelper_commonproperties[0]
### TODO ### show affected fcurves
layout.prop(wm, 'fcurvehelper_fcurve_type')
layout.prop(wm, 'fcurvehelper_add_mode')
col = layout.column(align=True)
box = col.box()
row = box.row(align=False)
row.prop(wm, 'fcurvehelper_modifiers_list', text = "")
row.prop(common_props, 'mute')
row.operator("fcurvehelper.copy_active_modifier", text = "Copy Active")
### MODIFIER PROPERTIES ###
box = col.box()
if wm.fcurvehelper_modifiers_list == 'GENERATOR': drawGeneratorProperties(box, context)
elif wm.fcurvehelper_modifiers_list == 'FNGENERATOR': drawFNGeneratorProperties(box, context)
elif wm.fcurvehelper_modifiers_list == 'ENVELOPE': drawEnvelopeProperties(box, context)
elif wm.fcurvehelper_modifiers_list == 'CYCLES': drawCyclesProperties(box, context)
elif wm.fcurvehelper_modifiers_list == 'NOISE': drawNoiseProperties(box, context)
elif wm.fcurvehelper_modifiers_list == 'LIMITS': drawLimitsProperties(box, context)
elif wm.fcurvehelper_modifiers_list == 'STEPPED': drawSteppedProperties(box, context)
### COMMON PROPERTIES ###
box = col.box()
drawCommonProperties(box, context)
def execute(self, context):
wm = context.window_manager
common_props = wm.fcurvehelper_commonproperties[0]
if wm.fcurvehelper_debug: print("FCurveHelper --- starting add/modify operator") ###debug
for obj in getSelectedObjects(context.scene):
if wm.fcurvehelper_fcurve_type == 'AUTO':
if context.mode == 'POSE': curve_list = getSelectedBonesFCurves(obj)
else: curve_list = getSelectedFCurves(obj)
elif wm.fcurvehelper_fcurve_type == 'BONE': curve_list = getSelectedBonesFCurves(obj)
else: curve_list = getSelectedFCurves(obj)
for curve in curve_list:
if not curve.lock:
modifier = ''
if wm.fcurvehelper_debug: print("FCurveHelper --- treating FCurve : " + curve.data_path) ###debug
# add mode
if wm.fcurvehelper_add_mode == 'ADD':
modifier = curve.modifiers.new(type=wm.fcurvehelper_modifiers_list)
# add and modify mode
else:
if curve.modifiers:
chk_mod = 0
for mod in curve.modifiers:
if mod.type == wm.fcurvehelper_modifiers_list:
modifier = mod
chk_mod = 1
break
if chk_mod == 0 and wm.fcurvehelper_add_mode == 'ADD_MODIFY':
modifier = curve.modifiers.new(type = wm.fcurvehelper_modifiers_list)
else:
if wm.fcurvehelper_add_mode == 'ADD_MODIFY':
modifier = curve.modifiers.new(type = wm.fcurvehelper_modifiers_list)
#set modifier keys
if modifier != '':
setPropertiesFromDataset(common_props, modifier)
if wm.fcurvehelper_modifiers_list == 'GENERATOR': setPropertiesFromDataset(wm.fcurvehelper_generatorproperties[0], modifier)
elif wm.fcurvehelper_modifiers_list == 'FNGENERATOR': setPropertiesFromDataset(wm.fcurvehelper_fngeneratorproperties[0], modifier)
elif wm.fcurvehelper_modifiers_list == 'ENVELOPE': setPropertiesFromDataset(wm.fcurvehelper_envelopeproperties[0], modifier)
elif wm.fcurvehelper_modifiers_list == 'CYCLES': setPropertiesFromDataset(wm.fcurvehelper_cyclesproperties[0], modifier)
elif wm.fcurvehelper_modifiers_list == 'NOISE': setPropertiesFromDataset(wm.fcurvehelper_noiseproperties[0], modifier)
elif wm.fcurvehelper_modifiers_list == 'LIMITS': setPropertiesFromDataset(wm.fcurvehelper_limitsproperties[0], modifier)
elif wm.fcurvehelper_modifiers_list == 'STEPPED': setPropertiesFromDataset(wm.fcurvehelper_steppedproperties[0], modifier)
else: ###debug
if wm.fcurvehelper_debug: print("FCurveHelper --- no modifier to set") ###debug
### TODO ### print log
### TODO ### return info log
redrawContextAreas(context)
return {'FINISHED'}