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