Merged changes in the trunk up to revision 47381.
[blender-staging.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 from bpy.types import Panel
22
23
24 class PhysicsButtonsPanel():
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "physics"
28
29
30 class PHYSICS_PT_game_physics(PhysicsButtonsPanel, Panel):
31     bl_label = "Physics"
32     COMPAT_ENGINES = {'BLENDER_GAME'}
33
34     @classmethod
35     def poll(cls, context):
36         ob = context.active_object
37         rd = context.scene.render
38         return ob and ob.game and (rd.engine in cls.COMPAT_ENGINES)
39
40     def draw(self, context):
41         layout = self.layout
42
43         ob = context.active_object
44         game = ob.game
45         soft = ob.game.soft_body
46
47         layout.prop(game, "physics_type")
48         layout.separator()
49
50         physics_type = game.physics_type
51
52         if physics_type == 'CHARACTER':
53             layout.prop(game, "step_height", slider=True)
54             layout.prop(game, "jump_speed")
55             layout.prop(game, "fall_speed")
56
57         elif physics_type in {'DYNAMIC', 'RIGID_BODY'}:
58             split = layout.split()
59
60             col = split.column()
61             col.prop(game, "use_actor")
62             col.prop(game, "use_ghost")
63             col.prop(ob, "hide_render", text="Invisible")  # out of place but useful
64
65             col = split.column()
66             col.prop(game, "use_material_physics_fh")
67             col.prop(game, "use_rotate_from_normal")
68             col.prop(game, "use_sleep")
69
70             layout.separator()
71
72             split = layout.split()
73
74             col = split.column()
75             col.label(text="Attributes:")
76             col.prop(game, "mass")
77             col.prop(game, "radius")
78             col.prop(game, "form_factor")
79
80             col = split.column()
81             sub = col.column()
82             sub.prop(game, "use_anisotropic_friction")
83             subsub = sub.column()
84             subsub.active = game.use_anisotropic_friction
85             subsub.prop(game, "friction_coefficients", text="", slider=True)
86
87             split = layout.split()
88
89             col = split.column()
90             col.label(text="Velocity:")
91             sub = col.column(align=True)
92             sub.prop(game, "velocity_min", text="Minimum")
93             sub.prop(game, "velocity_max", text="Maximum")
94
95             col = split.column()
96             col.label(text="Damping:")
97             sub = col.column(align=True)
98             sub.prop(game, "damping", text="Translation", slider=True)
99             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
100
101             layout.separator()
102
103             split = layout.split()
104
105             col = split.column()
106             col.label(text="Lock Translation:")
107             col.prop(game, "lock_location_x", text="X")
108             col.prop(game, "lock_location_y", text="Y")
109             col.prop(game, "lock_location_z", text="Z")
110
111             col = split.column()
112             col.label(text="Lock Rotation:")
113             col.prop(game, "lock_rotation_x", text="X")
114             col.prop(game, "lock_rotation_y", text="Y")
115             col.prop(game, "lock_rotation_z", text="Z")
116
117         elif physics_type == 'SOFT_BODY':
118             col = layout.column()
119             col.prop(game, "use_actor")
120             col.prop(game, "use_ghost")
121             col.prop(ob, "hide_render", text="Invisible")
122
123             layout.separator()
124
125             split = layout.split()
126
127             col = split.column()
128             col.label(text="Attributes:")
129             col.prop(game, "mass")
130             # disabled in the code
131             # col.prop(soft, "weld_threshold")
132             col.prop(soft, "location_iterations")
133             col.prop(soft, "linear_stiffness", slider=True)
134             col.prop(soft, "dynamic_friction", slider=True)
135             col.prop(soft, "collision_margin", slider=True)
136             col.prop(soft, "use_bending_constraints", text="Bending Constraints")
137
138             col = split.column()
139             col.prop(soft, "use_shape_match")
140             sub = col.column()
141             sub.active = soft.use_shape_match
142             sub.prop(soft, "shape_threshold", slider=True)
143
144             col.separator()
145
146             col.label(text="Cluster Collision:")
147             col.prop(soft, "use_cluster_rigid_to_softbody")
148             col.prop(soft, "use_cluster_soft_to_softbody")
149             sub = col.column()
150             sub.active = (soft.use_cluster_rigid_to_softbody or soft.use_cluster_soft_to_softbody)
151             sub.prop(soft, "cluster_iterations", text="Iterations")
152
153         elif physics_type == 'STATIC':
154             col = layout.column()
155             col.prop(game, "use_actor")
156             col.prop(game, "use_ghost")
157             col.prop(ob, "hide_render", text="Invisible")
158
159             layout.separator()
160
161             split = layout.split()
162
163             col = split.column()
164             col.label(text="Attributes:")
165             col.prop(game, "radius")
166
167             col = split.column()
168             sub = col.column()
169             sub.prop(game, "use_anisotropic_friction")
170             subsub = sub.column()
171             subsub.active = game.use_anisotropic_friction
172             subsub.prop(game, "friction_coefficients", text="", slider=True)
173
174         elif physics_type == 'SENSOR':
175             col = layout.column()
176             col.prop(game, "use_actor", text="Detect Actors")
177             col.prop(ob, "hide_render", text="Invisible")
178
179         elif physics_type in {'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'}:
180             layout.prop(ob, "hide_render", text="Invisible")
181
182         elif physics_type == 'NAVMESH':
183             layout.operator("mesh.navmesh_face_copy")
184             layout.operator("mesh.navmesh_face_add")
185
186             layout.separator()
187
188             layout.operator("mesh.navmesh_reset")
189             layout.operator("mesh.navmesh_clear")
190
191
192 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, Panel):
193     bl_label = "Collision Bounds"
194     COMPAT_ENGINES = {'BLENDER_GAME'}
195
196     @classmethod
197     def poll(cls, context):
198         game = context.object.game
199         rd = context.scene.render
200         return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC', 'CHARACTER'}) and (rd.engine in cls.COMPAT_ENGINES)
201
202     def draw_header(self, context):
203         game = context.active_object.game
204
205         self.layout.prop(game, "use_collision_bounds", text="")
206
207     def draw(self, context):
208         layout = self.layout
209
210         game = context.active_object.game
211
212         layout.active = game.use_collision_bounds
213         layout.prop(game, "collision_bounds_type", text="Bounds")
214
215         row = layout.row()
216         row.prop(game, "collision_margin", text="Margin", slider=True)
217         row.prop(game, "use_collision_compound", text="Compound")
218
219
220 class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, Panel):
221     bl_label = "Create Obstacle"
222     COMPAT_ENGINES = {'BLENDER_GAME'}
223
224     @classmethod
225     def poll(cls, context):
226         game = context.object.game
227         rd = context.scene.render
228         return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES)
229
230     def draw_header(self, context):
231         game = context.active_object.game
232
233         self.layout.prop(game, "use_obstacle_create", text="")
234
235     def draw(self, context):
236         layout = self.layout
237
238         game = context.active_object.game
239
240         layout.active = game.use_obstacle_create
241
242         row = layout.row()
243         row.prop(game, "obstacle_radius", text="Radius")
244         row.label()
245
246
247 class RenderButtonsPanel():
248     bl_space_type = 'PROPERTIES'
249     bl_region_type = 'WINDOW'
250     bl_context = "render"
251
252     @classmethod
253     def poll(cls, context):
254         rd = context.scene.render
255         return (rd.engine in cls.COMPAT_ENGINES)
256
257
258 class RENDER_PT_embedded(RenderButtonsPanel, Panel):
259     bl_label = "Embedded Player"
260     COMPAT_ENGINES = {'BLENDER_GAME'}
261
262     def draw(self, context):
263         layout = self.layout
264
265         rd = context.scene.render
266
267         row = layout.row()
268         row.operator("view3d.game_start", text="Start")
269         row.label()
270         row = layout.row()
271         row.label(text="Resolution:")
272         row = layout.row(align=True)
273         row.prop(rd, "resolution_x", slider=False, text="X")
274         row.prop(rd, "resolution_y", slider=False, text="Y")
275
276
277 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
278     bl_label = "Standalone Player"
279     COMPAT_ENGINES = {'BLENDER_GAME'}
280
281     def draw(self, context):
282         layout = self.layout
283
284         gs = context.scene.game_settings
285
286         row = layout.row()
287         row.operator("wm.blenderplayer_start", text="Start")
288         row.label()
289
290         row = layout.row()
291         row.label(text="Resolution:")
292         row = layout.row(align=True)
293         row.prop(gs, "resolution_x", slider=False, text="X")
294         row.prop(gs, "resolution_y", slider=False, text="Y")
295         row = layout.row()
296         col = row.column()
297         col.prop(gs, "show_fullscreen")
298         col = row.column()
299         col.prop(gs, "use_desktop")
300         col.active = gs.show_fullscreen
301
302         col = layout.column()
303         col.label(text="Quality:")
304         col.prop(gs, "samples")
305         col = layout.column(align=True)
306         col.prop(gs, "depth", text="Bit Depth", slider=False)
307         col.prop(gs, "frequency", text="Refresh Rate", slider=False)
308
309
310 class RENDER_PT_game_stereo(RenderButtonsPanel, Panel):
311     bl_label = "Stereo"
312     COMPAT_ENGINES = {'BLENDER_GAME'}
313
314     def draw(self, context):
315         layout = self.layout
316
317         gs = context.scene.game_settings
318         stereo_mode = gs.stereo
319
320         # stereo options:
321         layout.prop(gs, "stereo", expand=True)
322
323         # stereo:
324         if stereo_mode == 'STEREO':
325             layout.prop(gs, "stereo_mode")
326             layout.prop(gs, "stereo_eye_separation")
327
328         # dome:
329         elif stereo_mode == 'DOME':
330             layout.prop(gs, "dome_mode", text="Dome Type")
331
332             dome_type = gs.dome_mode
333
334             split = layout.split()
335
336             if dome_type in {'FISHEYE', 'TRUNCATED_REAR', 'TRUNCATED_FRONT'}:
337                 col = split.column()
338
339                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
340                 col.prop(gs, "dome_angle", slider=True)
341
342                 col = split.column()
343                 col.prop(gs, "dome_tessellation", text="Tessellation")
344                 col.prop(gs, "dome_tilt")
345
346             elif dome_type == 'PANORAM_SPH':
347                 col = split.column()
348
349                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
350                 col = split.column()
351                 col.prop(gs, "dome_tessellation", text="Tessellation")
352
353             else:  # cube map
354                 col = split.column()
355
356                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
357
358                 col = split.column()
359
360             layout.prop(gs, "dome_text")
361
362
363 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
364     bl_label = "Shading"
365     COMPAT_ENGINES = {'BLENDER_GAME'}
366
367     def draw(self, context):
368         layout = self.layout
369
370         gs = context.scene.game_settings
371
372         layout.prop(gs, "material_mode", expand=True)
373
374         if gs.material_mode == 'GLSL':
375             split = layout.split()
376
377             col = split.column()
378             col.prop(gs, "use_glsl_lights", text="Lights")
379             col.prop(gs, "use_glsl_shaders", text="Shaders")
380             col.prop(gs, "use_glsl_shadows", text="Shadows")
381             col.prop(gs, "use_glsl_color_management", text="Color Management")
382
383             col = split.column()
384             col.prop(gs, "use_glsl_ramps", text="Ramps")
385             col.prop(gs, "use_glsl_nodes", text="Nodes")
386             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
387
388
389 class RENDER_PT_game_system(RenderButtonsPanel, Panel):
390     bl_label = "System"
391     COMPAT_ENGINES = {'BLENDER_GAME'}
392
393     def draw(self, context):
394         layout = self.layout
395
396         gs = context.scene.game_settings
397         row = layout.row()
398         row.prop(gs, "use_frame_rate")
399         row.prop(gs, "restrict_animation_updates")
400
401         row = layout.row()
402         row.prop(gs, "use_display_lists")
403
404         row = layout.row()
405         row.label("Exit Key")
406         row.prop(gs, "exit_key", text="", event=True)
407
408
409 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
410     bl_label = "Display"
411     COMPAT_ENGINES = {'BLENDER_GAME'}
412
413     def draw(self, context):
414         layout = self.layout
415
416         row = layout.row()
417         row.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
418
419         gs = context.scene.game_settings
420         flow = layout.column_flow()
421         flow.prop(gs, "show_debug_properties", text="Debug Properties")
422         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
423         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
424         flow.prop(gs, "use_deprecation_warnings")
425         flow.prop(gs, "show_mouse", text="Mouse Cursor")
426
427         col = layout.column()
428         col.label(text="Framing:")
429         col.row().prop(gs, "frame_type", expand=True)
430         if gs.frame_type == 'LETTERBOX':
431             col.prop(gs, "frame_color", text="")
432
433
434 class SceneButtonsPanel():
435     bl_space_type = 'PROPERTIES'
436     bl_region_type = 'WINDOW'
437     bl_context = "scene"
438
439
440 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
441     bl_label = "Navigation mesh"
442     bl_options = {'DEFAULT_CLOSED'}
443     COMPAT_ENGINES = {'BLENDER_GAME'}
444
445     @classmethod
446     def poll(cls, context):
447         scene = context.scene
448         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
449
450     def draw(self, context):
451         layout = self.layout
452
453         rd = context.scene.game_settings.recast_data
454
455         layout.operator("mesh.navmesh_make", text='Build navigation mesh')
456
457         col = layout.column()
458         col.label(text="Rasterization:")
459         row = col.row()
460         row.prop(rd, "cell_size")
461         row.prop(rd, "cell_height")
462
463         col = layout.column()
464         col.label(text="Agent:")
465         split = col.split()
466
467         col = split.column()
468         col.prop(rd, "agent_height", text="Height")
469         col.prop(rd, "agent_radius", text="Radius")
470
471         col = split.column()
472         col.prop(rd, "slope_max")
473         col.prop(rd, "climb_max")
474
475         col = layout.column()
476         col.label(text="Region:")
477         row = col.row()
478         row.prop(rd, "region_min_size")
479         row.prop(rd, "region_merge_size")
480
481         col = layout.column()
482         col.label(text="Polygonization:")
483         split = col.split()
484
485         col = split.column()
486         col.prop(rd, "edge_max_len")
487         col.prop(rd, "edge_max_error")
488
489         split.prop(rd, "verts_per_poly")
490
491         col = layout.column()
492         col.label(text="Detail Mesh:")
493         row = col.row()
494         row.prop(rd, "sample_dist")
495         row.prop(rd, "sample_max_error")
496
497
498 class RENDER_PT_game_sound(RenderButtonsPanel, Panel):
499     bl_label = "Sound"
500     COMPAT_ENGINES = {'BLENDER_GAME'}
501
502     def draw(self, context):
503         layout = self.layout
504
505         scene = context.scene
506
507         layout.prop(scene, "audio_distance_model")
508
509         col = layout.column(align=True)
510         col.prop(scene, "audio_doppler_speed", text="Speed")
511         col.prop(scene, "audio_doppler_factor")
512
513
514 class WorldButtonsPanel():
515     bl_space_type = 'PROPERTIES'
516     bl_region_type = 'WINDOW'
517     bl_context = "world"
518
519
520 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
521     bl_label = ""
522     bl_options = {'HIDE_HEADER'}
523     COMPAT_ENGINES = {'BLENDER_GAME'}
524
525     @classmethod
526     def poll(cls, context):
527         rd = context.scene.render
528         return (context.scene) and (rd.use_game_engine)
529
530     def draw(self, context):
531         layout = self.layout
532
533         scene = context.scene
534         world = context.world
535         space = context.space_data
536
537         split = layout.split(percentage=0.65)
538         if scene:
539             split.template_ID(scene, "world", new="world.new")
540         elif world:
541             split.template_ID(space, "pin_id")
542
543
544 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
545     bl_label = "World"
546     COMPAT_ENGINES = {'BLENDER_GAME'}
547
548     @classmethod
549     def poll(cls, context):
550         scene = context.scene
551         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
552
553     def draw(self, context):
554         layout = self.layout
555
556         world = context.world
557
558         row = layout.row()
559         row.column().prop(world, "horizon_color")
560         row.column().prop(world, "ambient_color")
561
562
563 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
564     bl_label = "Mist"
565     COMPAT_ENGINES = {'BLENDER_GAME'}
566
567     @classmethod
568     def poll(cls, context):
569         scene = context.scene
570         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
571
572     def draw_header(self, context):
573         world = context.world
574
575         self.layout.prop(world.mist_settings, "use_mist", text="")
576
577     def draw(self, context):
578         layout = self.layout
579
580         world = context.world
581
582         layout.active = world.mist_settings.use_mist
583         row = layout.row()
584         row.prop(world.mist_settings, "falloff")
585
586         row = layout.row(align=True)
587         row.prop(world.mist_settings, "start")
588         row.prop(world.mist_settings, "depth")
589         row = layout.row()
590         row.prop(world.mist_settings, "intensity", text="Minimum Intensity")
591
592
593 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
594     bl_label = "Physics"
595     COMPAT_ENGINES = {'BLENDER_GAME'}
596
597     @classmethod
598     def poll(cls, context):
599         scene = context.scene
600         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
601
602     def draw(self, context):
603         layout = self.layout
604
605         gs = context.scene.game_settings
606
607         layout.prop(gs, "physics_engine")
608         if gs.physics_engine != 'NONE':
609             layout.prop(gs, "physics_gravity", text="Gravity")
610
611             split = layout.split()
612
613             col = split.column()
614             col.label(text="Physics Steps:")
615             sub = col.column(align=True)
616             sub.prop(gs, "physics_step_max", text="Max")
617             sub.prop(gs, "physics_step_sub", text="Substeps")
618             col.prop(gs, "fps", text="FPS")
619
620             col = split.column()
621             col.label(text="Logic Steps:")
622             col.prop(gs, "logic_step_max", text="Max")
623
624             col = layout.column()
625             col.label(text="Physics Deactivation:")
626             sub = col.row(align=True)
627             sub.prop(gs, "deactivation_linear_threshold", text="Linear Threshold")
628             sub.prop(gs, "deactivation_angular_threshold", text="Angular Threshold")
629             sub = col.row()
630             sub.prop(gs, "deactivation_time", text="Time")
631
632             col = layout.column()
633             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
634             sub = col.column()
635             sub.active = gs.use_occlusion_culling
636             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
637
638         else:
639             split = layout.split()
640
641             col = split.column()
642             col.label(text="Physics Steps:")
643             col.prop(gs, "fps", text="FPS")
644
645             col = split.column()
646             col.label(text="Logic Steps:")
647             col.prop(gs, "logic_step_max", text="Max")
648
649
650 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
651     bl_label = "Obstacle simulation"
652     COMPAT_ENGINES = {'BLENDER_GAME'}
653
654     @classmethod
655     def poll(cls, context):
656         scene = context.scene
657         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
658
659     def draw(self, context):
660         layout = self.layout
661
662         gs = context.scene.game_settings
663
664         layout.prop(gs, "obstacle_simulation", text="Type")
665         if gs.obstacle_simulation != 'NONE':
666             layout.prop(gs, "level_height")
667             layout.prop(gs, "show_obstacle_simulation")
668
669
670 class DataButtonsPanel():
671     bl_space_type = 'PROPERTIES'
672     bl_region_type = 'WINDOW'
673     bl_context = "data"
674
675
676 class DATA_PT_shadow_game(DataButtonsPanel, Panel):
677     bl_label = "Shadow"
678     COMPAT_ENGINES = {'BLENDER_GAME'}
679
680     @classmethod
681     def poll(cls, context):
682         COMPAT_LIGHTS = {'SPOT', 'SUN'}
683         lamp = context.lamp
684         engine = context.scene.render.engine
685         return (lamp and lamp.type in COMPAT_LIGHTS) and (engine in cls.COMPAT_ENGINES)
686
687     def draw_header(self, context):
688         lamp = context.lamp
689
690         self.layout.prop(lamp, "use_shadow", text="")
691
692     def draw(self, context):
693         layout = self.layout
694
695         lamp = context.lamp
696
697         layout.active = lamp.use_shadow
698
699         split = layout.split()
700
701         col = split.column()
702         col.prop(lamp, "shadow_color", text="")
703
704         col = split.column()
705         col.prop(lamp, "use_shadow_layer", text="This Layer Only")
706         col.prop(lamp, "use_only_shadow")
707
708         col = layout.column()
709         col.label("Buffer Type:")
710         col.prop(lamp, "ge_shadow_buffer_type", text="", toggle=True)
711         col.label("Quality:")
712         col = layout.column(align=True)
713         col.prop(lamp, "shadow_buffer_size", text="Size")
714         col.prop(lamp, "shadow_buffer_bias", text="Bias")
715         col.prop(lamp, "shadow_buffer_bleed_bias", text="Bleed Bias")
716
717         row = layout.row()
718         row.label("Clipping:")
719         row = layout.row(align=True)
720         row.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
721         row.prop(lamp, "shadow_buffer_clip_end", text="Clip End")
722
723         if lamp.type == 'SUN':
724             row = layout.row()
725             row.prop(lamp, "shadow_frustum_size", text="Frustum Size")
726
727
728 if __name__ == "__main__":  # only for live edit.
729     bpy.utils.register_module(__name__)