Merge with trunk r37849
[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, "dynamicpaint_type", expand=True)
50
51             if md.dynamicpaint_type == 'CANVAS':
52                 canvas = md.canvas_settings
53                 surface = canvas.canvas_surfaces.active
54                 row = layout.row()
55                 row.template_list(canvas, "canvas_surfaces", canvas.canvas_surfaces, "active_index", rows=2)
56
57                 col = row.column(align=True)
58                 col.operator("dpaint.surface_slot_add", icon='ZOOMIN', text="")
59                 col.operator("dpaint.surface_slot_remove", icon='ZOOMOUT', text="")
60                 
61                 if surface:
62                     layout.prop(surface, "name")
63                     layout.prop(surface, "surface_format", expand=False)
64                     
65                     if surface.surface_format != "VERTEX":
66                         col = layout.column()
67                         col.label(text="Quality:")
68                         col.prop(surface, "image_resolution")
69                         col.prop(surface, "use_anti_aliasing")
70                 
71                     col = layout.column()
72                     col.label(text="Frames:")
73                     split = col.split()
74                 
75                     col = split.column(align=True)
76                     col.prop(surface, "start_frame", text="Start")
77                     col.prop(surface, "end_frame", text="End")
78                 
79                     col = split.column()
80                     col.prop(surface, "substeps")
81                 
82
83             elif md.dynamicpaint_type == 'BRUSH':
84                 brush = md.brush_settings
85                 
86                 layout.prop(brush, "brush_settings_context", expand=True, icon_only=True)
87                 
88                 if (brush.brush_settings_context == "GENERAL"):
89                     split = layout.split()
90
91                     col = split.column()
92                     col.prop(brush, "absolute_alpha")
93                     col.prop(brush, "paint_erase")
94                     col.prop(brush, "paint_wetness", text="Wetness")
95                 
96                     col = split.column()
97                     sub = col.column()
98                     sub.active = (brush.paint_source != "PSYS");
99                     sub.prop(brush, "use_material")
100                     if brush.use_material and brush.paint_source != "PSYS":
101                         col.prop(brush, "material", text="")
102                         col.prop(brush, "paint_alpha", text="Alpha Factor")
103                     else:
104                         col.prop(brush, "paint_color", text="")
105                         col.prop(brush, "paint_alpha", text="Alpha")
106                 
107                 if (brush.brush_settings_context != "GENERAL"):
108                     layout.label(text="-WIP-")
109
110
111 class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, bpy.types.Panel):
112     bl_label = "Dynamic Paint: Advanced"
113
114     @classmethod
115     def poll(cls, context):
116         md = context.dynamic_paint
117         return md and (md.dynamicpaint_type == 'CANVAS') and (context.dynamic_paint.canvas_settings.canvas_surfaces.active)
118
119     def draw(self, context):
120         layout = self.layout
121
122         canvas = context.dynamic_paint.canvas_settings
123         surface = canvas.canvas_surfaces.active
124         ob = context.object
125
126         layout.prop(surface, "surface_type", expand=False)
127         layout.separator()
128
129         if (surface.surface_type == "PAINT"):
130             split = layout.split(percentage=0.8)
131             split.prop(surface, "dry_speed", text="Dry Time")
132             split.prop(surface, "use_dry_log", text="Slow")
133             
134         if (surface.surface_type != "IWAVE"):
135             if (surface.surface_type == "DISPLACE"):
136                 layout.prop(surface, "use_dissolve", text="Dissolve:")
137             elif (surface.surface_type == "WEIGHT"):
138                 layout.prop(surface, "use_dissolve", text="Fade:")
139             else:
140                 layout.prop(surface, "use_dissolve", text="Dissolve:")
141             sub = layout.column()
142             sub.active = surface.use_dissolve
143             split = sub.split(percentage=0.8)
144             split.prop(surface, "dissolve_speed", text="Time")
145             split.prop(surface, "use_dissolve_log", text="Slow")
146             
147         layout.label(text="Brush Group:")
148         layout.prop(surface, "brush_group", text="")
149
150
151 class PHYSICS_PT_dp_canvas_output(PhysicButtonsPanel, bpy.types.Panel):
152     bl_label = "Dynamic Paint: Output"
153     bl_options = {'DEFAULT_CLOSED'}
154
155     @classmethod
156     def poll(cls, context):
157         md = context.dynamic_paint
158         if ((not md) or (md.dynamicpaint_type != 'CANVAS')):
159             return 0
160         surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
161         return (surface and (not (surface.surface_format=="VERTEX" and surface.surface_type=="DISPLACE") ))
162
163     def draw(self, context):
164         layout = self.layout
165
166         canvas = context.dynamic_paint.canvas_settings
167         surface = canvas.canvas_surfaces.active
168         ob = context.object
169         
170         # vertex format outputs
171         if (surface.surface_format == "VERTEX"):
172             if (surface.surface_type == "PAINT"):
173                 row = layout.row()
174                 row.prop_search(surface, "output_name", ob.data, "vertex_colors", text="Paintmap layer: ")
175                 #col = row.column(align=True)
176                 #col.operator("dpaint.output_add", icon='ZOOMIN', text="")
177                 
178                 row = layout.row()
179                 row.prop_search(surface, "output_name2", ob.data, "vertex_colors", text="Wetmap layer: ")
180                 #col = row.column(align=True)
181                 #col.operator("dpaint.output_add", icon='ZOOMIN', text="")
182             if (surface.surface_type == "WEIGHT"):
183                 layout.prop_search(surface, "output_name", ob, "vertex_groups", text="Vertex Group: ")
184
185         # image format outputs
186         if (surface.surface_format == "IMAGE"):
187             col = layout.column()
188             col.label(text="UV layer:")
189             col.prop_search(surface, "uv_layer", ob.data, "uv_textures", text="")
190             
191             col = layout.column()
192             col.prop(surface, "image_output_path", text="Output directory")
193             col.prop(surface, "image_fileformat", text="Image Format:")
194             if (surface.surface_type == "PAINT"):
195                 col.prop(surface, "do_output1", text="Output Paintmaps:")
196                 sub = col.column()
197                 sub.active = surface.do_output1
198                 sub.prop(surface, "output_name", text="Filename: ")
199                 sub.prop(surface, "premultiply", text="Premultiply alpha")
200                 
201                 col.prop(surface, "do_output2", text="Output Wetmaps:")
202                 sub = col.column()
203                 sub.active = surface.do_output2
204                 sub.prop(surface, "output_name2", text="Filename: ")
205             if (surface.surface_type == "DISPLACE"):
206                 col.prop(surface, "output_name", text="Filename: ")
207                 col.prop(surface, "disp_type", text="Displace Type")
208             
209             layout.separator()
210             layout.operator("dpaint.bake", text="Bake Image Sequence", icon='MOD_DYNAMICPAINT')
211             if len(canvas.ui_info) != 0:
212                 layout.label(text=canvas.ui_info)
213                 
214
215 class PHYSICS_PT_dp_effects(PhysicButtonsPanel, bpy.types.Panel):
216     bl_label = "Dynamic Paint: Effects"
217     bl_options = {'DEFAULT_CLOSED'}
218
219     @classmethod
220     def poll(cls, context):
221         md = context.dynamic_paint
222         if ((not md) or (md.dynamicpaint_type != 'CANVAS')):
223             return False;
224         surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
225         return surface and (surface.surface_format != "PTEX")
226
227     def draw(self, context):
228         layout = self.layout
229
230         canvas = context.dynamic_paint.canvas_settings
231         surface = canvas.canvas_surfaces.active
232
233         layout.prop(surface, "effect_ui", expand=True)
234
235         if surface.effect_ui == "SPREAD":
236             layout.prop(surface, "use_spread")
237             col = layout.column()
238             col.active = surface.use_spread
239             col.prop(surface, "spread_speed")
240
241         elif surface.effect_ui == "DRIP":
242             layout.prop(surface, "use_drip")
243             col = layout.column()
244             col.active = surface.use_drip
245             effector_weights_ui(self, context, surface.effector_weights)
246
247         elif surface.effect_ui == "SHRINK":
248             layout.prop(surface, "use_shrink")
249             col = layout.column()
250             col.active = surface.use_shrink
251             col.prop(surface, "shrink_speed")
252                         
253
254 class PHYSICS_PT_dp_cache(PhysicButtonsPanel, bpy.types.Panel):
255     bl_label = "Dynamic Paint: Cache"
256     bl_options = {'DEFAULT_CLOSED'}
257
258     @classmethod
259     def poll(cls, context):
260         md = context.dynamic_paint
261         return md and (md.dynamicpaint_type == 'CANVAS') and \
262         (md.canvas_settings.canvas_surfaces.active) and (md.canvas_settings.canvas_surfaces.active.uses_cache)
263
264     def draw(self, context):
265         layout = self.layout
266
267         surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
268         cache = surface.point_cache
269         
270         point_cache_ui(self, context, cache, (cache.is_baked is False), 'DYNAMIC_PAINT')
271
272
273 class PHYSICS_PT_dp_advanced_brush(PhysicButtonsPanel, bpy.types.Panel):
274     bl_label = "Dynamic Paint: Advanced"
275     bl_options = {'DEFAULT_CLOSED'}
276
277     @classmethod
278     def poll(cls, context):
279         md = context.dynamic_paint
280         return md and (md.dynamicpaint_type == 'BRUSH')
281
282     def draw(self, context):
283         layout = self.layout
284
285         brush = context.dynamic_paint.brush_settings
286         ob = context.object
287                 
288         split = layout.split()
289         col = split.column()
290         col.prop(brush, "paint_source")
291
292         if brush.paint_source == "PSYS":
293             col.prop_search(brush, "psys", ob, "particle_systems", text="")
294             if brush.psys:
295                 col.label(text="Particle effect:")
296                 sub = col.column()
297                 sub.active = not brush.use_part_radius
298                 sub.prop(brush, "solid_radius", text="Solid Radius")
299                 col.prop(brush, "use_part_radius", text="Use Particle's Radius")
300                 col.prop(brush, "smooth_radius", text="Smooth radius")
301
302         elif brush.paint_source == "DISTANCE" or brush.paint_source == "VOLDIST":
303             col.prop(brush, "paint_distance", text="Paint Distance")
304             split = layout.row().split()
305             sub = split.column()
306             sub.prop(brush, "prox_facealigned")
307             sub = split.column()
308             sub.prop(brush, "prox_falloff", text="Falloff")
309             if brush.paint_source == "VOLDIST":
310                 col = layout.row().column()
311                 col.prop(brush, "prox_inverse")
312             if brush.prox_falloff == "RAMP":
313                 col = layout.row().column()
314                 col.separator()
315                 col.prop(brush, "prox_ramp_alpha", text="Only Use Alpha")
316                 col.template_color_ramp(brush, "paint_ramp", expand=True)
317
318 def register():
319     bpy.utils.register_module(__name__)
320
321
322 def unregister():
323     bpy.utils.register_module(__name__)
324
325 if __name__ == "__main__":
326     register()