synched with trunk at revision 34793
[blender-staging.git] / release / scripts / 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")
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         split = layout.split()
194
195         col = split.column()
196         col.prop(game, "collision_margin", text="Margin", slider=True)
197
198         col = split.column()
199         col.prop(game, "use_collision_compound", text="Compound")
200
201 class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, bpy.types.Panel):
202     bl_label = "Create obstacle"
203     COMPAT_ENGINES = {'BLENDER_GAME'}
204
205     @classmethod
206     def poll(self, context):
207         game = context.object.game
208         rd = context.scene.render
209         return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'))  and (rd.engine in cls.COMPAT_ENGINES)
210
211     def draw_header(self, context):
212         game = context.active_object.game
213
214         self.layout.prop(game, "create_obstacle", text="")
215
216     def draw(self, context):
217         layout = self.layout
218
219         game = context.active_object.game
220
221         layout.active = game.create_obstacle
222
223         split = layout.split()
224         col = split.column()
225         col.prop(game, "obstacle_radius", text="Radius")
226
227 class RenderButtonsPanel():
228     bl_space_type = 'PROPERTIES'
229     bl_region_type = 'WINDOW'
230     bl_context = "render"
231
232     @classmethod
233     def poll(cls, context):
234         rd = context.scene.render
235         return (rd.engine in cls.COMPAT_ENGINES)
236
237
238 class RENDER_PT_game(RenderButtonsPanel, bpy.types.Panel):
239     bl_label = "Game"
240     COMPAT_ENGINES = {'BLENDER_GAME'}
241
242     def draw(self, context):
243         layout = self.layout
244
245         row = layout.row()
246         row.operator("view3d.game_start", text="Start")
247         row.label()
248
249
250 class RENDER_PT_game_player(RenderButtonsPanel, bpy.types.Panel):
251     bl_label = "Standalone Player"
252     COMPAT_ENGINES = {'BLENDER_GAME'}
253
254     def draw(self, context):
255         layout = self.layout
256
257         gs = context.scene.game_settings
258
259         layout.prop(gs, "show_fullscreen")
260
261         split = layout.split()
262
263         col = split.column()
264         col.label(text="Resolution:")
265         sub = col.column(align=True)
266         sub.prop(gs, "resolution_x", slider=False, text="X")
267         sub.prop(gs, "resolution_y", slider=False, text="Y")
268
269         col = split.column()
270         col.label(text="Quality:")
271         sub = col.column(align=True)
272         sub.prop(gs, "depth", text="Bit Depth", slider=False)
273         sub.prop(gs, "frequency", text="FPS", slider=False)
274
275         # framing:
276         col = layout.column()
277         col.label(text="Framing:")
278         col.row().prop(gs, "frame_type", expand=True)
279         if gs.frame_type == 'LETTERBOX':
280             col.prop(gs, "frame_color", text="")
281
282
283 class RENDER_PT_game_stereo(RenderButtonsPanel, bpy.types.Panel):
284     bl_label = "Stereo"
285     COMPAT_ENGINES = {'BLENDER_GAME'}
286
287     def draw(self, context):
288         layout = self.layout
289
290         gs = context.scene.game_settings
291         stereo_mode = gs.stereo
292
293         # stereo options:
294         layout.prop(gs, "stereo", expand=True)
295
296         # stereo:
297         if stereo_mode == 'STEREO':
298             layout.prop(gs, "stereo_mode")
299             layout.prop(gs, "stereo_eye_separation")
300
301         # dome:
302         elif stereo_mode == 'DOME':
303             layout.prop(gs, "dome_mode", text="Dome Type")
304
305             dome_type = gs.dome_mode
306
307             split = layout.split()
308
309             if dome_type == 'FISHEYE' or \
310                dome_type == 'TRUNCATED_REAR' or \
311                dome_type == 'TRUNCATED_FRONT':
312
313                 col = split.column()
314                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
315                 col.prop(gs, "dome_angle", slider=True)
316
317                 col = split.column()
318                 col.prop(gs, "dome_tesselation", text="Tesselation")
319                 col.prop(gs, "dome_tilt")
320
321             elif dome_type == 'PANORAM_SPH':
322                 col = split.column()
323
324                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
325                 col = split.column()
326                 col.prop(gs, "dome_tesselation", text="Tesselation")
327
328             else:  # cube map
329                 col = split.column()
330                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
331
332                 col = split.column()
333
334             layout.prop(gs, "dome_text")
335
336
337 class RENDER_PT_game_shading(RenderButtonsPanel, bpy.types.Panel):
338     bl_label = "Shading"
339     COMPAT_ENGINES = {'BLENDER_GAME'}
340
341     def draw(self, context):
342         layout = self.layout
343
344         gs = context.scene.game_settings
345
346         layout.prop(gs, "material_mode", expand=True)
347
348         if gs.material_mode == 'GLSL':
349             split = layout.split()
350
351             col = split.column()
352             col.prop(gs, "use_glsl_lights", text="Lights")
353             col.prop(gs, "use_glsl_shaders", text="Shaders")
354             col.prop(gs, "use_glsl_shadows", text="Shadows")
355
356             col = split.column()
357             col.prop(gs, "use_glsl_ramps", text="Ramps")
358             col.prop(gs, "use_glsl_nodes", text="Nodes")
359             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
360
361
362 class RENDER_PT_game_performance(RenderButtonsPanel, bpy.types.Panel):
363     bl_label = "Performance"
364     COMPAT_ENGINES = {'BLENDER_GAME'}
365
366     def draw(self, context):
367         layout = self.layout
368
369         gs = context.scene.game_settings
370         row = layout.row()
371         row.prop(gs, "use_frame_rate")
372         row.prop(gs, "use_display_lists")
373
374
375 class RENDER_PT_game_display(RenderButtonsPanel, bpy.types.Panel):
376     bl_label = "Display"
377     COMPAT_ENGINES = {'BLENDER_GAME'}
378
379     def draw(self, context):
380         layout = self.layout
381
382         gs = context.scene.game_settings
383         flow = layout.column_flow()
384         flow.prop(gs, "show_debug_properties", text="Debug Properties")
385         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
386         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
387         flow.prop(gs, "use_deprecation_warnings")
388         flow.prop(gs, "show_mouse")
389
390
391 class RENDER_PT_game_sound(RenderButtonsPanel, bpy.types.Panel):
392     bl_label = "Sound"
393     COMPAT_ENGINES = {'BLENDER_GAME'}
394
395     def draw(self, context):
396         layout = self.layout
397
398         scene = context.scene
399
400         layout.prop(scene, "audio_distance_model")
401
402         layout.prop(scene, "audio_doppler_speed", text="Speed")
403         layout.prop(scene, "audio_doppler_factor")
404
405
406 class WorldButtonsPanel():
407     bl_space_type = 'PROPERTIES'
408     bl_region_type = 'WINDOW'
409     bl_context = "world"
410
411
412 class WORLD_PT_game_context_world(WorldButtonsPanel, bpy.types.Panel):
413     bl_label = ""
414     bl_options = {'HIDE_HEADER'}
415     COMPAT_ENGINES = {'BLENDER_GAME'}
416
417     @classmethod
418     def poll(cls, context):
419         rd = context.scene.render
420         return (context.scene) and (rd.use_game_engine)
421
422     def draw(self, context):
423         layout = self.layout
424
425         scene = context.scene
426         world = context.world
427         space = context.space_data
428
429         split = layout.split(percentage=0.65)
430         if scene:
431             split.template_ID(scene, "world", new="world.new")
432         elif world:
433             split.template_ID(space, "pin_id")
434
435
436 class WORLD_PT_game_world(WorldButtonsPanel, bpy.types.Panel):
437     bl_label = "World"
438     COMPAT_ENGINES = {'BLENDER_GAME'}
439
440     @classmethod
441     def poll(cls, context):
442         scene = context.scene
443         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
444
445     def draw(self, context):
446         layout = self.layout
447
448         world = context.world
449
450         split = layout.split()
451
452         col = split.column()
453         col.prop(world, "horizon_color")
454
455         col = split.column()
456         col.prop(world, "ambient_color")
457
458
459 class WORLD_PT_game_mist(WorldButtonsPanel, bpy.types.Panel):
460     bl_label = "Mist"
461     COMPAT_ENGINES = {'BLENDER_GAME'}
462
463     @classmethod
464     def poll(cls, context):
465         scene = context.scene
466         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
467
468     def draw_header(self, context):
469         world = context.world
470
471         self.layout.prop(world.mist_settings, "use_mist", text="")
472
473     def draw(self, context):
474         layout = self.layout
475
476         world = context.world
477
478         layout.active = world.mist_settings.use_mist
479         split = layout.split()
480
481         col = split.column()
482         col.prop(world.mist_settings, "start")
483
484         col = split.column()
485         col.prop(world.mist_settings, "depth")
486
487
488 class WORLD_PT_game_physics(WorldButtonsPanel, bpy.types.Panel):
489     bl_label = "Physics"
490     COMPAT_ENGINES = {'BLENDER_GAME'}
491
492     @classmethod
493     def poll(cls, context):
494         scene = context.scene
495         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
496
497     def draw(self, context):
498         layout = self.layout
499
500         gs = context.scene.game_settings
501
502         layout.prop(gs, "physics_engine")
503         if gs.physics_engine != 'NONE':
504             layout.prop(gs, "physics_gravity", text="Gravity")
505
506             split = layout.split()
507
508             col = split.column()
509             col.label(text="Physics Steps:")
510             sub = col.column(align=True)
511             sub.prop(gs, "physics_step_max", text="Max")
512             sub.prop(gs, "physics_step_sub", text="Substeps")
513             col.prop(gs, "fps", text="FPS")
514
515             col = split.column()
516             col.label(text="Logic Steps:")
517             col.prop(gs, "logic_step_max", text="Max")
518
519             col = layout.column()
520             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
521             sub = col.column()
522             sub.active = gs.use_occlusion_culling
523             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
524
525         else:
526             split = layout.split()
527
528             col = split.column()
529             col.label(text="Physics Steps:")
530             col.prop(gs, "fps", text="FPS")
531
532             col = split.column()
533             col.label(text="Logic Steps:")
534             col.prop(gs, "logic_step_max", text="Max")
535
536 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, bpy.types.Panel):
537     bl_label = "Obstacle simulation"
538     COMPAT_ENGINES = {'BLENDER_GAME'}
539
540     def draw(self, context):
541         layout = self.layout
542
543         gs = context.scene.game_settings
544
545         layout.prop(gs, "obstacle_simulation", text = "Type")
546         if gs.obstacle_simulation != 'None':
547             layout.prop(gs, "level_height")
548             layout.prop(gs, "show_obstacle_simulation")
549
550 def register():
551     bpy.utils.register_module(__name__)
552
553
554 def unregister():
555     bpy.utils.unregister_module(__name__)
556
557 if __name__ == "__main__":
558     register()