-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanim_mask_animator.py
110 lines (85 loc) · 3.14 KB
/
anim_mask_animator.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
import bpy
from bpy.app.handlers import persistent
bl_info = {
"name": "Mask Animator",
"description": "Makes the Mask modifier animatable",
"author": "Pekka Heikkinen",
"version": (1, 1),
"location": "VIEW_3D > Tools > Animation",
"category": "Animation"
}
##########################
# Mask Animator handlers #
##########################
@persistent
def update_masks(scene):
sceneDirty = False
if 'Animated Masks' in bpy.data.groups:
for object in bpy.data.groups['Animated Masks'].objects:
if 'MaskIndex' in object and 'Mask' in object.modifiers:
if object.MaskIndex < len(object.vertex_groups):
object.modifiers["Mask"].vertex_group = object.vertex_groups[object.MaskIndex].name
sceneDirty = True
if sceneDirty:
scene.update()
def on_update_masks(self, context):
update_masks(context.scene)
bpy.types.Object.MaskIndex = bpy.props.IntProperty(name = "Mask Index", min=0, update=on_update_masks)
###########################
# Mask Animator Operators #
###########################
class SetMaskAnimation(bpy.types.Operator):
bl_idname = "maskanimation.setasanimated"
bl_label = "Set Mask Animation For Selected"
@classmethod
def poll(cls, context):
if context.active_object != None:
if 'Animated Masks' not in bpy.data.groups:
return True
else:
return bpy.data.groups['Animated Masks'] not in context.active_object.users_group
return False
def execute(self, context):
if 'Animated Masks' not in bpy.data.groups:
bpy.ops.group.create(name='Animated Masks')
bpy.ops.object.group_link(group='Animated Masks')
if 'MaskIndex' not in context.active_object:
context.active_object["MaskIndex"] = 0
if 'Mask' not in context.active_object.modifiers:
context.active_object.modifiers.new("Mask", type='MASK')
return {'FINISHED'}
####################
# Mask Animator UI #
####################
class MaskAnimatorPanel(bpy.types.Panel):
bl_label = "Mask Animator"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Animation"
@classmethod
def poll(cls, context):
return len(context.selected_objects) > 0
def draw(self, context):
layout = self.layout
scene = context.scene
row = layout.row()
row.operator(SetMaskAnimation.bl_idname)
##############################
# Mask Animator registration #
##############################
def register():
bpy.utils.register_module(__name__)
bpy.app.handlers.frame_change_post.append(update_masks)
bpy.app.handlers.render_pre.append(update_masks)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.app.handlers.frame_change_post.remove(update_masks)
bpy.app.handlers.render_pre.remove(update_masks)
########################
# Mask Animator Debug #
#######################
if __name__ == "__main__":
bpy.app.handlers.frame_change_post.clear()
bpy.app.handlers.frame_change_pre.clear()
bpy.app.handlers.render_pre.clear()
register()