BGE: removing remaining reference to sce->world->gravity/physics/... (it's all in...
[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
23                 layout.itemR(game, "physics_type")
24                 layout.itemS()
25                 
26                 split = layout.split()
27                 
28                 col = split.column()
29                 col.itemR(game, "actor")
30                 col.itemR(game, "ghost")
31                 col.itemR(ob, "restrict_render", text="Invisible") # out of place but useful
32                 
33                 col = split.column()
34                 col.itemR(game, "do_fh", text="Use Material Physics")
35                 col.itemR(game, "rotation_fh", text="Rotate From Normal")
36                 col.itemR(game, "no_sleeping")
37                 
38                 layout.itemS()
39                 
40                 split = layout.split()
41                 
42                 col = split.column()
43                 col.itemL(text="Attributes:")
44                 sub = col.column(align=True)
45                 sub.itemR(game, "mass")
46                 sub.itemR(game, "radius")
47                 sub.itemR(game, "form_factor")
48                 
49                 col.itemS()
50                 
51                 col.itemL(text="Damping:")
52                 sub = col.column(align=True)
53                 sub.itemR(game, "damping", text="Translation", slider=True)
54                 sub.itemR(game, "rotation_damping", text="Rotation", slider=True)
55                 
56                 col = split.column()
57                 col.itemL(text="Velocity:")
58                 sub = col.column(align=True)
59                 sub.itemR(game, "minimum_velocity", text="Minimum")
60                 sub.itemR(game, "maximum_velocity", text="Maximum")
61                 
62                 col.itemS()
63                 
64                 col.itemR(game, "anisotropic_friction")
65                 sub = col.column()
66                 sub.active = game.anisotropic_friction
67                 sub.itemR(game, "friction_coefficients", text="", slider=True)
68                 
69                 layout.itemS()
70                 
71                 split = layout.split()
72                 
73                 col = split.column()
74                 col.itemL(text="Lock Translation:")
75                 col.itemR(game, "lock_x_axis", text="X")
76                 col.itemR(game, "lock_y_axis", text="Y")
77                 col.itemR(game, "lock_z_axis", text="Z")
78                 
79                 col = split.column()
80                 col.itemL(text="Lock Rotation:")
81                 col.itemR(game, "lock_x_rot_axis", text="X")
82                 col.itemR(game, "lock_y_rot_axis", text="Y")
83                 col.itemR(game, "lock_z_rot_axis", text="Z")
84
85 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
86         __label__ = "Collision Bounds"
87
88         def draw_header(self, context):
89                 layout = self.layout
90                 
91                 ob = context.active_object
92                 game = ob.game
93
94                 layout.itemR(game, "use_collision_bounds", text="")
95         
96         def draw(self, context):
97                 layout = self.layout
98                 
99                 ob = context.scene.objects[0]
100                 game = ob.game
101                 
102                 layout.active = game.use_collision_bounds
103                 layout.itemR(game, "collision_bounds", text="Bounds")
104                 
105                 row = layout.row()
106                 row.itemR(game, "collision_compound", text="Compound")
107                 row.itemR(game, "collision_margin", text="Margin", slider=True)
108
109 bpy.types.register(PHYSICS_PT_game_physics)
110 bpy.types.register(PHYSICS_PT_game_collision_bounds)
111
112 class SceneButtonsPanel(bpy.types.Panel):
113         __space_type__ = "BUTTONS_WINDOW"
114         __region_type__ = "WINDOW"
115         __context__ = "scene"
116
117         def poll(self, context):
118                 rd = context.scene.render_data
119                 return (rd.engine == 'BLENDER_GAME')
120
121 class SCENE_PT_game(SceneButtonsPanel):
122         __label__ = "Game"
123
124         def draw(self, context):
125                 layout = self.layout
126                 
127                 rd = context.scene.render_data
128
129                 row = layout.row()
130                 row.itemO("view3d.game_start", text="Start")
131                 row.itemL()
132
133 class SCENE_PT_game_player(SceneButtonsPanel):
134         __label__ = "Player"
135
136         def draw(self, context):
137                 layout = self.layout
138                 
139                 gs = context.scene.game_data
140                 
141                 layout.itemR(gs, "fullscreen")
142
143                 split = layout.split()
144                 
145                 col = split.column()
146                 col.itemL(text="Resolution:")
147                 sub = col.column(align=True)
148                 sub.itemR(gs, "resolution_x", slider=False, text="X")
149                 sub.itemR(gs, "resolution_y", slider=False, text="Y")
150
151                 col = split.column()
152                 col.itemL(text="Quality:")
153                 sub = col.column(align=True)
154                 sub.itemR(gs, "depth", text="Bit Depth", slider=False)
155                 sub.itemR(gs, "frequency", text="FPS", slider=False)
156
157                 # framing:
158                 col = layout.column()
159                 col.itemL(text="Framing:")
160                 col.row().itemR(gs, "framing_type", expand=True)
161                 sub = col.column()
162                 sub.itemR(gs, "framing_color", text="")
163
164 class SCENE_PT_game_stereo(SceneButtonsPanel):
165         __label__ = "Stereo"
166
167         def draw(self, context):
168                 layout = self.layout
169                 
170                 gs = context.scene.game_data
171                 stereo_mode = gs.stereo
172
173                 # stereo options:
174                 layout.itemR(gs, "stereo", expand=True)
175  
176                 # stereo:
177                 if stereo_mode == 'STEREO':
178                         layout.itemR(gs, "stereo_mode")
179                         layout.itemL(text="To do: Focal Length")
180                         layout.itemL(text="To do: Eye Separation")
181
182                 # dome:
183                 elif stereo_mode == 'DOME':
184                         layout.itemR(gs, "dome_mode", text="Dome Type")
185
186                         dome_type = gs.dome_mode
187
188                         split=layout.split()
189
190                         if dome_type == 'FISHEYE' or \
191                            dome_type == 'TRUNCATED_REAR' or \
192                            dome_type == 'TRUNCATED_FRONT':
193                                 
194                                 col=split.column()
195                                 col.itemR(gs, "dome_angle", slider=True)
196                                 col.itemR(gs, "dome_tilt")
197
198                                 col=split.column()
199                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
200                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
201
202                         elif dome_type == 'PANORAM_SPH':
203                                 col=split.column()
204                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
205                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
206
207                         else: # cube map
208                                 col=split.column()
209                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
210                 
211                         layout.itemR(gs, "dome_text")
212
213 bpy.types.register(SCENE_PT_game)
214 bpy.types.register(SCENE_PT_game_player)
215 bpy.types.register(SCENE_PT_game_stereo)
216
217 class WorldButtonsPanel(bpy.types.Panel):
218         __space_type__ = "BUTTONS_WINDOW"
219         __region_type__ = "WINDOW"
220         __context__ = "world"
221
222         def poll(self, context):
223                 rd = context.scene.render_data
224                 return (rd.engine == 'BLENDER_GAME')
225
226 class WORLD_PT_game_context_world(WorldButtonsPanel):
227         __show_header__ = False
228
229         def poll(self, context):
230                 rd = context.scene.render_data
231                 return (context.scene) and (rd.use_game_engine)
232
233         def draw(self, context):
234                 layout = self.layout
235                 
236                 scene = context.scene
237                 world = context.world
238                 space = context.space_data
239
240                 split = layout.split(percentage=0.65)
241
242                 if scene:
243                         split.template_ID(scene, "world", new="world.new")
244                 elif world:
245                         split.template_ID(space, "pin_id")
246
247 class WORLD_PT_game_world(WorldButtonsPanel):
248         __label__ = "World"
249
250         def draw(self, context):
251                 layout = self.layout
252                 
253                 world = context.world
254
255                 row = layout.row()
256                 row.column().itemR(world, "horizon_color")
257                 row.column().itemR(world, "ambient_color")
258
259                 layout.itemR(world.mist, "enabled", text="Mist")
260
261                 row = layout.column_flow()
262                 row.active = world.mist.enabled
263                 row.itemR(world.mist, "start")
264                 row.itemR(world.mist, "depth")
265
266 class WORLD_PT_game_physics(WorldButtonsPanel):
267         __label__ = "Physics"
268  
269         def draw(self, context):
270                 layout = self.layout
271                 
272                 gs = context.scene.game_data
273                 
274                 layout.itemR(gs, "physics_engine")
275                 if gs.physics_engine != 'NONE':
276                         layout.itemR(gs, "physics_gravity", text="Gravity")
277  
278                         split = layout.split()
279                         
280                         col = split.column()
281                         col.itemL(text="Physics Steps:")
282                         sub = col.column(align=True)
283                         sub.itemR(gs, "physics_step_max", text="Max")
284                         sub.itemR(gs, "physics_step_sub", text="Substeps")
285                         col.itemR(gs, "fps", text="FPS")
286                         
287                         col = split.column()
288                         col.itemL(text="Logic Steps:")
289                         col.itemR(gs, "logic_step_max", text="Max")
290                         
291                         col = layout.column()
292                         col.itemR(gs, "use_occlusion_culling", text="Occlusion Culling")
293                         sub = col.column()
294                         sub.active = gs.use_occlusion_culling
295                         sub.itemR(gs, "occlusion_culling_resolution", text="Resolution")
296
297                 else:
298                         split = layout.split()
299                         
300                         col = split.column()
301                         col.itemL(text="Physics Steps:")
302                         col.itemR(gs, "fps", text="FPS")
303                         
304                         col = split.column()
305                         col.itemL(text="Logic Steps:")
306                         col.itemR(gs, "logic_step_max", text="Max")
307
308 bpy.types.register(WORLD_PT_game_context_world)
309 bpy.types.register(WORLD_PT_game_world)
310 bpy.types.register(WORLD_PT_game_physics)