Welcome to mirror list, hosted at ThFree Co, Russian Federation.

animation_rotobezier.py - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b92fc32a428a54128dbfc97d4ee4520f430fafd (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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
    'name': 'RotoBezier',
    'author': 'Daniel Salazar <zanqdo@gmail.com>',
    'version': (0, 8),
    "blender": (2, 5, 7),
    "api": 35622,
    'location': 'Select a Curve: Tool Shelf > RotoBezier Panel',
    'description': 'Allows animation of Bezier and NURBS curves',
    'warning': '',
    'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/'\
        'Scripts/Animation/RotoBezier',
    'tracker_url': 'http://projects.blender.org/tracker/index.php?'\
        'func=detail&aid=24839',
    'category': 'Animation'}

'''
-------------------------------------------------------------------------
Thanks to Campbell Barton for his API additions and fixes
Daniel Salazar - ZanQdo

Rev 0.1 Initial release
Rev 0.2 New make matte object tools and convenient display toggles
Rev 0.3 Tool to clear all animation from the curve
Rev 0.4 Moved from curve properties to toolbar
Rev 0.5 Added pass index property
Rev 0.6 Re-arranged UI
Rev 0.7 Adding options for what properties to keyframe
Rev 0.8 Allowing to key NURBS
-------------------------------------------------------------------------
'''

import bpy
from bpy.props import *


#
# Property Definitions
#
bpy.types.WindowManager.key_points = BoolProperty(
    name="Points",
    description="Insert keyframes on point locations",
    default=True)

bpy.types.WindowManager.key_radius = BoolProperty(
    name="Radius",
    description="Insert keyframes on point radius (Shrink/Fatten)",
    default=False)

bpy.types.WindowManager.key_tilt = BoolProperty(
    name="Tilt",
    description="Insert keyframes on point tilt",
    default=False)


#
# GUI (Panel)
#
class VIEW3D_PT_rotobezier(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_label = 'RotoBezier'

    # show this add-on only in the Camera-Data-Panel
    @classmethod
    def poll(self, context):
        if context.active_object:
            return context.active_object.type  == 'CURVE'
    
    # draw the gui
    def draw(self, context):
        layout = self.layout
        
        col = layout.column(align=True)
        
        col.label(text="Keyframing:")
        row = col.row()
        row.prop(context.window_manager, "key_points")
        row.prop(context.window_manager, "key_radius")
        row.prop(context.window_manager, "key_tilt")
        
        row = col.row()
        row.operator('curve.insert_keyframe_rotobezier', icon='KEY_HLT')
        row.operator('curve.delete_keyframe_rotobezier', icon='KEY_DEHLT')
        row = layout.row()
        row.operator('curve.clear_animation_rotobezier', icon='X')
        
        col = layout.column()
        
        col.label(text="Display:")
        row = col.row()
        row.operator('curve.toggle_draw_rotobezier', icon='MESH_CIRCLE')
        
        if context.mode == 'EDIT_CURVE':
            row.operator('curve.toggle_handles_rotobezier', icon='CURVE_BEZCIRCLE')
        
        col = layout.column(align=True)
        
        col.label(text="Tools:")
        row = col.row()
        row.operator('curve.make_white_matte_rotobezier')
        row.operator('curve.make_black_matte_rotobezier')
        row = layout.row()
        ob = context.active_object
        row.prop(ob, "pass_index")


class CURVE_OT_insert_keyframe_rotobezier(bpy.types.Operator):
    bl_label = 'Insert'
    bl_idname = 'curve.insert_keyframe_rotobezier'
    bl_description = 'Insert/Replace all Keyframes in current frame'
    bl_options = {'REGISTER', 'UNDO'}
    
    # on mouse up:
    def invoke(self, context, event):
        self.execute(context)
        return {'FINISHED'}
    
    @classmethod
    def poll(cls, context):
        return (context.active_object.type == 'CURVE')
    
    def execute(op, context):
        
        Obj = context.active_object
        
        Mode = False
        if context.mode != 'OBJECT':
            Mode = not Mode
            bpy.ops.object.editmode_toggle()
        Data = Obj.data
        
        for Spline in Data.splines:
            if Spline.type == 'BEZIER':
                for CV in Spline.bezier_points:
                    if context.window_manager.key_points:
                        CV.keyframe_insert('co')
                        CV.keyframe_insert('handle_left')
                        CV.keyframe_insert('handle_right')
                    if context.window_manager.key_radius:
                        CV.keyframe_insert('radius')
                    if context.window_manager.key_tilt:
                        CV.keyframe_insert('tilt')
                    
            elif Spline.type == 'NURBS':
                for CV in Spline.points:
                    if context.window_manager.key_points:
                        CV.keyframe_insert('co')
                    if context.window_manager.key_radius:
                        CV.keyframe_insert('radius')
                    if context.window_manager.key_tilt:
                        CV.keyframe_insert('tilt')
                        
        if Mode:
            bpy.ops.object.editmode_toggle()


        return {'FINISHED'}


class CURVE_OT_delete_keyframe_rotobezier(bpy.types.Operator):
    bl_label = 'Delete'
    bl_idname = 'curve.delete_keyframe_rotobezier'
    bl_description = 'Delete all keyframes in current frame'
    bl_options = {'REGISTER', 'UNDO'}
    
    # on mouse up:
    def invoke(self, context, event):
        self.execute(context)
        return {'FINISHED'}

    @classmethod
    def poll(cls, context):
        return (context.active_object.type == 'CURVE')

    def execute(op, context):
        
        Obj = context.active_object

        Mode = False
        if context.mode != 'OBJECT':
            Mode = not Mode
            bpy.ops.object.editmode_toggle()
        Data = Obj.data
        
        for Spline in Data.splines:
            if Spline.type == 'BEZIER':
                for CV in Spline.bezier_points:
                    if context.window_manager.key_points:
                        CV.keyframe_delete('co')
                        CV.keyframe_delete('handle_left')
                        CV.keyframe_delete('handle_right')
                    if context.window_manager.key_radius:
                        CV.keyframe_delete('radius')
                    if context.window_manager.key_tilt:
                        CV.keyframe_delete('tilt')
                    
            elif Spline.type == 'NURBS':
                for CV in Spline.points:
                    if context.window_manager.key_points:
                        CV.keyframe_delete('co')
                    if context.window_manager.key_radius:
                        CV.keyframe_delete('radius')
                    if context.window_manager.key_tilt:
                        CV.keyframe_delete('tilt')
                        
        if Mode:
            bpy.ops.object.editmode_toggle()

        return {'FINISHED'}


class CURVE_OT_clear_animation_rotobezier(bpy.types.Operator):
    bl_label = 'Clear Animation'
    bl_idname = 'curve.clear_animation_rotobezier'
    bl_description = 'Clear all animation from the curve'
    bl_options = {'REGISTER', 'UNDO'}

    # on mouse up:
    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_confirm(self, event)
    
    def execute(op, context):
        Data = context.active_object.data
        Data.animation_data_clear()
        return {'FINISHED'}


def MakeMatte (Type):
    '''
    Matte Material Assignment Function
    '''
    
    Obj = bpy.context.active_object
    
    # Material
    
    if Type == 'White':
        MatName = 'RotoBezier_WhiteMatte'
        MatCol = (1,1,1)

    elif Type == 'Black':
        MatName = 'RotoBezier_BlackMatte'
        MatCol = (0,0,0)

    if bpy.data.materials.get(MatName):
        Mat = bpy.data.materials[MatName]
        if not Obj.material_slots:
            bpy.ops.object.material_slot_add()
        Obj.material_slots[0].material = Mat
    
    else:
        Mat = bpy.data.materials.new(MatName)
        Mat.diffuse_color = MatCol
        Mat.use_shadeless = True
        Mat.use_raytrace = False
        Mat.use_shadows = False
        Mat.use_cast_buffer_shadows = False
        Mat.use_cast_approximate = False
        
        if not Obj.material_slots:
            bpy.ops.object.material_slot_add()
            
        Obj.material_slots[0].material = Mat
    
    # Settings
    Curve = Obj.data
    
    Curve.dimensions = '2D'
    Curve.use_fill_front = False
    Curve.use_fill_back = False


class CURVE_OT_make_white_matte_rotobezier(bpy.types.Operator):
    bl_label = 'White Matte'
    bl_idname = 'curve.make_white_matte_rotobezier'
    bl_description = 'Make this curve a white matte'
    bl_options = {'REGISTER', 'UNDO'}

    # on mouse up:
    def invoke(self, context, event):
        self.execute(context)
        return {'FINISHED'}

    def execute(op, context):
        MakeMatte('White')
        return {'FINISHED'}


class CURVE_OT_make_black_matte_rotobezier(bpy.types.Operator):
    bl_label = 'Black Matte'
    bl_idname = 'curve.make_black_matte_rotobezier'
    bl_description = 'Make this curve a black matte'
    bl_options = {'REGISTER', 'UNDO'}

    # on mouse up:
    def invoke(self, context, event):
        self.execute(context)
        return {'FINISHED'}

    def execute(op, context):
        MakeMatte('Black')
        return {'FINISHED'}


class CURVE_OT_toggle_handles_rotobezier(bpy.types.Operator):
    bl_label = 'Handles'
    bl_idname = 'curve.toggle_handles_rotobezier'
    bl_description = 'Toggle the curve handles display in edit mode'
    bl_options = {'REGISTER', 'UNDO'}

    # on mouse up:
    def invoke(self, context, event):
        self.execute(context)
        return {'FINISHED'}
    
    def execute(op, context):
        Obj = context.active_object
        Curve = Obj.data
        if Curve.show_handles:
            Curve.show_handles = False
        else:
            Curve.show_handles = True
        return {'FINISHED'}


class CURVE_OT_toggle_draw_rotobezier(bpy.types.Operator):
    bl_label = 'Filling'
    bl_idname = 'curve.toggle_draw_rotobezier'
    bl_description = 'Toggle the curve display mode between Wire and Solid'
    bl_options = {'REGISTER', 'UNDO'}

    # on mouse up:
    def invoke(self, context, event):
        self.execute(context)
        return {'FINISHED'}
    
    def execute(op, context):
        Obj = context.active_object
        
        if Obj.draw_type == 'SOLID':
            Obj.draw_type = 'WIRE'
            
        elif Obj.draw_type == 'WIRE':
            Obj.draw_type = 'SOLID'
            
        else:
            Obj.draw_type = 'WIRE'
        
        return {'FINISHED'}


def register():
    bpy.utils.register_module(__name__)

    pass
    
def unregister():
    bpy.utils.unregister_module(__name__)

    pass
    
if __name__ == "__main__":
    register()