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