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