2.5: Game Engine
[blender.git] / release / ui / buttons_game.py
1
2 import bpy
3  
4 class PhysicsButtonsPanel(bpy.types.Panel):
5         __space_type__ = "PROPERTIES"
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, "material_physics")
39                         col.itemR(game, "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 = split.column()
54                         sub = col.column()
55                         sub.active = (game.physics_type == 'RIGID_BODY')
56                         sub.itemR(game, "anisotropic_friction")
57                         subsub = sub.column()
58                         subsub.active = game.anisotropic_friction
59                         subsub.itemR(game, "friction_coefficients", text="", slider=True)
60                         
61                         split = layout.split()
62                         
63                         col = split.column()
64                         col.itemL(text="Velocity:")
65                         sub = col.column(align=True)
66                         sub.itemR(game, "minimum_velocity", text="Minimum")
67                         sub.itemR(game, "maximum_velocity", text="Maximum")
68                         
69                         col = split.column()
70                         col.itemL(text="Damping:")
71                         sub = col.column(align=True)
72                         sub.itemR(game, "damping", text="Translation", slider=True)
73                         sub.itemR(game, "rotation_damping", text="Rotation", 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, "cluster_rigid_to_softbody")
123                         col.itemR(soft, "cluster_soft_to_softbody")
124                         sub  = col.column()
125                         sub.active = (soft.cluster_rigid_to_softbody or soft.cluster_soft_to_softbody)
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                 rd = context.scene.render_data
147                 return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
148
149         def draw_header(self, context):
150                 layout = self.layout
151                 
152                 ob = context.active_object
153                 game = ob.game
154
155                 layout.itemR(game, "use_collision_bounds", text="")
156         
157         def draw(self, context):
158                 layout = self.layout
159                 
160                 ob = context.scene.objects[0]
161                 game = ob.game
162                 
163                 layout.active = game.use_collision_bounds
164                 layout.itemR(game, "collision_bounds", text="Bounds")
165                 
166                 row = layout.row()
167                 row.itemR(game, "collision_compound", text="Compound")
168                 row.itemR(game, "collision_margin", text="Margin", slider=True)
169
170 bpy.types.register(PHYSICS_PT_game_physics)
171 bpy.types.register(PHYSICS_PT_game_collision_bounds)
172
173 class SceneButtonsPanel(bpy.types.Panel):
174         __space_type__ = "PROPERTIES"
175         __region_type__ = "WINDOW"
176         __context__ = "scene"
177
178         def poll(self, context):
179                 rd = context.scene.render_data
180                 return (rd.engine == 'BLENDER_GAME')
181
182 class SCENE_PT_game(SceneButtonsPanel):
183         __label__ = "Game"
184
185         def draw(self, context):
186                 layout = self.layout
187                 
188                 rd = context.scene.render_data
189
190                 row = layout.row()
191                 row.itemO("view3d.game_start", text="Start")
192                 row.itemL()
193
194 class SCENE_PT_game_player(SceneButtonsPanel):
195         __label__ = "Standalone Player"
196
197         def draw(self, context):
198                 layout = self.layout
199                 
200                 gs = context.scene.game_data
201                 
202                 layout.itemR(gs, "fullscreen")
203
204                 split = layout.split()
205                 
206                 col = split.column()
207                 col.itemL(text="Resolution:")
208                 sub = col.column(align=True)
209                 sub.itemR(gs, "resolution_x", slider=False, text="X")
210                 sub.itemR(gs, "resolution_y", slider=False, text="Y")
211
212                 col = split.column()
213                 col.itemL(text="Quality:")
214                 sub = col.column(align=True)
215                 sub.itemR(gs, "depth", text="Bit Depth", slider=False)
216                 sub.itemR(gs, "frequency", text="FPS", slider=False)
217
218                 # framing:
219                 col = layout.column()
220                 col.itemL(text="Framing:")
221                 col.row().itemR(gs, "framing_type", expand=True)
222                 if gs.framing_type == 'LETTERBOX':
223                         col.itemR(gs, "framing_color", text="")
224
225 class SCENE_PT_game_stereo(SceneButtonsPanel):
226         __label__ = "Stereo"
227
228         def draw(self, context):
229                 layout = self.layout
230                 
231                 gs = context.scene.game_data
232                 stereo_mode = gs.stereo
233
234                 # stereo options:
235                 layout.itemR(gs, "stereo", expand=True)
236  
237                 # stereo:
238                 if stereo_mode == 'STEREO':
239                         layout.itemR(gs, "stereo_mode")
240                         layout.itemL(text="To do: Focal Length")
241                         layout.itemL(text="To do: Eye Separation")
242
243                 # dome:
244                 elif stereo_mode == 'DOME':
245                         layout.itemR(gs, "dome_mode", text="Dome Type")
246
247                         dome_type = gs.dome_mode
248
249                         split=layout.split()
250
251                         if dome_type == 'FISHEYE' or \
252                            dome_type == 'TRUNCATED_REAR' or \
253                            dome_type == 'TRUNCATED_FRONT':
254                                 
255                                 col=split.column()
256                                 col.itemR(gs, "dome_angle", slider=True)
257                                 col.itemR(gs, "dome_tilt")
258
259                                 col=split.column()
260                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
261                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
262
263                         elif dome_type == 'PANORAM_SPH':
264                                 col=split.column()
265                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
266                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
267
268                         else: # cube map
269                                 col=split.column()
270                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
271                 
272                         layout.itemR(gs, "dome_text")
273
274 class SCENE_PT_game_shading(SceneButtonsPanel):
275         __label__ = "Shading"
276
277         def draw(self, context):
278                 layout = self.layout
279                 
280                 gs = context.scene.game_data
281                 layout.itemR(gs, "material_mode", expand=True)
282  
283                 if gs.material_mode == 'GLSL':
284                         split = layout.split()
285
286                         col = split.column()
287                         col.itemR(gs, "glsl_lights", text="Lights")
288                         col.itemR(gs, "glsl_shaders", text="Shaders")
289                         col.itemR(gs, "glsl_shadows", text="Shadows")
290
291                         col = split.column()
292                         col.itemR(gs, "glsl_ramps", text="Ramps")
293                         col.itemR(gs, "glsl_nodes", text="Nodes")
294                         col.itemR(gs, "glsl_extra_textures", text="Extra Textures")
295
296 class SCENE_PT_game_performance(SceneButtonsPanel):
297         __label__ = "Performance"
298
299         def draw(self, context):
300                 layout = self.layout
301                 
302                 gs = context.scene.game_data
303
304                 split = layout.split()
305
306                 col = split.column()
307                 col.itemL(text="Show:")
308                 col.itemR(gs, "show_debug_properties", text="Debug Properties")
309                 col.itemR(gs, "show_framerate_profile", text="Framerate and Profile")
310                 col.itemR(gs, "show_physics_visualization", text="Physics Visualization")
311                 col.itemR(gs, "deprecation_warnings")
312  
313                 col = split.column()
314                 col.itemL(text="Render:")
315                 col.itemR(gs, "all_frames")
316                 col.itemR(gs, "display_lists")
317
318 bpy.types.register(SCENE_PT_game)
319 bpy.types.register(SCENE_PT_game_player)
320 bpy.types.register(SCENE_PT_game_stereo)
321 bpy.types.register(SCENE_PT_game_shading)
322 bpy.types.register(SCENE_PT_game_performance)
323
324 class WorldButtonsPanel(bpy.types.Panel):
325         __space_type__ = "PROPERTIES"
326         __region_type__ = "WINDOW"
327         __context__ = "world"
328
329         def poll(self, context):
330                 rd = context.scene.render_data
331                 return (rd.engine == 'BLENDER_GAME')
332
333 class WORLD_PT_game_context_world(WorldButtonsPanel):
334         __show_header__ = False
335
336         def poll(self, context):
337                 rd = context.scene.render_data
338                 return (context.scene) and (rd.use_game_engine)
339
340         def draw(self, context):
341                 layout = self.layout
342                 
343                 scene = context.scene
344                 world = context.world
345                 space = context.space_data
346
347                 split = layout.split(percentage=0.65)
348
349                 if scene:
350                         split.template_ID(scene, "world", new="world.new")
351                 elif world:
352                         split.template_ID(space, "pin_id")
353
354 class WORLD_PT_game_world(WorldButtonsPanel):
355         __label__ = "World"
356
357         def draw(self, context):
358                 layout = self.layout
359                 
360                 world = context.world
361
362                 row = layout.row()
363                 row.column().itemR(world, "horizon_color")
364                 row.column().itemR(world, "ambient_color")
365
366                 layout.itemR(world.mist, "enabled", text="Mist")
367
368                 row = layout.column_flow()
369                 row.active = world.mist.enabled
370                 row.itemR(world.mist, "start")
371                 row.itemR(world.mist, "depth")
372
373 class WORLD_PT_game_physics(WorldButtonsPanel):
374         __label__ = "Physics"
375  
376         def draw(self, context):
377                 layout = self.layout
378                 
379                 gs = context.scene.game_data
380                 
381                 layout.itemR(gs, "physics_engine")
382                 if gs.physics_engine != 'NONE':
383                         layout.itemR(gs, "physics_gravity", text="Gravity")
384  
385                         split = layout.split()
386                         
387                         col = split.column()
388                         col.itemL(text="Physics Steps:")
389                         sub = col.column(align=True)
390                         sub.itemR(gs, "physics_step_max", text="Max")
391                         sub.itemR(gs, "physics_step_sub", text="Substeps")
392                         col.itemR(gs, "fps", text="FPS")
393                         
394                         col = split.column()
395                         col.itemL(text="Logic Steps:")
396                         col.itemR(gs, "logic_step_max", text="Max")
397                         
398                         col = layout.column()
399                         col.itemR(gs, "use_occlusion_culling", text="Occlusion Culling")
400                         sub = col.column()
401                         sub.active = gs.use_occlusion_culling
402                         sub.itemR(gs, "occlusion_culling_resolution", text="Resolution")
403
404                 else:
405                         split = layout.split()
406                         
407                         col = split.column()
408                         col.itemL(text="Physics Steps:")
409                         col.itemR(gs, "fps", text="FPS")
410                         
411                         col = split.column()
412                         col.itemL(text="Logic Steps:")
413                         col.itemR(gs, "logic_step_max", text="Max")
414
415 bpy.types.register(WORLD_PT_game_context_world)
416 bpy.types.register(WORLD_PT_game_world)
417 bpy.types.register(WORLD_PT_game_physics)