Forgot to commit these files in 23837.
[blender.git] / release / scripts / 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                         split = layout.split()
30                         
31                         col = split.column()
32                         col.itemR(game, "actor")
33                         col.itemR(game, "ghost")
34                         col.itemR(ob, "restrict_render", text="Invisible") # out of place but useful
35                         
36                         col = split.column()
37                         col.itemR(game, "material_physics")
38                         col.itemR(game, "rotate_from_normal")
39                         col.itemR(game, "no_sleeping")
40                         
41                         layout.itemS()
42                         
43                         split = layout.split()
44                         
45                         col = split.column()
46                         col.itemL(text="Attributes:")
47                         col.itemR(game, "mass")
48                         col.itemR(game, "radius")
49                         col.itemR(game, "form_factor")
50                         
51                         col = split.column()
52                         sub = col.column()
53                         sub.active = (game.physics_type == 'RIGID_BODY')
54                         sub.itemR(game, "anisotropic_friction")
55                         subsub = sub.column()
56                         subsub.active = game.anisotropic_friction
57                         subsub.itemR(game, "friction_coefficients", text="", slider=True)
58                         
59                         split = layout.split()
60                         
61                         col = split.column()
62                         col.itemL(text="Velocity:")
63                         sub = col.column(align=True)
64                         sub.itemR(game, "minimum_velocity", text="Minimum")
65                         sub.itemR(game, "maximum_velocity", text="Maximum")
66                         
67                         col = split.column()
68                         col.itemL(text="Damping:")
69                         sub = col.column(align=True)
70                         sub.itemR(game, "damping", text="Translation", slider=True)
71                         sub.itemR(game, "rotation_damping", text="Rotation", slider=True)
72                         
73                         layout.itemS()
74                         
75                         split = layout.split()
76                         
77                         col = split.column()
78                         col.itemL(text="Lock Translation:")
79                         col.itemR(game, "lock_x_axis", text="X")
80                         col.itemR(game, "lock_y_axis", text="Y")
81                         col.itemR(game, "lock_z_axis", text="Z")
82                         
83                         col = split.column()
84                         col.itemL(text="Lock Rotation:")
85                         col.itemR(game, "lock_x_rot_axis", text="X")
86                         col.itemR(game, "lock_y_rot_axis", text="Y")
87                         col.itemR(game, "lock_z_rot_axis", text="Z")
88                 
89                 elif game.physics_type == 'SOFT_BODY':
90                         col = layout.column()
91                         col.itemR(game, "actor")
92                         col.itemR(game, "ghost")
93                         col.itemR(ob, "restrict_render", text="Invisible")
94                         
95                         layout.itemS()
96                         
97                         split = layout.split()
98                         
99                         col = split.column()
100                         col.itemL(text="Attributes:")
101                         col.itemR(game, "mass")
102                         col.itemR(soft, "welding")
103                         col.itemR(soft, "position_iterations")
104                         col.itemR(soft, "linstiff", slider=True)
105                         col.itemR(soft, "dynamic_friction", slider=True)
106                         col.itemR(soft, "margin", slider=True)
107                         col.itemR(soft, "bending_const", text="Bending Constraints")
108
109                         col = split.column()
110                         col.itemR(soft, "shape_match")
111                         sub = col.column()
112                         sub.active = soft.shape_match
113                         sub.itemR(soft, "threshold", slider=True)
114                         
115                         col.itemS()
116                         
117                         col.itemL(text="Cluster Collision:")
118                         col.itemR(soft, "cluster_rigid_to_softbody")
119                         col.itemR(soft, "cluster_soft_to_softbody")
120                         sub  = col.column()
121                         sub.active = (soft.cluster_rigid_to_softbody or soft.cluster_soft_to_softbody)
122                         sub.itemR(soft, "cluster_iterations", text="Iterations")
123                 
124                 elif game.physics_type == 'STATIC':
125                         col = layout.column()
126                         col.itemR(game, "actor")
127                         col.itemR(game, "ghost")
128                         col.itemR(ob, "restrict_render", text="Invisible")
129                         
130                 elif game.physics_type in ('SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'):
131                         layout.itemR(ob, "restrict_render", text="Invisible")
132                         
133 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
134         __label__ = "Collision Bounds"
135
136         def poll(self, context):
137                 game = context.object.game
138                 rd = context.scene.render_data
139                 return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
140
141         def draw_header(self, context):
142                 game = context.active_object.game
143
144                 self.layout.itemR(game, "use_collision_bounds", text="")
145         
146         def draw(self, context):
147                 layout = self.layout
148                 
149                 game = context.active_object.game
150
151                 layout.active = game.use_collision_bounds
152                 layout.itemR(game, "collision_bounds", text="Bounds")
153                 
154                 row = layout.row()
155                 row.itemR(game, "collision_compound", text="Compound")
156                 row.itemR(game, "collision_margin", text="Margin", slider=True)
157
158 bpy.types.register(PHYSICS_PT_game_physics)
159 bpy.types.register(PHYSICS_PT_game_collision_bounds)
160
161 class RenderButtonsPanel(bpy.types.Panel):
162         __space_type__ = 'PROPERTIES'
163         __region_type__ = 'WINDOW'
164         __context__ = "render"
165
166         def poll(self, context):
167                 rd = context.scene.render_data
168                 return (rd.engine == 'BLENDER_GAME')
169
170 class RENDER_PT_game(RenderButtonsPanel):
171         __label__ = "Game"
172
173         def draw(self, context):
174                 layout = self.layout
175
176                 row = layout.row()
177                 row.itemO("view3d.game_start", text="Start")
178                 row.itemL()
179
180 class RENDER_PT_game_player(RenderButtonsPanel):
181         __label__ = "Standalone Player"
182
183         def draw(self, context):
184                 layout = self.layout
185                 
186                 gs = context.scene.game_data
187                 
188                 layout.itemR(gs, "fullscreen")
189
190                 split = layout.split()
191                 
192                 col = split.column()
193                 col.itemL(text="Resolution:")
194                 sub = col.column(align=True)
195                 sub.itemR(gs, "resolution_x", slider=False, text="X")
196                 sub.itemR(gs, "resolution_y", slider=False, text="Y")
197
198                 col = split.column()
199                 col.itemL(text="Quality:")
200                 sub = col.column(align=True)
201                 sub.itemR(gs, "depth", text="Bit Depth", slider=False)
202                 sub.itemR(gs, "frequency", text="FPS", slider=False)
203
204                 # framing:
205                 col = layout.column()
206                 col.itemL(text="Framing:")
207                 col.row().itemR(gs, "framing_type", expand=True)
208                 if gs.framing_type == 'LETTERBOX':
209                         col.itemR(gs, "framing_color", text="")
210
211 class RENDER_PT_game_stereo(RenderButtonsPanel):
212         __label__ = "Stereo"
213
214         def draw(self, context):
215                 layout = self.layout
216                 
217                 gs = context.scene.game_data
218                 stereo_mode = gs.stereo
219
220                 # stereo options:
221                 layout.itemR(gs, "stereo", expand=True)
222  
223                 # stereo:
224                 if stereo_mode == 'STEREO':
225                         layout.itemR(gs, "stereo_mode")
226                         layout.itemL(text="To do: Focal Length")
227                         layout.itemL(text="To do: Eye Separation")
228
229                 # dome:
230                 elif stereo_mode == 'DOME':
231                         layout.itemR(gs, "dome_mode", text="Dome Type")
232
233                         dome_type = gs.dome_mode
234
235                         split=layout.split()
236
237                         if dome_type == 'FISHEYE' or \
238                            dome_type == 'TRUNCATED_REAR' or \
239                            dome_type == 'TRUNCATED_FRONT':
240                                 
241                                 col=split.column()
242                                 col.itemR(gs, "dome_angle", slider=True)
243                                 col.itemR(gs, "dome_tilt")
244
245                                 col=split.column()
246                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
247                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
248
249                         elif dome_type == 'PANORAM_SPH':
250                                 col=split.column()
251                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
252                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
253
254                         else: # cube map
255                                 col=split.column()
256                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
257                 
258                         layout.itemR(gs, "dome_text")
259
260 class RENDER_PT_game_shading(RenderButtonsPanel):
261         __label__ = "Shading"
262
263         def draw(self, context):
264                 layout = self.layout
265                 
266                 gs = context.scene.game_data
267                 layout.itemR(gs, "material_mode", expand=True)
268  
269                 if gs.material_mode == 'GLSL':
270                         split = layout.split()
271
272                         col = split.column()
273                         col.itemR(gs, "glsl_lights", text="Lights")
274                         col.itemR(gs, "glsl_shaders", text="Shaders")
275                         col.itemR(gs, "glsl_shadows", text="Shadows")
276
277                         col = split.column()
278                         col.itemR(gs, "glsl_ramps", text="Ramps")
279                         col.itemR(gs, "glsl_nodes", text="Nodes")
280                         col.itemR(gs, "glsl_extra_textures", text="Extra Textures")
281
282 class RENDER_PT_game_performance(RenderButtonsPanel):
283         __label__ = "Performance"
284
285         def draw(self, context):
286                 layout = self.layout
287                 
288                 gs = context.scene.game_data
289
290                 split = layout.split()
291
292                 col = split.column()
293                 col.itemL(text="Show:")
294                 col.itemR(gs, "show_debug_properties", text="Debug Properties")
295                 col.itemR(gs, "show_framerate_profile", text="Framerate and Profile")
296                 col.itemR(gs, "show_physics_visualization", text="Physics Visualization")
297                 col.itemR(gs, "deprecation_warnings")
298  
299                 col = split.column()
300                 col.itemL(text="Render:")
301                 col.itemR(gs, "all_frames")
302                 col.itemR(gs, "display_lists")
303                 
304 class RENDER_PT_game_sound(RenderButtonsPanel):
305         __label__ = "Sound"
306
307         def draw(self, context):
308                 layout = self.layout
309
310                 scene = context.scene
311                 
312                 layout.itemR(scene, "distance_model")
313                 layout.itemR(scene, "speed_of_sound", text="Speed")
314                 layout.itemR(scene, "doppler_factor")
315
316 bpy.types.register(RENDER_PT_game)
317 bpy.types.register(RENDER_PT_game_player)
318 bpy.types.register(RENDER_PT_game_stereo)
319 bpy.types.register(RENDER_PT_game_shading)
320 bpy.types.register(RENDER_PT_game_performance)
321 bpy.types.register(RENDER_PT_game_sound)
322
323 class WorldButtonsPanel(bpy.types.Panel):
324         __space_type__ = 'PROPERTIES'
325         __region_type__ = 'WINDOW'
326         __context__ = "world"
327
328         def poll(self, context):
329                 rd = context.scene.render_data
330                 return (rd.engine == 'BLENDER_GAME')
331
332 class WORLD_PT_game_context_world(WorldButtonsPanel):
333         __show_header__ = False
334
335         def poll(self, context):
336                 rd = context.scene.render_data
337                 return (context.scene) and (rd.use_game_engine)
338
339         def draw(self, context):
340                 layout = self.layout
341                 
342                 scene = context.scene
343                 world = context.world
344                 space = context.space_data
345
346                 split = layout.split(percentage=0.65)
347
348                 if scene:
349                         split.template_ID(scene, "world", new="world.new")
350                 elif world:
351                         split.template_ID(space, "pin_id")
352
353 class WORLD_PT_game_world(WorldButtonsPanel):
354         __label__ = "World"
355
356         def draw(self, context):
357                 layout = self.layout
358                 
359                 world = context.world
360
361                 row = layout.row()
362                 row.column().itemR(world, "horizon_color")
363                 row.column().itemR(world, "ambient_color")
364
365                 layout.itemR(world.mist, "enabled", text="Mist")
366
367                 row = layout.column_flow()
368                 row.active = world.mist.enabled
369                 row.itemR(world.mist, "start")
370                 row.itemR(world.mist, "depth")
371
372 class WORLD_PT_game_physics(WorldButtonsPanel):
373         __label__ = "Physics"
374  
375         def draw(self, context):
376                 layout = self.layout
377                 
378                 gs = context.scene.game_data
379                 
380                 layout.itemR(gs, "physics_engine")
381                 if gs.physics_engine != 'NONE':
382                         layout.itemR(gs, "physics_gravity", text="Gravity")
383  
384                         split = layout.split()
385                         
386                         col = split.column()
387                         col.itemL(text="Physics Steps:")
388                         sub = col.column(align=True)
389                         sub.itemR(gs, "physics_step_max", text="Max")
390                         sub.itemR(gs, "physics_step_sub", text="Substeps")
391                         col.itemR(gs, "fps", text="FPS")
392                         
393                         col = split.column()
394                         col.itemL(text="Logic Steps:")
395                         col.itemR(gs, "logic_step_max", text="Max")
396                         
397                         col = layout.column()
398                         col.itemR(gs, "use_occlusion_culling", text="Occlusion Culling")
399                         sub = col.column()
400                         sub.active = gs.use_occlusion_culling
401                         sub.itemR(gs, "occlusion_culling_resolution", text="Resolution")
402
403                 else:
404                         split = layout.split()
405                         
406                         col = split.column()
407                         col.itemL(text="Physics Steps:")
408                         col.itemR(gs, "fps", text="FPS")
409                         
410                         col = split.column()
411                         col.itemL(text="Logic Steps:")
412                         col.itemR(gs, "logic_step_max", text="Max")
413
414 bpy.types.register(WORLD_PT_game_context_world)
415 bpy.types.register(WORLD_PT_game_world)
416 bpy.types.register(WORLD_PT_game_physics)