Dynamic Paint:
[blender.git] / release / scripts / startup / bl_ui / properties_physics_dynamicpaint.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 from bl_ui.properties_physics_common import (
23     point_cache_ui,
24     effector_weights_ui,
25     )
26
27 class PhysicButtonsPanel():
28     bl_space_type = 'PROPERTIES'
29     bl_region_type = 'WINDOW'
30     bl_context = "physics"
31
32     @classmethod
33     def poll(cls, context):
34         ob = context.object
35         rd = context.scene.render
36         return (ob and ob.type == 'MESH') and (not rd.use_game_engine) and (context.dynamic_paint)
37
38
39 class PHYSICS_PT_dynamic_paint(PhysicButtonsPanel, bpy.types.Panel):
40     bl_label = "Dynamic Paint"
41
42     def draw(self, context):
43         layout = self.layout
44
45         md = context.dynamic_paint
46         ob = context.object
47
48         if md:
49             layout.prop(md, "ui_type", expand=True)
50
51             if (md.ui_type == "CANVAS"):
52                 canvas = md.canvas_settings
53                 
54                 if (not canvas):
55                     layout.operator("dpaint.type_toggle", text="Add Canvas").type = 'CANVAS'
56                 else:
57                     layout.operator("dpaint.type_toggle", text="Remove Canvas", icon='X').type = 'CANVAS'
58
59                     surface = canvas.canvas_surfaces.active
60                     row = layout.row()
61                     row.template_list(canvas, "canvas_surfaces", canvas.canvas_surfaces, "active_index", rows=2)
62
63                     col = row.column(align=True)
64                     col.operator("dpaint.surface_slot_add", icon='ZOOMIN', text="")
65                     col.operator("dpaint.surface_slot_remove", icon='ZOOMOUT', text="")
66                     
67                     if surface:
68                         layout.prop(surface, "name")
69                         layout.prop(surface, "surface_format", expand=False)
70                         col = layout.column()
71                         
72                         if surface.surface_format != "VERTEX":
73                             col.label(text="Quality:")
74                             col.prop(surface, "image_resolution")
75                         col.prop(surface, "use_anti_aliasing")
76                     
77                         col = layout.column()
78                         col.label(text="Frames:")
79                         split = col.split()
80                     
81                         col = split.column(align=True)
82                         col.prop(surface, "start_frame", text="Start")
83                         col.prop(surface, "end_frame", text="End")
84                     
85                         col = split.column()
86                         col.prop(surface, "substeps")
87
88             elif (md.ui_type == "BRUSH"):
89                 brush = md.brush_settings
90                 
91                 if (not brush):
92                     layout.operator("dpaint.type_toggle", text="Add Brush").type = 'BRUSH'
93                 else:
94                     layout.operator("dpaint.type_toggle", text="Remove Brush", icon='X').type = 'BRUSH'
95                     
96                     layout.prop(brush, "brush_settings_context", expand=True, icon_only=True)
97                     
98                     if (brush.brush_settings_context == "GENERAL"):
99                         split = layout.split()
100
101                         col = split.column()
102                         col.prop(brush, "absolute_alpha")
103                         col.prop(brush, "paint_erase")
104                         col.prop(brush, "paint_wetness", text="Wetness")
105                     
106                         col = split.column()
107                         sub = col.column()
108                         sub.active = (brush.paint_source != "PSYS");
109                         sub.prop(brush, "use_material")
110                         if brush.use_material and brush.paint_source != "PSYS":
111                             col.prop(brush, "material", text="")
112                             col.prop(brush, "paint_alpha", text="Alpha Factor")
113                         else:
114                             col.prop(brush, "paint_color", text="")
115                             col.prop(brush, "paint_alpha", text="Alpha")
116                     
117                     elif (brush.brush_settings_context == "WAVE"):
118                         layout.prop(brush, "wave_type")
119                         if (brush.wave_type != "REFLECT"):
120                             split = layout.split(percentage=0.6)
121                             split.prop(brush, "wave_factor")
122                     elif (brush.brush_settings_context == "VELOCITY"):
123                         col = layout.row().column()
124                         col.label(text="Velocity Settings:")
125                         split = layout.split()
126                         col = split.column()
127                         col.prop(brush, "velocity_alpha")
128                         col.prop(brush, "velocity_color")
129                         col = split.column()
130                         col.prop(brush, "velocity_depth")
131                         sub = layout.row().column()
132                         sub.active = (brush.velocity_alpha or brush.velocity_color or brush.velocity_depth)
133                         sub.prop(brush, "max_velocity")
134                         sub.template_color_ramp(brush, "velocity_ramp", expand=True)
135                         layout.separator()
136                         layout.label(text="Smudge:")
137                         layout.prop(brush, "do_smudge")
138                         layout.prop(brush, "smudge_strength")
139                     else:
140                         layout.label(text="-WIP-")
141
142
143 class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, bpy.types.Panel):
144     bl_label = "Dynamic Paint: Advanced"
145
146     @classmethod
147     def poll(cls, context):
148         md = context.dynamic_paint
149         return md and (md.ui_type == "CANVAS") and (md.canvas_settings) and (md.canvas_settings.canvas_surfaces.active)
150
151     def draw(self, context):
152         layout = self.layout
153
154         canvas = context.dynamic_paint.canvas_settings
155         surface = canvas.canvas_surfaces.active
156         ob = context.object
157
158         layout.prop(surface, "surface_type", expand=False)
159         layout.separator()
160
161         # dissolve
162         if (surface.surface_type == "PAINT"):
163             layout.label(text="Wetmap drying:")
164             split = layout.split(percentage=0.8)
165             split.prop(surface, "dry_speed", text="Dry Time")
166             split.prop(surface, "use_dry_log", text="Slow")
167             
168         if (surface.surface_type != "WAVE"):
169             if (surface.surface_type == "DISPLACE"):
170                 layout.prop(surface, "use_dissolve", text="Dissolve:")
171             elif (surface.surface_type == "WEIGHT"):
172                 layout.prop(surface, "use_dissolve", text="Fade:")
173             else:
174                 layout.prop(surface, "use_dissolve", text="Dissolve:")
175             sub = layout.column()
176             sub.active = surface.use_dissolve
177             split = sub.split(percentage=0.8)
178             split.prop(surface, "dissolve_speed", text="Time")
179             split.prop(surface, "use_dissolve_log", text="Slow")
180         
181         # per type settings
182         if (surface.surface_type == "DISPLACE"):
183             layout.prop(surface, "disp_clamp")
184             layout.prop(surface, "incremental_disp")
185             
186         if (surface.surface_type == "WAVE"):
187             layout.prop(surface, "wave_open_borders")
188             
189             split = layout.split()
190             
191             col = split.column(align=True)
192             col.prop(surface, "wave_timescale")
193             col.prop(surface, "wave_speed")
194             
195             col = split.column(align=True)
196             col.prop(surface, "wave_damping")
197             col.prop(surface, "wave_spring")
198             
199         layout.label(text="Brush Group:")
200         layout.prop(surface, "brush_group", text="")
201
202
203 class PHYSICS_PT_dp_canvas_output(PhysicButtonsPanel, bpy.types.Panel):
204     bl_label = "Dynamic Paint: Output"
205     bl_options = {'DEFAULT_CLOSED'}
206
207     @classmethod
208     def poll(cls, context):
209         md = context.dynamic_paint
210         if (not (md and (md.ui_type == "CANVAS") and (md.canvas_settings))):
211             return 0
212         surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
213         return (surface and not (surface.surface_format=="VERTEX" and (surface.surface_type=="DISPLACE" or surface.surface_type=="WAVE")))
214
215     def draw(self, context):
216         layout = self.layout
217
218         canvas = context.dynamic_paint.canvas_settings
219         surface = canvas.canvas_surfaces.active
220         ob = context.object
221         
222         # vertex format outputs
223         if (surface.surface_format == "VERTEX"):
224             if (surface.surface_type == "PAINT"):
225                 # paintmap output
226                 row = layout.row()
227                 row.prop_search(surface, "output_name", ob.data, "vertex_colors", text="Paintmap layer: ")
228                 ic = 'ZOOMIN'
229                 if (surface.output_exists(object=ob, index=0)):
230                     ic = 'ZOOMOUT'
231                 col = row.column(align=True)
232                 col.operator("dpaint.output_toggle", icon=ic, text="").index = 0
233                 
234                 # wetmap output
235                 row = layout.row()
236                 row.prop_search(surface, "output_name2", ob.data, "vertex_colors", text="Wetmap layer: ")
237                 ic = 'ZOOMIN'
238                 if (surface.output_exists(object=ob, index=1)):
239                     ic = 'ZOOMOUT'
240                 col = row.column(align=True)
241                 col.operator("dpaint.output_toggle", icon=ic, text="").index = 1
242             if (surface.surface_type == "WEIGHT"):
243                 row = layout.row()
244                 row.prop_search(surface, "output_name", ob, "vertex_groups", text="Vertex Group: ")
245                 ic = 'ZOOMIN'
246                 if (surface.output_exists(object=ob, index=0)):
247                     ic = 'ZOOMOUT'
248                 col = row.column(align=True)
249                 col.operator("dpaint.output_toggle", icon=ic, text="").index = 0
250
251         # image format outputs
252         if (surface.surface_format == "IMAGE"):
253             col = layout.column()
254             col.label(text="UV layer:")
255             col.prop_search(surface, "uv_layer", ob.data, "uv_textures", text="")
256             
257             col.separator()
258             col = layout.column()
259             col.prop(surface, "image_output_path", text="Output directory")
260             col.prop(surface, "image_fileformat", text="Image Format")
261             col.separator()
262             if (surface.surface_type == "PAINT"):
263                 split = col.split()
264                 col = split.column()
265                 col.prop(surface, "do_output1", text="Output Paintmaps:")
266                 sub = split.column()
267                 sub.prop(surface, "premultiply", text="Premultiply alpha")
268                 sub.active = surface.do_output1
269                 sub = layout.column()
270                 sub.active = surface.do_output1
271                 sub.prop(surface, "output_name", text="Filename: ")
272                 
273                 col = layout.column()
274                 col.prop(surface, "do_output2", text="Output Wetmaps:")
275                 sub = col.column()
276                 sub.active = surface.do_output2
277                 sub.prop(surface, "output_name2", text="Filename: ")
278             else:
279                 col.prop(surface, "output_name", text="Filename: ")
280                 if (surface.surface_type == "DISPLACE"):
281                     col.prop(surface, "disp_type", text="Displace Type")
282             
283             layout.separator()
284             layout.operator("dpaint.bake", text="Bake Image Sequence", icon='MOD_DYNAMICPAINT')
285             if len(canvas.ui_info) != 0:
286                 layout.label(text=canvas.ui_info)
287                 
288
289 class PHYSICS_PT_dp_effects(PhysicButtonsPanel, bpy.types.Panel):
290     bl_label = "Dynamic Paint: Effects"
291     bl_options = {'DEFAULT_CLOSED'}
292
293     @classmethod
294     def poll(cls, context):
295         md = context.dynamic_paint
296         if (not (md and (md.ui_type == "CANVAS") and (md.canvas_settings))):
297             return False;
298         surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
299         return surface and (surface.surface_type == "PAINT")
300
301     def draw(self, context):
302         layout = self.layout
303
304         canvas = context.dynamic_paint.canvas_settings
305         surface = canvas.canvas_surfaces.active
306
307         layout.prop(surface, "effect_ui", expand=True)
308
309         if surface.effect_ui == "SPREAD":
310             layout.prop(surface, "use_spread")
311             col = layout.column()
312             col.active = surface.use_spread
313             split = col.split()
314             sub = split.column()
315             sub.prop(surface, "spread_speed")
316             sub = split.column()
317             sub.prop(surface, "color_spread_speed")
318
319         elif surface.effect_ui == "DRIP":
320             layout.prop(surface, "use_drip")
321             col = layout.column()
322             col.active = surface.use_drip
323             effector_weights_ui(self, context, surface.effector_weights)
324             split = layout.split()
325
326             layout.label(text="Surface Movement:")
327             split = layout.split()
328             col = split.column()
329             col.prop(surface, "drip_velocity", slider=True)
330             col = split.column()
331             col.prop(surface, "drip_acceleration", slider=True)
332
333         elif surface.effect_ui == "SHRINK":
334             layout.prop(surface, "use_shrink")
335             col = layout.column()
336             col.active = surface.use_shrink
337             col.prop(surface, "shrink_speed")
338                         
339
340 class PHYSICS_PT_dp_cache(PhysicButtonsPanel, bpy.types.Panel):
341     bl_label = "Dynamic Paint: Cache"
342     bl_options = {'DEFAULT_CLOSED'}
343
344     @classmethod
345     def poll(cls, context):
346         md = context.dynamic_paint
347         return md and (md.ui_type == "CANVAS") and (md.canvas_settings) and \
348         (md.canvas_settings.canvas_surfaces.active) and (md.canvas_settings.canvas_surfaces.active.uses_cache)
349
350     def draw(self, context):
351         layout = self.layout
352
353         surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
354         cache = surface.point_cache
355         
356         point_cache_ui(self, context, cache, (cache.is_baked is False), 'DYNAMIC_PAINT')
357
358
359 class PHYSICS_PT_dp_advanced_brush(PhysicButtonsPanel, bpy.types.Panel):
360     bl_label = "Dynamic Paint: Advanced"
361     bl_options = {'DEFAULT_CLOSED'}
362
363     @classmethod
364     def poll(cls, context):
365         md = context.dynamic_paint
366         return md and (md.ui_type == "BRUSH") and (md.brush_settings)
367
368     def draw(self, context):
369         layout = self.layout
370
371         brush = context.dynamic_paint.brush_settings
372         ob = context.object
373                 
374         split = layout.split()
375         col = split.column()
376         col.prop(brush, "paint_source")
377
378         if brush.paint_source == "PSYS":
379             col.prop_search(brush, "psys", ob, "particle_systems", text="")
380             if brush.psys:
381                 col.label(text="Particle effect:")
382                 sub = col.column()
383                 sub.active = not brush.use_part_radius
384                 sub.prop(brush, "solid_radius", text="Solid Radius")
385                 col.prop(brush, "use_part_radius", text="Use Particle's Radius")
386                 col.prop(brush, "smooth_radius", text="Smooth radius")
387         elif brush.paint_source in {'VOLUME', 'VOLDIST'}:
388             split = layout.row().split(percentage=0.4)
389             sub = split.column()
390             sub.prop(brush, "accept_nonclosed")
391             if brush.accept_nonclosed:
392                 sub = split.column()
393                 sub.prop(brush, "ray_dir")
394                 
395                 
396         if brush.paint_source in {'DISTANCE', 'VOLDIST', 'POINT'}:
397             col.prop(brush, "paint_distance", text="Paint Distance")
398             split = layout.row().split(percentage=0.4)
399             sub = split.column()
400             if (brush.paint_source != 'POINT'):
401                 sub.prop(brush, "prox_facealigned")
402             sub = split.column()
403             sub.prop(brush, "prox_falloff")
404             if brush.paint_source == "VOLDIST":
405                 col = layout.row().column()
406                 col.prop(brush, "prox_inverse")
407             if brush.prox_falloff == "RAMP":
408                 col = layout.row().column()
409                 col.separator()
410                 col.prop(brush, "prox_ramp_alpha", text="Only Use Alpha")
411                 col.template_color_ramp(brush, "paint_ramp", expand=True)
412
413 def register():
414     bpy.utils.register_module(__name__)
415
416
417 def unregister():
418     bpy.utils.register_module(__name__)
419
420 if __name__ == "__main__":
421     register()