Merge with 2.5 -r 21619:21756.
[blender.git] / release / ui / buttons_physics_fluid.py
1
2 import bpy
3
4 class PhysicButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.object
11                 return (ob and ob.type == 'MESH')
12                 
13 class PHYSICS_PT_fluid(PhysicButtonsPanel):
14         __idname__ = "PHYSICS_PT_fluid"
15         __label__ = "Fluid"
16
17         def draw(self, context):
18                 layout = self.layout
19                 md = context.fluid
20                 ob = context.object
21
22                 split = layout.split()
23                 split.operator_context = "EXEC_DEFAULT"
24
25                 if md:
26                         # remove modifier + settings
27                         split.set_context_pointer("modifier", md)
28                         split.itemO("object.modifier_remove", text="Remove")
29
30                         row = split.row(align=True)
31                         row.itemR(md, "render", text="")
32                         row.itemR(md, "realtime", text="")
33                         
34                         fluid = md.settings
35                         
36                 else:
37                         # add modifier
38                         split.item_enumO("object.modifier_add", "type", "FLUID_SIMULATION", text="Add")
39                         split.itemL()
40                         
41                         fluid = None
42                 
43                 
44                 if fluid:
45                         
46
47                         col = layout.column(align=True)
48                         row = col.row()
49                         row.item_enumR(fluid, "type", "DOMAIN")
50                         row.item_enumR(fluid, "type", "FLUID")
51                         row.item_enumR(fluid, "type", "OBSTACLE")
52                         row = col.row()
53                         row.item_enumR(fluid, "type", "INFLOW")
54                         row.item_enumR(fluid, "type", "OUTFLOW")
55                         row.item_enumR(fluid, "type", "PARTICLE")
56                         row.item_enumR(fluid, "type", "CONTROL")
57
58                         if fluid.type == 'DOMAIN':
59                                 layout.itemO("fluid.bake", text="BAKE")
60                                 split = layout.split()
61                                 
62                                 col = split.column()
63                                 col.itemL(text="Resolution:")
64                                 colsub = col.column()
65                                 colsub.itemR(fluid, "resolution", text="Final")
66                                 colsub.itemL(text="Render Display:")
67                                 colsub.itemR(fluid, "render_display_mode", text="")
68                                 col.itemL(text="Time:")
69                                 colsub = col.column(align=True)
70                                 colsub.itemR(fluid, "start_time", text="Start")
71                                 colsub.itemR(fluid, "end_time", text="End")
72                                 
73                                 col = split.column()
74                                 colsub = col.column()
75                                 colsub.itemL(text="Required Memory: " + fluid.memory_estimate)
76                                 colsub.itemR(fluid, "preview_resolution", text="Preview")
77                                 colsub.itemL(text="Viewport Display:")
78                                 colsub.itemR(fluid, "viewport_display_mode", text="")
79                                 colsub = col.column()
80                                 colsub.itemL(text="")
81                                 colsub.itemR(fluid, "reverse_frames")
82                                 colsub.itemR(fluid, "generate_speed_vectors")
83                                 
84                                 layout.itemL(text="Path:")
85                                 layout.itemR(fluid, "path", text="")
86                                 
87                         if fluid.type == 'FLUID':
88                                 split = layout.split()
89                                 col = split.column()
90                                 col.itemL(text="Volume Initialization:")
91                                 col.itemR(fluid, "volume_initialization", text="")
92                                 col.itemR(fluid, "export_animated_mesh")
93                                 col = split.column()
94                                 col.itemL(text="Initial Velocity:")
95                                 col.itemR(fluid, "initial_velocity", text="")
96                                 
97                         if fluid.type == 'OBSTACLE':
98                                 split = layout.split()
99                                 col = split.column()
100                                 col.itemL(text="Volume Initialization:")
101                                 col.itemR(fluid, "volume_initialization", text="")
102                                 col.itemR(fluid, "export_animated_mesh")
103                                 col = split.column()
104                                 col.itemL(text="Slip Type:")
105                                 colsub=col.column(align=True)
106                                 colsub.itemR(fluid, "slip_type", text="")
107                                 if fluid.slip_type == 'PARTIALSLIP':
108                                         colsub.itemR(fluid, "partial_slip_amount", slider=True, text="Amount")
109                                         
110                                 col.itemR(fluid, "impact_factor")
111                                 
112                         if fluid.type == 'INFLOW':
113                                 split = layout.split()
114                                 col = split.column()
115                                 col.itemL(text="Volume Initialization:")
116                                 col.itemR(fluid, "volume_initialization", text="")
117                                 col.itemR(fluid, "export_animated_mesh")
118                                 col.itemR(fluid, "local_coordinates")
119                                 
120                                 col = split.column()
121                                 col.itemL(text="Inflow Velocity:")
122                                 col.itemR(fluid, "inflow_velocity", text="")
123                                 
124                         if fluid.type == 'OUTFLOW':
125                                 split = layout.split()
126                                 col = split.column()
127                                 col.itemL(text="Volume Initialization:")
128                                 col.itemR(fluid, "volume_initialization", text="")
129                                 col.itemR(fluid, "export_animated_mesh")
130                                 col = split.column()
131                                 
132                         if fluid.type == 'PARTICLE':
133                                 split = layout.split()
134                                 
135                                 col = split.column()
136                                 col.itemL(text="Influence:")
137                                 colsub = col.column(align=True)
138                                 colsub.itemR(fluid, "particle_influence", text="Size")
139                                 colsub.itemR(fluid, "alpha_influence", text="Alpha")
140                                 col.itemL(text="Path:")
141                                 
142                                 layout.itemR(fluid, "path", text="")
143                                 
144                                 col = split.column()
145                                 col.itemL(text="Type:")
146                                 col.itemR(fluid, "drops")
147                                 col.itemR(fluid, "floats")
148                                 col.itemR(fluid, "tracer")
149                                 
150                         if fluid.type == 'CONTROL':
151                                 split = layout.split()
152                                 
153                                 col = split.column()
154                                 col.itemL(text="")
155                                 col.itemR(fluid, "quality", slider=True)
156                                 col.itemR(fluid, "reverse_frames")
157                                 
158                                 col = split.column()
159                                 col.itemL(text="Time:")
160                                 col=col.column(align=True)
161                                 col.itemR(fluid, "start_time", text="Start")
162                                 col.itemR(fluid, "end_time", text="End")
163                                 
164                                 split = layout.split()
165                                 
166                                 col = split.column()
167                                 col.itemL(text="Attraction Force:")
168                                 col=col.column(align=True)
169                                 col.itemR(fluid, "attraction_strength", text="Strength")
170                                 col.itemR(fluid, "attraction_radius", text="Radius")
171                                 
172                                 col = split.column()
173                                 col.itemL(text="Velocity Force:")
174                                 col=col.column(align=True)
175                                 col.itemR(fluid, "velocity_strength", text="Strength")
176                                 col.itemR(fluid, "velocity_radius", text="Radius")
177
178 class PHYSICS_PT_domain_gravity(PhysicButtonsPanel):
179         __idname__ = "PHYSICS_PT_domain_gravity"
180         __label__ = "Domain World"
181         __default_closed__ = True
182         
183         def poll(self, context):
184                 md = context.fluid
185                 if md:
186                         settings = md.settings
187                         if settings:
188                                 return (settings.type == 'DOMAIN')
189                 
190                 return False
191
192         def draw(self, context):
193                 layout = self.layout
194                 fluid = context.fluid.settings
195                 
196                 split = layout.split()
197                 
198                 col = split.column()
199                 col.itemL(text="Gravity:")
200                 col.itemR(fluid, "gravity", text="")
201                 
202                 col.itemL(text="Real World Size:")
203                 col.itemR(fluid, "real_world_size", text="Metres")
204                 
205                 col = split.column()
206                 col.itemL(text="Viscosity Presets:")
207                 colsub=col.column(align=True)
208                 colsub.itemR(fluid, "viscosity_preset", text="")
209                 
210                 if fluid.viscosity_preset == 'MANUAL':
211                         colsub.itemR(fluid, "viscosity_base", text="Base")
212                         colsub.itemR(fluid, "viscosity_exponent", text="Exponent", slider=True)
213                 else:
214                         colsub.itemL(text="")
215                         colsub.itemL(text="")
216                         
217                 col.itemL(text="Optimization:")
218                 col=col.column(align=True)
219                 col.itemR(fluid, "grid_levels", slider=True)
220                 col.itemR(fluid, "compressibility", slider=True)
221         
222 class PHYSICS_PT_domain_boundary(PhysicButtonsPanel):
223         __idname__ = "PHYSICS_PT_domain_boundary"
224         __label__ = "Domain Boundary"
225         __default_closed__ = True
226         
227         def poll(self, context):
228                 md = context.fluid
229                 if md:
230                         settings = md.settings
231                         if settings:
232                                 return (settings.type == 'DOMAIN')
233                 
234                 return False
235
236         def draw(self, context):
237                 layout = self.layout
238                 fluid = context.fluid.settings
239                 
240                 split = layout.split()
241                 col = split.column()
242                 col.itemL(text="Slip Type:")
243                 col=col.column(align=True)
244                 col.itemR(fluid, "slip_type", text="")
245                 if fluid.slip_type == 'PARTIALSLIP':
246                         col.itemR(fluid, "partial_slip_amount", slider=True, text="Amount")
247                 col = split.column()
248                 col.itemL(text="Surface:")
249                 col=col.column(align=True)
250                 col.itemR(fluid, "surface_smoothing", text="Smoothing")
251                 col.itemR(fluid, "surface_subdivisions", text="Subdivisions")   
252                 
253 class PHYSICS_PT_domain_particles(PhysicButtonsPanel):
254         __idname__ = "PHYSICS_PT_domain_particles"
255         __label__ = "Domain Particles"
256         __default_closed__ = True
257         
258         def poll(self, context):
259                 md = context.fluid
260                 if md:
261                         settings = md.settings
262                         if settings:
263                                 return (settings.type == 'DOMAIN')
264                 
265                 return False
266
267         def draw(self, context):
268                 layout = self.layout
269                 fluid = context.fluid.settings
270                 
271                 col=layout.column(align=True)
272                 col.itemR(fluid, "tracer_particles")
273                 col.itemR(fluid, "generate_particles")
274
275 bpy.types.register(PHYSICS_PT_fluid)
276 bpy.types.register(PHYSICS_PT_domain_gravity)
277 bpy.types.register(PHYSICS_PT_domain_boundary)
278 bpy.types.register(PHYSICS_PT_domain_particles)