synched with trunk at revision 36569
[blender.git] / release / scripts / startup / bl_ui / properties_game.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 class PhysicsButtonsPanel():
24     bl_space_type = 'PROPERTIES'
25     bl_region_type = 'WINDOW'
26     bl_context = "physics"
27
28
29 class PHYSICS_PT_game_physics(PhysicsButtonsPanel, bpy.types.Panel):
30     bl_label = "Physics"
31     COMPAT_ENGINES = {'BLENDER_GAME'}
32
33     @classmethod
34     def poll(cls, context):
35         ob = context.active_object
36         rd = context.scene.render
37         return ob and ob.game and (rd.engine in cls.COMPAT_ENGINES)
38
39     def draw(self, context):
40         layout = self.layout
41
42         ob = context.active_object
43         game = ob.game
44         soft = ob.game.soft_body
45
46         layout.prop(game, "physics_type")
47         layout.separator()
48
49         #if game.physics_type == 'DYNAMIC':
50         if game.physics_type in {'DYNAMIC', 'RIGID_BODY'}:
51             split = layout.split()
52
53             col = split.column()
54             col.prop(game, "use_actor")
55             col.prop(game, "use_ghost")
56             col.prop(ob, "hide_render", text="Invisible")  # out of place but useful
57
58             col = split.column()
59             col.prop(game, "use_material_physics_fh")
60             col.prop(game, "use_rotate_from_normal")
61             col.prop(game, "use_sleep")
62
63             layout.separator()
64
65             split = layout.split()
66
67             col = split.column()
68             col.label(text="Attributes:")
69             col.prop(game, "mass")
70             col.prop(game, "radius")
71             col.prop(game, "form_factor")
72
73             col = split.column()
74             sub = col.column()
75             sub.prop(game, "use_anisotropic_friction")
76             subsub = sub.column()
77             subsub.active = game.use_anisotropic_friction
78             subsub.prop(game, "friction_coefficients", text="", slider=True)
79
80             split = layout.split()
81
82             col = split.column()
83             col.label(text="Velocity:")
84             sub = col.column(align=True)
85             sub.prop(game, "velocity_min", text="Minimum")
86             sub.prop(game, "velocity_max", text="Maximum")
87
88             col = split.column()
89             col.label(text="Damping:")
90             sub = col.column(align=True)
91             sub.prop(game, "damping", text="Translation", slider=True)
92             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
93
94             layout.separator()
95
96             split = layout.split()
97
98             col = split.column()
99             col.label(text="Lock Translation:")
100             col.prop(game, "lock_location_x", text="X")
101             col.prop(game, "lock_location_y", text="Y")
102             col.prop(game, "lock_location_z", text="Z")
103
104             col = split.column()
105             col.label(text="Lock Rotation:")
106             col.prop(game, "lock_rotation_x", text="X")
107             col.prop(game, "lock_rotation_y", text="Y")
108             col.prop(game, "lock_rotation_z", text="Z")
109
110         elif game.physics_type == 'SOFT_BODY':
111             col = layout.column()
112             col.prop(game, "use_actor")
113             col.prop(game, "use_ghost")
114             col.prop(ob, "hide_render", text="Invisible")
115
116             layout.separator()
117
118             split = layout.split()
119
120             col = split.column()
121             col.label(text="Attributes:")
122             col.prop(game, "mass")
123             col.prop(soft, "weld_threshold")
124             col.prop(soft, "location_iterations")
125             col.prop(soft, "linear_stiffness", slider=True)
126             col.prop(soft, "dynamic_friction", slider=True)
127             col.prop(soft, "collision_margin", slider=True)
128             col.prop(soft, "use_bending_constraints", text="Bending Constraints")
129
130             col = split.column()
131             col.prop(soft, "use_shape_match")
132             sub = col.column()
133             sub.active = soft.use_shape_match
134             sub.prop(soft, "shape_threshold", slider=True)
135
136             col.separator()
137
138             col.label(text="Cluster Collision:")
139             col.prop(soft, "use_cluster_rigid_to_softbody")
140             col.prop(soft, "use_cluster_soft_to_softbody")
141             sub = col.column()
142             sub.active = (soft.use_cluster_rigid_to_softbody or soft.use_cluster_soft_to_softbody)
143             sub.prop(soft, "cluster_iterations", text="Iterations")
144
145         elif game.physics_type == 'STATIC':
146             col = layout.column()
147             col.prop(game, "use_actor")
148             col.prop(game, "use_ghost")
149             col.prop(ob, "hide_render", text="Invisible")
150
151             layout.separator()
152
153             split = layout.split()
154
155             col = split.column()
156             col.label(text="Attributes:")
157             col.prop(game, "radius")
158
159             col = split.column()
160             sub = col.column()
161             sub.prop(game, "use_anisotropic_friction")
162             subsub = sub.column()
163             subsub.active = game.use_anisotropic_friction
164             subsub.prop(game, "friction_coefficients", text="", slider=True)
165
166         elif game.physics_type in {'SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'}:
167             layout.prop(ob, "hide_render", text="Invisible")
168
169
170 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, bpy.types.Panel):
171     bl_label = "Collision Bounds"
172     COMPAT_ENGINES = {'BLENDER_GAME'}
173
174     @classmethod
175     def poll(cls, context):
176         game = context.object.game
177         rd = context.scene.render
178         return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES)
179
180     def draw_header(self, context):
181         game = context.active_object.game
182
183         self.layout.prop(game, "use_collision_bounds", text="")
184
185     def draw(self, context):
186         layout = self.layout
187
188         game = context.active_object.game
189
190         layout.active = game.use_collision_bounds
191         layout.prop(game, "collision_bounds_type", text="Bounds")
192
193         row = layout.row()
194         row.prop(game, "collision_margin", text="Margin", slider=True)
195         row.prop(game, "use_collision_compound", text="Compound")
196
197 class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, bpy.types.Panel):
198     bl_label = "Create obstacle"
199     COMPAT_ENGINES = {'BLENDER_GAME'}
200  
201     @classmethod
202     def poll(self, context):
203         game = context.object.game
204         rd = context.scene.render
205         return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'))  and (rd.engine in cls.COMPAT_ENGINES)
206
207     def draw_header(self, context):
208         game = context.active_object.game
209
210         self.layout.prop(game, "create_obstacle", text="")
211
212     def draw(self, context):
213         layout = self.layout
214
215         game = context.active_object.game
216
217         layout.active = game.create_obstacle
218
219         split = layout.split()
220         col = split.column()
221         col.prop(game, "obstacle_radius", text="Radius")                
222
223 class RenderButtonsPanel():
224     bl_space_type = 'PROPERTIES'
225     bl_region_type = 'WINDOW'
226     bl_context = "render"
227
228     @classmethod
229     def poll(cls, context):
230         rd = context.scene.render
231         return (rd.engine in cls.COMPAT_ENGINES)
232
233
234 class RENDER_PT_game(RenderButtonsPanel, bpy.types.Panel):
235     bl_label = "Game"
236     COMPAT_ENGINES = {'BLENDER_GAME'}
237
238     def draw(self, context):
239         layout = self.layout
240
241         row = layout.row()
242         row.operator("view3d.game_start", text="Start")
243         row.label()
244
245
246 class RENDER_PT_game_player(RenderButtonsPanel, bpy.types.Panel):
247     bl_label = "Standalone Player"
248     COMPAT_ENGINES = {'BLENDER_GAME'}
249
250     def draw(self, context):
251         layout = self.layout
252
253         gs = context.scene.game_settings
254
255         layout.prop(gs, "show_fullscreen")
256
257         split = layout.split()
258
259         col = split.column()
260         col.label(text="Resolution:")
261         sub = col.column(align=True)
262         sub.prop(gs, "resolution_x", slider=False, text="X")
263         sub.prop(gs, "resolution_y", slider=False, text="Y")
264
265         col = split.column()
266         col.label(text="Quality:")
267         sub = col.column(align=True)
268         sub.prop(gs, "depth", text="Bit Depth", slider=False)
269         sub.prop(gs, "frequency", text="FPS", slider=False)
270
271         # framing:
272         col = layout.column()
273         col.label(text="Framing:")
274         col.row().prop(gs, "frame_type", expand=True)
275         if gs.frame_type == 'LETTERBOX':
276             col.prop(gs, "frame_color", text="")
277
278
279 class RENDER_PT_game_stereo(RenderButtonsPanel, bpy.types.Panel):
280     bl_label = "Stereo"
281     COMPAT_ENGINES = {'BLENDER_GAME'}
282
283     def draw(self, context):
284         layout = self.layout
285
286         gs = context.scene.game_settings
287         stereo_mode = gs.stereo
288
289         # stereo options:
290         layout.prop(gs, "stereo", expand=True)
291
292         # stereo:
293         if stereo_mode == 'STEREO':
294             layout.prop(gs, "stereo_mode")
295             layout.prop(gs, "stereo_eye_separation")
296
297         # dome:
298         elif stereo_mode == 'DOME':
299             layout.prop(gs, "dome_mode", text="Dome Type")
300
301             dome_type = gs.dome_mode
302
303             split = layout.split()
304
305             if dome_type == 'FISHEYE' or \
306                dome_type == 'TRUNCATED_REAR' or \
307                dome_type == 'TRUNCATED_FRONT':
308
309                 col = split.column()
310                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
311                 col.prop(gs, "dome_angle", slider=True)
312
313                 col = split.column()
314                 col.prop(gs, "dome_tesselation", text="Tesselation")
315                 col.prop(gs, "dome_tilt")
316
317             elif dome_type == 'PANORAM_SPH':
318                 col = split.column()
319
320                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
321                 col = split.column()
322                 col.prop(gs, "dome_tesselation", text="Tesselation")
323
324             else:  # cube map
325                 col = split.column()
326                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
327
328                 col = split.column()
329
330             layout.prop(gs, "dome_text")
331
332
333 class RENDER_PT_game_shading(RenderButtonsPanel, bpy.types.Panel):
334     bl_label = "Shading"
335     COMPAT_ENGINES = {'BLENDER_GAME'}
336
337     def draw(self, context):
338         layout = self.layout
339
340         gs = context.scene.game_settings
341
342         layout.prop(gs, "material_mode", expand=True)
343
344         if gs.material_mode == 'GLSL':
345             split = layout.split()
346
347             col = split.column()
348             col.prop(gs, "use_glsl_lights", text="Lights")
349             col.prop(gs, "use_glsl_shaders", text="Shaders")
350             col.prop(gs, "use_glsl_shadows", text="Shadows")
351             col.prop(gs, "use_glsl_color_management", text="Color Management")
352
353             col = split.column()
354             col.prop(gs, "use_glsl_ramps", text="Ramps")
355             col.prop(gs, "use_glsl_nodes", text="Nodes")
356             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
357
358
359 class RENDER_PT_game_performance(RenderButtonsPanel, bpy.types.Panel):
360     bl_label = "Performance"
361     COMPAT_ENGINES = {'BLENDER_GAME'}
362
363     def draw(self, context):
364         layout = self.layout
365
366         gs = context.scene.game_settings
367         row = layout.row()
368         row.prop(gs, "use_frame_rate")
369         row.prop(gs, "use_display_lists")
370
371
372 class RENDER_PT_game_display(RenderButtonsPanel, bpy.types.Panel):
373     bl_label = "Display"
374     COMPAT_ENGINES = {'BLENDER_GAME'}
375
376     def draw(self, context):
377         layout = self.layout
378
379         gs = context.scene.game_settings
380         flow = layout.column_flow()
381         flow.prop(gs, "show_debug_properties", text="Debug Properties")
382         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
383         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
384         flow.prop(gs, "use_deprecation_warnings")
385         flow.prop(gs, "show_mouse", text="Mouse Cursor")
386
387
388 class RENDER_PT_game_sound(RenderButtonsPanel, bpy.types.Panel):
389     bl_label = "Sound"
390     COMPAT_ENGINES = {'BLENDER_GAME'}
391
392     def draw(self, context):
393         layout = self.layout
394
395         scene = context.scene
396
397         layout.prop(scene, "audio_distance_model")
398
399         layout.prop(scene, "audio_doppler_speed", text="Speed")
400         layout.prop(scene, "audio_doppler_factor")
401
402
403 class WorldButtonsPanel():
404     bl_space_type = 'PROPERTIES'
405     bl_region_type = 'WINDOW'
406     bl_context = "world"
407
408
409 class WORLD_PT_game_context_world(WorldButtonsPanel, bpy.types.Panel):
410     bl_label = ""
411     bl_options = {'HIDE_HEADER'}
412     COMPAT_ENGINES = {'BLENDER_GAME'}
413
414     @classmethod
415     def poll(cls, context):
416         rd = context.scene.render
417         return (context.scene) and (rd.use_game_engine)
418
419     def draw(self, context):
420         layout = self.layout
421
422         scene = context.scene
423         world = context.world
424         space = context.space_data
425
426         split = layout.split(percentage=0.65)
427         if scene:
428             split.template_ID(scene, "world", new="world.new")
429         elif world:
430             split.template_ID(space, "pin_id")
431
432
433 class WORLD_PT_game_world(WorldButtonsPanel, bpy.types.Panel):
434     bl_label = "World"
435     COMPAT_ENGINES = {'BLENDER_GAME'}
436
437     @classmethod
438     def poll(cls, context):
439         scene = context.scene
440         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
441
442     def draw(self, context):
443         layout = self.layout
444
445         world = context.world
446
447         row = layout.row()
448         row.column().prop(world, "horizon_color")
449         row.column().prop(world, "ambient_color")
450
451
452 class WORLD_PT_game_mist(WorldButtonsPanel, bpy.types.Panel):
453     bl_label = "Mist"
454     COMPAT_ENGINES = {'BLENDER_GAME'}
455
456     @classmethod
457     def poll(cls, context):
458         scene = context.scene
459         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
460
461     def draw_header(self, context):
462         world = context.world
463
464         self.layout.prop(world.mist_settings, "use_mist", text="")
465
466     def draw(self, context):
467         layout = self.layout
468
469         world = context.world
470
471         layout.active = world.mist_settings.use_mist
472
473         row = layout.row()
474         row.prop(world.mist_settings, "start")
475         row.prop(world.mist_settings, "depth")
476
477
478 class WORLD_PT_game_physics(WorldButtonsPanel, bpy.types.Panel):
479     bl_label = "Physics"
480     COMPAT_ENGINES = {'BLENDER_GAME'}
481
482     @classmethod
483     def poll(cls, context):
484         scene = context.scene
485         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
486
487     def draw(self, context):
488         layout = self.layout
489
490         gs = context.scene.game_settings
491
492         layout.prop(gs, "physics_engine")
493         if gs.physics_engine != 'NONE':
494             layout.prop(gs, "physics_gravity", text="Gravity")
495
496             split = layout.split()
497
498             col = split.column()
499             col.label(text="Physics Steps:")
500             sub = col.column(align=True)
501             sub.prop(gs, "physics_step_max", text="Max")
502             sub.prop(gs, "physics_step_sub", text="Substeps")
503             col.prop(gs, "fps", text="FPS")
504
505             col = split.column()
506             col.label(text="Logic Steps:")
507             col.prop(gs, "logic_step_max", text="Max")
508
509             col = layout.column()
510             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
511             sub = col.column()
512             sub.active = gs.use_occlusion_culling
513             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
514
515         else:
516             split = layout.split()
517
518             col = split.column()
519             col.label(text="Physics Steps:")
520             col.prop(gs, "fps", text="FPS")
521
522             col = split.column()
523             col.label(text="Logic Steps:")
524             col.prop(gs, "logic_step_max", text="Max")
525
526 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, bpy.types.Panel):
527     bl_label = "Obstacle simulation"
528     COMPAT_ENGINES = {'BLENDER_GAME'}
529
530     def draw(self, context):
531         layout = self.layout
532
533         gs = context.scene.game_settings
534
535         layout.prop(gs, "obstacle_simulation", text = "Type")
536         if gs.obstacle_simulation != 'None':
537             layout.prop(gs, "level_height")
538             layout.prop(gs, "show_obstacle_simulation")
539
540 if __name__ == "__main__":  # only for live edit.
541     bpy.utils.register_module(__name__)