35934ebfb320fd346d06d54fa1fdb6f80a970f90
[blender-staging.git] / release / scripts / ui / properties_physics_fluid.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
23 class PhysicButtonsPanel():
24     bl_space_type = 'PROPERTIES'
25     bl_region_type = 'WINDOW'
26     bl_context = "physics"
27
28     @classmethod
29     def poll(cls, context):
30         ob = context.object
31         rd = context.scene.render
32         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
33
34
35 class PHYSICS_PT_fluid(PhysicButtonsPanel, bpy.types.Panel):
36     bl_label = "Fluid"
37
38     def draw(self, context):
39         layout = self.layout
40
41         md = context.fluid
42
43         split = layout.split()
44
45         if md:
46             # remove modifier + settings
47             split.set_context_pointer("modifier", md)
48             split.operator("object.modifier_remove", text="Remove")
49
50             row = split.row(align=True)
51             row.prop(md, "show_render", text="")
52             row.prop(md, "show_viewport", text="")
53
54             fluid = md.settings
55
56         else:
57             # add modifier
58             split.operator("object.modifier_add", text="Add").type = 'FLUID_SIMULATION'
59             split.label()
60
61             fluid = None
62
63
64         if fluid:
65             row = layout.row()
66             row.prop(fluid, "type")
67             if fluid.type not in ('NONE', 'DOMAIN', 'PARTICLE'):
68                 row.prop(fluid, "use", text="")
69
70             layout = layout.column()
71             if fluid.type not in ('NONE', 'DOMAIN', 'PARTICLE'):
72                 layout.active = fluid.use
73
74             if fluid.type == 'DOMAIN':
75                 layout.operator("fluid.bake", text="Bake Fluid Simulation", icon='MOD_FLUIDSIM')
76                 split = layout.split()
77
78                 col = split.column()
79                 col.label(text="Resolution:")
80                 col.prop(fluid, "resolution", text="Final")
81                 col.label(text="Render Display:")
82                 col.prop(fluid, "render_display_mode", text="")
83
84                 col = split.column()
85                 col.label(text="Required Memory: " + fluid.memory_estimate)
86                 col.prop(fluid, "preview_resolution", text="Preview")
87                 col.label(text="Viewport Display:")
88                 col.prop(fluid, "viewport_display_mode", text="")
89
90                 split = layout.split()
91
92                 col = split.column()
93                 col.label(text="Time:")
94                 sub = col.column(align=True)
95                 sub.prop(fluid, "start_time", text="Start")
96                 sub.prop(fluid, "end_time", text="End")
97
98                 col = split.column()
99                 col.label()
100                 col.prop(fluid, "generate_speed_vectors")
101                 col.prop(fluid, "reverse_frames")
102
103                 layout.prop(fluid, "filepath", text="")
104
105             elif fluid.type == 'FLUID':
106                 split = layout.split()
107
108                 col = split.column()
109                 col.label(text="Volume Initialization:")
110                 col.prop(fluid, "volume_initialization", text="")
111                 col.prop(fluid, "export_animated_mesh")
112
113                 col = split.column()
114                 col.label(text="Initial Velocity:")
115                 col.prop(fluid, "initial_velocity", text="")
116
117             elif fluid.type == 'OBSTACLE':
118                 split = layout.split()
119
120                 col = split.column()
121                 col.label(text="Volume Initialization:")
122                 col.prop(fluid, "volume_initialization", text="")
123                 col.prop(fluid, "export_animated_mesh")
124
125                 col = split.column()
126                 col.label(text="Slip Type:")
127                 col.prop(fluid, "slip_type", text="")
128                 if fluid.slip_type == 'PARTIALSLIP':
129                     col.prop(fluid, "partial_slip_factor", slider=True, text="Amount")
130
131                 col.label(text="Impact:")
132                 col.prop(fluid, "impact_factor", text="Factor")
133
134             elif fluid.type == 'INFLOW':
135                 split = layout.split()
136
137                 col = split.column()
138                 col.label(text="Volume Initialization:")
139                 col.prop(fluid, "volume_initialization", text="")
140                 col.prop(fluid, "export_animated_mesh")
141                 col.prop(fluid, "local_coordinates")
142
143                 col = split.column()
144                 col.label(text="Inflow Velocity:")
145                 col.prop(fluid, "inflow_velocity", text="")
146
147             elif fluid.type == 'OUTFLOW':
148                 split = layout.split()
149
150                 col = split.column()
151                 col.label(text="Volume Initialization:")
152                 col.prop(fluid, "volume_initialization", text="")
153                 col.prop(fluid, "export_animated_mesh")
154
155                 split.column()
156
157             elif fluid.type == 'PARTICLE':
158                 split = layout.split()
159
160                 col = split.column()
161                 col.label(text="Influence:")
162                 col.prop(fluid, "particle_influence", text="Size")
163                 col.prop(fluid, "alpha_influence", text="Alpha")
164
165                 col = split.column()
166                 col.label(text="Type:")
167                 col.prop(fluid, "drops")
168                 col.prop(fluid, "floats")
169                 col.prop(fluid, "show_tracer")
170
171                 layout.prop(fluid, "filepath", text="")
172
173             elif fluid.type == 'CONTROL':
174                 split = layout.split()
175
176                 col = split.column()
177                 col.label(text="")
178                 col.prop(fluid, "quality", slider=True)
179                 col.prop(fluid, "reverse_frames")
180
181                 col = split.column()
182                 col.label(text="Time:")
183                 sub = col.column(align=True)
184                 sub.prop(fluid, "start_time", text="Start")
185                 sub.prop(fluid, "end_time", text="End")
186
187                 split = layout.split()
188
189                 col = split.column()
190                 col.label(text="Attraction Force:")
191                 sub = col.column(align=True)
192                 sub.prop(fluid, "attraction_strength", text="Strength")
193                 sub.prop(fluid, "attraction_radius", text="Radius")
194
195                 col = split.column()
196                 col.label(text="Velocity Force:")
197                 sub = col.column(align=True)
198                 sub.prop(fluid, "velocity_strength", text="Strength")
199                 sub.prop(fluid, "velocity_radius", text="Radius")
200
201
202 class PHYSICS_PT_domain_gravity(PhysicButtonsPanel, bpy.types.Panel):
203     bl_label = "Domain World"
204     bl_default_closed = True
205
206     @classmethod
207     def poll(cls, context):
208         md = context.fluid
209         return md and md.settings and (md.settings.type == 'DOMAIN')
210
211     def draw(self, context):
212         layout = self.layout
213
214         fluid = context.fluid.settings
215         scene = context.scene
216
217         split = layout.split()
218
219         col = split.column()
220         if scene.use_gravity:
221             col.label(text="Using Scene Gravity", icon="SCENE_DATA")
222             sub = col.column()
223             sub.enabled = False
224             sub.prop(fluid, "gravity", text="")
225         else:
226             col.label(text="Gravity:")
227             col.prop(fluid, "gravity", text="")
228
229         if scene.unit_settings.system != 'NONE':
230             col.label(text="Using Scene Size Units", icon="SCENE_DATA")
231             sub = col.column()
232             sub.enabled = False
233             sub.prop(fluid, "real_world_size", text="Metres")
234         else:
235             col.label(text="Real World Size:")
236             col.prop(fluid, "real_world_size", text="Metres")
237
238         col = split.column()
239         col.label(text="Viscosity Presets:")
240         sub = col.column(align=True)
241         sub.prop(fluid, "viscosity_preset", text="")
242
243         if fluid.viscosity_preset == 'MANUAL':
244             sub.prop(fluid, "viscosity_base", text="Base")
245             sub.prop(fluid, "viscosity_exponent", text="Exponent", slider=True)
246
247         col.label(text="Optimization:")
248         col.prop(fluid, "grid_levels", slider=True)
249         col.prop(fluid, "compressibility", slider=True)
250
251
252 class PHYSICS_PT_domain_boundary(PhysicButtonsPanel, bpy.types.Panel):
253     bl_label = "Domain Boundary"
254     bl_default_closed = True
255
256     @classmethod
257     def poll(cls, context):
258         md = context.fluid
259         return md and md.settings and (md.settings.type == 'DOMAIN')
260
261     def draw(self, context):
262         layout = self.layout
263
264         fluid = context.fluid.settings
265
266         split = layout.split()
267
268         col = split.column()
269         col.label(text="Slip Type:")
270         col.prop(fluid, "slip_type", text="")
271         if fluid.slip_type == 'PARTIALSLIP':
272             col.prop(fluid, "partial_slip_factor", slider=True, text="Amount")
273
274         col = split.column()
275         col.label(text="Surface:")
276         col.prop(fluid, "surface_smoothing", text="Smoothing")
277         col.prop(fluid, "surface_subdivisions", text="Subdivisions")
278
279
280 class PHYSICS_PT_domain_particles(PhysicButtonsPanel, bpy.types.Panel):
281     bl_label = "Domain Particles"
282     bl_default_closed = True
283
284     @classmethod
285     def poll(cls, context):
286         md = context.fluid
287         return md and md.settings and (md.settings.type == 'DOMAIN')
288
289     def draw(self, context):
290         layout = self.layout
291
292         fluid = context.fluid.settings
293
294         col = layout.column(align=True)
295         col.prop(fluid, "tracer_particles")
296         col.prop(fluid, "generate_particles")
297
298
299 def register():
300     pass
301
302
303 def unregister():
304     pass
305
306 if __name__ == "__main__":
307     register()