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