Added game soft body settings, and cleaned up layout there slightly.
[blender.git] / release / ui / buttons_game.py
1
2 import bpy
3  
4 class PhysicsButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.active_object
11                 rd = context.scene.render_data
12                 return ob and ob.game and (rd.engine == 'BLENDER_GAME')
13
14 class PHYSICS_PT_game_physics(PhysicsButtonsPanel):
15         __label__ = "Physics"
16
17         def draw(self, context):
18                 layout = self.layout
19                 
20                 ob = context.active_object
21                 game = ob.game
22                 soft = ob.game.soft_body
23
24                 layout.itemR(game, "physics_type")
25                 layout.itemS()
26                 
27                 #if game.physics_type == 'DYNAMIC':
28                 if game.physics_type in ('DYNAMIC', 'RIGID_BODY'):
29
30                         split = layout.split()
31                         
32                         col = split.column()
33                         col.itemR(game, "actor")
34                         col.itemR(game, "ghost")
35                         col.itemR(ob, "restrict_render", text="Invisible") # out of place but useful
36                         
37                         col = split.column()
38                         col.itemR(game, "do_fh", text="Use Material Physics")
39                         col.itemR(game, "rotation_fh", text="Rotate From Normal")
40                         col.itemR(game, "no_sleeping")
41                         
42                         layout.itemS()
43                         
44                         split = layout.split()
45                         
46                         col = split.column()
47                         col.itemL(text="Attributes:")
48                         sub = col.column()
49                         sub.itemR(game, "mass")
50                         sub.itemR(game, "radius")
51                         sub.itemR(game, "form_factor")
52                         
53                         col.itemS()
54                         
55                         col.itemL(text="Damping:")
56                         sub = col.column(align=True)
57                         sub.itemR(game, "damping", text="Translation", slider=True)
58                         sub.itemR(game, "rotation_damping", text="Rotation", slider=True)
59                         
60                         col = split.column()
61                         col.itemL(text="Velocity:")
62                         sub = col.column(align=True)
63                         sub.itemR(game, "minimum_velocity", text="Minimum")
64                         sub.itemR(game, "maximum_velocity", text="Maximum")
65                         
66                         col.itemS()
67                         
68                         sub = col.column()
69                         sub.active = (game.physics_type == 'RIGID_BODY')
70                         sub.itemR(game, "anisotropic_friction")
71                         subsub = sub.column()
72                         subsub.active = game.anisotropic_friction
73                         subsub.itemR(game, "friction_coefficients", text="", slider=True)
74                         
75                         layout.itemS()
76                         
77                         split = layout.split()
78                         
79                         col = split.column()
80                         col.itemL(text="Lock Translation:")
81                         col.itemR(game, "lock_x_axis", text="X")
82                         col.itemR(game, "lock_y_axis", text="Y")
83                         col.itemR(game, "lock_z_axis", text="Z")
84                         
85                         col = split.column()
86                         col.itemL(text="Lock Rotation:")
87                         col.itemR(game, "lock_x_rot_axis", text="X")
88                         col.itemR(game, "lock_y_rot_axis", text="Y")
89                         col.itemR(game, "lock_z_rot_axis", text="Z")
90                 
91                 elif game.physics_type == 'SOFT_BODY':
92
93                         col = layout.column()
94                         col.itemR(game, "actor")
95                         col.itemR(game, "ghost")
96                         col.itemR(ob, "restrict_render", text="Invisible")
97                         
98                         layout.itemS()
99                         
100                         split = layout.split()
101                         
102                         col = split.column()
103                         col.itemL(text="Attributes:")
104                         col.itemR(game, "mass")
105                         col.itemR(soft, "welding")
106                         col.itemR(soft, "position_iterations")
107                         col.itemR(soft, "linstiff", slider=True)
108                         col.itemR(soft, "dynamic_friction", slider=True)
109                         col.itemR(soft, "margin", slider=True)
110                         col.itemR(soft, "bending_const", text="Bending Constraints")
111                         
112                         
113                         col = split.column()
114                         col.itemR(soft, "shape_match")
115                         sub = col.column()
116                         sub.active = soft.shape_match
117                         sub.itemR(soft, "threshold", slider=True)
118                         
119                         col.itemS()
120                         
121                         col.itemL(text="Cluster Collision:")
122                         col.itemR(soft, "enable_rs_collision", text="Rigid to Soft Body")
123                         col.itemR(soft, "enable_ss_collision", text="Soft to Soft Body")
124                         sub  = col.column()
125                         sub.active = (soft.enable_rs_collision or soft.enable_ss_collision)
126                         sub.itemR(soft, "cluster_iterations", text="Iterations")
127                 
128                 elif game.physics_type == 'STATIC':
129                         
130                         col = layout.column()
131                         col.itemR(game, "actor")
132                         col.itemR(game, "ghost")
133                         col.itemR(ob, "restrict_render", text="Invisible")
134                         
135                 elif game.physics_type in ('SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'):
136                         
137                         col = layout.column()
138                         col.itemR(ob, "restrict_render", text="Invisible")
139                         
140 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
141         __label__ = "Collision Bounds"
142
143         def poll(self, context):
144                 ob = context.active_object
145                 game = ob.game
146                 return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'))
147
148         def draw_header(self, context):
149                 layout = self.layout
150                 
151                 ob = context.active_object
152                 game = ob.game
153
154                 layout.itemR(game, "use_collision_bounds", text="")
155         
156         def draw(self, context):
157                 layout = self.layout
158                 
159                 ob = context.scene.objects[0]
160                 game = ob.game
161                 
162                 layout.active = game.use_collision_bounds
163                 layout.itemR(game, "collision_bounds", text="Bounds")
164                 
165                 row = layout.row()
166                 row.itemR(game, "collision_compound", text="Compound")
167                 row.itemR(game, "collision_margin", text="Margin", slider=True)
168
169 bpy.types.register(PHYSICS_PT_game_physics)
170 bpy.types.register(PHYSICS_PT_game_collision_bounds)
171
172 class SceneButtonsPanel(bpy.types.Panel):
173         __space_type__ = "BUTTONS_WINDOW"
174         __region_type__ = "WINDOW"
175         __context__ = "scene"
176
177         def poll(self, context):
178                 rd = context.scene.render_data
179                 return (rd.engine == 'BLENDER_GAME')
180
181 class SCENE_PT_game(SceneButtonsPanel):
182         __label__ = "Game"
183
184         def draw(self, context):
185                 layout = self.layout
186                 
187                 rd = context.scene.render_data
188
189                 row = layout.row()
190                 row.itemO("view3d.game_start", text="Start")
191                 row.itemL()
192
193 class SCENE_PT_game_player(SceneButtonsPanel):
194         __label__ = "Player"
195
196         def draw(self, context):
197                 layout = self.layout
198                 
199                 gs = context.scene.game_data
200                 
201                 layout.itemR(gs, "fullscreen")
202
203                 split = layout.split()
204                 
205                 col = split.column()
206                 col.itemL(text="Resolution:")
207                 sub = col.column(align=True)
208                 sub.itemR(gs, "resolution_x", slider=False, text="X")
209                 sub.itemR(gs, "resolution_y", slider=False, text="Y")
210
211                 col = split.column()
212                 col.itemL(text="Quality:")
213                 sub = col.column(align=True)
214                 sub.itemR(gs, "depth", text="Bit Depth", slider=False)
215                 sub.itemR(gs, "frequency", text="FPS", slider=False)
216
217                 # framing:
218                 col = layout.column()
219                 col.itemL(text="Framing:")
220                 col.row().itemR(gs, "framing_type", expand=True)
221                 sub = col.column()
222                 sub.itemR(gs, "framing_color", text="")
223
224 class SCENE_PT_game_stereo(SceneButtonsPanel):
225         __label__ = "Stereo"
226
227         def draw(self, context):
228                 layout = self.layout
229                 
230                 gs = context.scene.game_data
231                 stereo_mode = gs.stereo
232
233                 # stereo options:
234                 layout.itemR(gs, "stereo", expand=True)
235  
236                 # stereo:
237                 if stereo_mode == 'STEREO':
238                         layout.itemR(gs, "stereo_mode")
239                         layout.itemL(text="To do: Focal Length")
240                         layout.itemL(text="To do: Eye Separation")
241
242                 # dome:
243                 elif stereo_mode == 'DOME':
244                         layout.itemR(gs, "dome_mode", text="Dome Type")
245
246                         dome_type = gs.dome_mode
247
248                         split=layout.split()
249
250                         if dome_type == 'FISHEYE' or \
251                            dome_type == 'TRUNCATED_REAR' or \
252                            dome_type == 'TRUNCATED_FRONT':
253                                 
254                                 col=split.column()
255                                 col.itemR(gs, "dome_angle", slider=True)
256                                 col.itemR(gs, "dome_tilt")
257
258                                 col=split.column()
259                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
260                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
261
262                         elif dome_type == 'PANORAM_SPH':
263                                 col=split.column()
264                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
265                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
266
267                         else: # cube map
268                                 col=split.column()
269                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
270                 
271                         layout.itemR(gs, "dome_text")
272
273 bpy.types.register(SCENE_PT_game)
274 bpy.types.register(SCENE_PT_game_player)
275 bpy.types.register(SCENE_PT_game_stereo)
276
277 class WorldButtonsPanel(bpy.types.Panel):
278         __space_type__ = "BUTTONS_WINDOW"
279         __region_type__ = "WINDOW"
280         __context__ = "world"
281
282         def poll(self, context):
283                 rd = context.scene.render_data
284                 return (rd.engine == 'BLENDER_GAME')
285
286 class WORLD_PT_game_context_world(WorldButtonsPanel):
287         __show_header__ = False
288
289         def poll(self, context):
290                 rd = context.scene.render_data
291                 return (context.scene) and (rd.use_game_engine)
292
293         def draw(self, context):
294                 layout = self.layout
295                 
296                 scene = context.scene
297                 world = context.world
298                 space = context.space_data
299
300                 split = layout.split(percentage=0.65)
301
302                 if scene:
303                         split.template_ID(scene, "world", new="world.new")
304                 elif world:
305                         split.template_ID(space, "pin_id")
306
307 class WORLD_PT_game_world(WorldButtonsPanel):
308         __label__ = "World"
309
310         def draw(self, context):
311                 layout = self.layout
312                 
313                 world = context.world
314
315                 row = layout.row()
316                 row.column().itemR(world, "horizon_color")
317                 row.column().itemR(world, "ambient_color")
318
319                 layout.itemR(world.mist, "enabled", text="Mist")
320
321                 row = layout.column_flow()
322                 row.active = world.mist.enabled
323                 row.itemR(world.mist, "start")
324                 row.itemR(world.mist, "depth")
325
326 class WORLD_PT_game_physics(WorldButtonsPanel):
327         __label__ = "Physics"
328  
329         def draw(self, context):
330                 layout = self.layout
331                 
332                 gs = context.scene.game_data
333                 
334                 layout.itemR(gs, "physics_engine")
335                 if gs.physics_engine != 'NONE':
336                         layout.itemR(gs, "physics_gravity", text="Gravity")
337  
338                         split = layout.split()
339                         
340                         col = split.column()
341                         col.itemL(text="Physics Steps:")
342                         sub = col.column(align=True)
343                         sub.itemR(gs, "physics_step_max", text="Max")
344                         sub.itemR(gs, "physics_step_sub", text="Substeps")
345                         col.itemR(gs, "fps", text="FPS")
346                         
347                         col = split.column()
348                         col.itemL(text="Logic Steps:")
349                         col.itemR(gs, "logic_step_max", text="Max")
350                         
351                         col = layout.column()
352                         col.itemR(gs, "use_occlusion_culling", text="Occlusion Culling")
353                         sub = col.column()
354                         sub.active = gs.use_occlusion_culling
355                         sub.itemR(gs, "occlusion_culling_resolution", text="Resolution")
356
357                 else:
358                         split = layout.split()
359                         
360                         col = split.column()
361                         col.itemL(text="Physics Steps:")
362                         col.itemR(gs, "fps", text="FPS")
363                         
364                         col = split.column()
365                         col.itemL(text="Logic Steps:")
366                         col.itemR(gs, "logic_step_max", text="Max")
367
368 bpy.types.register(WORLD_PT_game_context_world)
369 bpy.types.register(WORLD_PT_game_world)
370 bpy.types.register(WORLD_PT_game_physics)