2e309a10940e0ce889f1bdfef8d2d7070ba20d59
[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, Menu
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, "use_actor")
54             layout.prop(ob, "hide_render", text="Invisible")  # out of place but useful
55             layout.prop(game, "step_height", slider=True)
56             layout.prop(game, "jump_speed")
57             layout.prop(game, "fall_speed")
58             layout.prop(game, "jump_max")
59
60         elif physics_type in {'DYNAMIC', 'RIGID_BODY'}:
61             split = layout.split()
62
63             col = split.column()
64             col.prop(game, "use_actor")
65             col.prop(game, "use_ghost")
66             col.prop(ob, "hide_render", text="Invisible")  # out of place but useful
67
68             col = split.column()
69             col.prop(game, "use_material_physics_fh")
70             col.prop(game, "use_rotate_from_normal")
71             col.prop(game, "use_sleep")
72
73             layout.separator()
74
75             split = layout.split()
76
77             col = split.column()
78             col.label(text="Attributes:")
79             col.prop(game, "mass")
80             col.prop(game, "radius")
81             col.prop(game, "form_factor")
82
83             col = split.column()
84             sub = col.column()
85             sub.prop(game, "use_anisotropic_friction")
86             subsub = sub.column()
87             subsub.active = game.use_anisotropic_friction
88             subsub.prop(game, "friction_coefficients", text="", slider=True)
89
90             split = layout.split()
91
92             col = split.column()
93             col.label(text="Linear velocity:")
94             sub = col.column(align=True)
95             sub.prop(game, "velocity_min", text="Minimum")
96             sub.prop(game, "velocity_max", text="Maximum")
97             col.label(text="Angular velocity:")
98             sub = col.column(align=True)
99             sub.prop(game, "angular_velocity_min", text="Minimum")
100             sub.prop(game, "angular_velocity_max", text="Maximum")
101
102             col = split.column()
103             col.label(text="Damping:")
104             sub = col.column(align=True)
105             sub.prop(game, "damping", text="Translation", slider=True)
106             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
107
108             layout.separator()
109
110             split = layout.split()
111
112             col = split.column()
113             col.label(text="Lock Translation:")
114             col.prop(game, "lock_location_x", text="X")
115             col.prop(game, "lock_location_y", text="Y")
116             col.prop(game, "lock_location_z", text="Z")
117
118         if physics_type == 'RIGID_BODY':
119             col = split.column()
120             col.label(text="Lock Rotation:")
121             col.prop(game, "lock_rotation_x", text="X")
122             col.prop(game, "lock_rotation_y", text="Y")
123             col.prop(game, "lock_rotation_z", text="Z")
124
125         elif physics_type == 'SOFT_BODY':
126             col = layout.column()
127             col.prop(game, "use_actor")
128             col.prop(game, "use_ghost")
129             col.prop(ob, "hide_render", text="Invisible")
130
131             layout.separator()
132
133             split = layout.split()
134
135             col = split.column()
136             col.label(text="Attributes:")
137             col.prop(game, "mass")
138             # disabled in the code
139             # col.prop(soft, "weld_threshold")
140             col.prop(soft, "location_iterations")
141             col.prop(soft, "linear_stiffness", slider=True)
142             col.prop(soft, "dynamic_friction", slider=True)
143             col.prop(soft, "collision_margin", slider=True)
144             col.prop(soft, "use_bending_constraints", text="Bending Constraints")
145
146             col = split.column()
147             col.prop(soft, "use_shape_match")
148             sub = col.column()
149             sub.active = soft.use_shape_match
150             sub.prop(soft, "shape_threshold", slider=True)
151
152             col.separator()
153
154             col.label(text="Cluster Collision:")
155             col.prop(soft, "use_cluster_rigid_to_softbody")
156             col.prop(soft, "use_cluster_soft_to_softbody")
157             sub = col.column()
158             sub.active = (soft.use_cluster_rigid_to_softbody or soft.use_cluster_soft_to_softbody)
159             sub.prop(soft, "cluster_iterations", text="Iterations")
160
161         elif physics_type == 'STATIC':
162             col = layout.column()
163             col.prop(game, "use_actor")
164             col.prop(game, "use_ghost")
165             col.prop(game, "use_record_animation")
166             col.prop(ob, "hide_render", text="Invisible")
167
168             layout.separator()
169
170             split = layout.split()
171
172             col = split.column()
173             col.label(text="Attributes:")
174             col.prop(game, "radius")
175
176             col = split.column()
177             sub = col.column()
178             sub.prop(game, "use_anisotropic_friction")
179             subsub = sub.column()
180             subsub.active = game.use_anisotropic_friction
181             subsub.prop(game, "friction_coefficients", text="", slider=True)
182
183         elif physics_type == 'SENSOR':
184             col = layout.column()
185             col.prop(game, "use_actor", text="Detect Actors")
186             col.prop(ob, "hide_render", text="Invisible")
187
188         elif physics_type in {'INVISIBLE', 'NO_COLLISION', 'OCCLUDER'}:
189             layout.prop(ob, "hide_render", text="Invisible")
190
191         elif physics_type == 'NAVMESH':
192             layout.operator("mesh.navmesh_face_copy")
193             layout.operator("mesh.navmesh_face_add")
194
195             layout.separator()
196
197             layout.operator("mesh.navmesh_reset")
198             layout.operator("mesh.navmesh_clear")
199
200
201 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, Panel):
202     bl_label = "Collision Bounds"
203     COMPAT_ENGINES = {'BLENDER_GAME'}
204
205     @classmethod
206     def poll(cls, context):
207         game = context.object.game
208         rd = context.scene.render
209         return (rd.engine in cls.COMPAT_ENGINES) \
210                 and (game.physics_type in {'SENSOR', 'STATIC', 'DYNAMIC', 'RIGID_BODY', 'CHARACTER', 'SOFT_BODY'})
211
212     def draw_header(self, context):
213         game = context.active_object.game
214
215         self.layout.prop(game, "use_collision_bounds", text="")
216
217     def draw(self, context):
218         layout = self.layout
219
220         game = context.active_object.game
221         split = layout.split()
222         split.active = game.use_collision_bounds
223
224         col = split.column()
225         col.prop(game, "collision_bounds_type", text="Bounds")
226
227         row = col.row()
228         row.prop(game, "collision_margin", text="Margin", slider=True)
229
230         sub = row.row()
231         sub.active = game.physics_type not in {'SOFT_BODY', 'CHARACTER'}
232         sub.prop(game, "use_collision_compound", text="Compound")
233
234         layout.separator()
235         split = layout.split()
236         col = split.column()
237         col.prop(game, "collision_group")
238         col = split.column()
239         col.prop(game, "collision_mask")
240
241
242 class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, Panel):
243     bl_label = "Create Obstacle"
244     COMPAT_ENGINES = {'BLENDER_GAME'}
245
246     @classmethod
247     def poll(cls, context):
248         game = context.object.game
249         rd = context.scene.render
250         return (rd.engine in cls.COMPAT_ENGINES) \
251                 and (game.physics_type in {'SENSOR', 'STATIC', 'DYNAMIC', 'RIGID_BODY', 'SOFT_BODY', 'CHARACTER', 'NO_COLLISION'})
252
253     def draw_header(self, context):
254         game = context.active_object.game
255
256         self.layout.prop(game, "use_obstacle_create", text="")
257
258     def draw(self, context):
259         layout = self.layout
260
261         game = context.active_object.game
262
263         layout.active = game.use_obstacle_create
264
265         row = layout.row()
266         row.prop(game, "obstacle_radius", text="Radius")
267         row.label()
268
269
270 class RenderButtonsPanel:
271     bl_space_type = 'PROPERTIES'
272     bl_region_type = 'WINDOW'
273     bl_context = "render"
274
275     @classmethod
276     def poll(cls, context):
277         rd = context.scene.render
278         return (rd.engine in cls.COMPAT_ENGINES)
279
280
281 class RENDER_PT_embedded(RenderButtonsPanel, Panel):
282     bl_label = "Embedded Player"
283     COMPAT_ENGINES = {'BLENDER_GAME'}
284
285     def draw(self, context):
286         layout = self.layout
287
288         rd = context.scene.render
289
290         row = layout.row()
291         row.operator("view3d.game_start", text="Start")
292         row = layout.row()
293         row.label(text="Resolution:")
294         row = layout.row(align=True)
295         row.prop(rd, "resolution_x", slider=False, text="X")
296         row.prop(rd, "resolution_y", slider=False, text="Y")
297
298
299 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
300     bl_label = "Standalone Player"
301     COMPAT_ENGINES = {'BLENDER_GAME'}
302
303     def draw(self, context):
304         import sys
305         layout = self.layout
306         not_osx = sys.platform != "darwin"
307
308         gs = context.scene.game_settings
309
310         row = layout.row()
311         row.operator("wm.blenderplayer_start", text="Start")
312         row = layout.row()
313         row.label(text="Resolution:")
314         row = layout.row(align=True)
315         row.active = not_osx or not gs.show_fullscreen
316         row.prop(gs, "resolution_x", slider=False, text="X")
317         row.prop(gs, "resolution_y", slider=False, text="Y")
318         row = layout.row()
319         col = row.column()
320         col.prop(gs, "show_fullscreen")
321
322         if not_osx:
323             col = row.column()
324             col.prop(gs, "use_desktop")
325             col.active = gs.show_fullscreen
326
327         col = layout.column()
328         col.label(text="Quality:")
329         col.prop(gs, "samples")
330         col = layout.column(align=True)
331         col.prop(gs, "depth", text="Bit Depth", slider=False)
332         col.prop(gs, "frequency", text="Refresh Rate", slider=False)
333
334
335 class RENDER_PT_game_stereo(RenderButtonsPanel, Panel):
336     bl_label = "Stereo"
337     COMPAT_ENGINES = {'BLENDER_GAME'}
338
339     def draw(self, context):
340         layout = self.layout
341
342         gs = context.scene.game_settings
343         stereo_mode = gs.stereo
344
345         # stereo options:
346         layout.prop(gs, "stereo", expand=True)
347
348         # stereo:
349         if stereo_mode == 'STEREO':
350             layout.prop(gs, "stereo_mode")
351             layout.prop(gs, "stereo_eye_separation")
352
353         # dome:
354         elif stereo_mode == 'DOME':
355             layout.prop(gs, "dome_mode", text="Dome Type")
356
357             dome_type = gs.dome_mode
358
359             split = layout.split()
360
361             if dome_type in {'FISHEYE', 'TRUNCATED_REAR', 'TRUNCATED_FRONT'}:
362                 col = split.column()
363                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
364                 col.prop(gs, "dome_angle", slider=True)
365
366                 col = split.column()
367                 col.prop(gs, "dome_tessellation", text="Tessellation")
368                 col.prop(gs, "dome_tilt")
369
370             elif dome_type == 'PANORAM_SPH':
371                 col = split.column()
372                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
373
374                 col = split.column()
375                 col.prop(gs, "dome_tessellation", text="Tessellation")
376
377             else:  # cube map
378                 col = split.column()
379                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
380
381                 col = split.column()
382
383             layout.prop(gs, "dome_text")
384
385
386 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
387     bl_label = "Shading"
388     COMPAT_ENGINES = {'BLENDER_GAME'}
389
390     def draw(self, context):
391         layout = self.layout
392
393         gs = context.scene.game_settings
394
395         layout.prop(gs, "material_mode", expand=True)
396
397         if gs.material_mode == 'GLSL':
398             split = layout.split()
399
400             col = split.column()
401             col.prop(gs, "use_glsl_lights", text="Lights")
402             col.prop(gs, "use_glsl_shaders", text="Shaders")
403             col.prop(gs, "use_glsl_shadows", text="Shadows")
404             col.prop(gs, "use_glsl_environment_lighting", text="Environment Lighting")
405
406             col = split.column()
407             col.prop(gs, "use_glsl_ramps", text="Ramps")
408             col.prop(gs, "use_glsl_nodes", text="Nodes")
409             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
410
411
412 class RENDER_PT_game_system(RenderButtonsPanel, Panel):
413     bl_label = "System"
414     COMPAT_ENGINES = {'BLENDER_GAME'}
415
416     def draw(self, context):
417         layout = self.layout
418
419         gs = context.scene.game_settings
420         col = layout.column()
421         row = col.row()
422         col = row.column()
423         col.prop(gs, "use_frame_rate")
424         col.prop(gs, "use_restrict_animation_updates")
425         col.prop(gs, "use_material_caching")
426         col = row.column()
427         col.prop(gs, "use_display_lists")
428         col.active = gs.raster_storage != 'VERTEX_BUFFER_OBJECT'
429
430         row = layout.row()
431         row.prop(gs, "vsync")
432
433         row = layout.row()
434         row.prop(gs, "raster_storage")
435
436         row = layout.row()
437         row.label("Exit Key")
438         row.prop(gs, "exit_key", text="", event=True)
439
440
441 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
442     bl_label = "Display"
443     COMPAT_ENGINES = {'BLENDER_GAME'}
444
445     def draw(self, context):
446         layout = self.layout
447
448         gs = context.scene.game_settings
449
450         layout.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
451
452         flow = layout.column_flow()
453         flow.prop(gs, "show_debug_properties", text="Debug Properties")
454         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
455         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
456         flow.prop(gs, "use_deprecation_warnings")
457         flow.prop(gs, "show_mouse", text="Mouse Cursor")
458
459         col = layout.column()
460         col.label(text="Framing:")
461         col.row().prop(gs, "frame_type", expand=True)
462         if gs.frame_type == 'LETTERBOX':
463             col.prop(gs, "frame_color", text="")
464
465
466 class SceneButtonsPanel:
467     bl_space_type = 'PROPERTIES'
468     bl_region_type = 'WINDOW'
469     bl_context = "scene"
470
471
472 class SCENE_PT_game_physics(SceneButtonsPanel, Panel):
473     bl_label = "Physics"
474     COMPAT_ENGINES = {'BLENDER_GAME'}
475
476     @classmethod
477     def poll(cls, context):
478         scene = context.scene
479         return (scene.render.engine in cls.COMPAT_ENGINES)
480
481     def draw(self, context):
482         layout = self.layout
483
484         gs = context.scene.game_settings
485
486         layout.prop(gs, "physics_engine", text="Engine")
487         if gs.physics_engine != 'NONE':
488             layout.prop(gs, "physics_gravity", text="Gravity")
489
490             split = layout.split()
491
492             col = split.column()
493             col.label(text="Physics Steps:")
494             sub = col.column(align=True)
495             sub.prop(gs, "physics_step_max", text="Max")
496             sub.prop(gs, "physics_step_sub", text="Substeps")
497             col.prop(gs, "fps", text="FPS")
498
499             col = split.column()
500             col.label(text="Logic Steps:")
501             col.prop(gs, "logic_step_max", text="Max")
502
503             col = layout.column()
504             col.label(text="Physics Deactivation:")
505             sub = col.row(align=True)
506             sub.prop(gs, "deactivation_linear_threshold", text="Linear Threshold")
507             sub.prop(gs, "deactivation_angular_threshold", text="Angular Threshold")
508             sub = col.row()
509             sub.prop(gs, "deactivation_time", text="Time")
510
511             col = layout.column()
512             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
513             sub = col.column()
514             sub.active = gs.use_occlusion_culling
515             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
516
517         else:
518             split = layout.split()
519
520             col = split.column()
521             col.label(text="Physics Steps:")
522             col.prop(gs, "fps", text="FPS")
523
524             col = split.column()
525             col.label(text="Logic Steps:")
526             col.prop(gs, "logic_step_max", text="Max")
527
528
529 class SCENE_PT_game_physics_obstacles(SceneButtonsPanel, Panel):
530     bl_label = "Obstacle Simulation"
531     bl_options = {'DEFAULT_CLOSED'}
532     COMPAT_ENGINES = {'BLENDER_GAME'}
533
534     @classmethod
535     def poll(cls, context):
536         scene = context.scene
537         return (scene.render.engine in cls.COMPAT_ENGINES)
538
539     def draw(self, context):
540         layout = self.layout
541
542         gs = context.scene.game_settings
543
544         layout.prop(gs, "obstacle_simulation", text="Type")
545         if gs.obstacle_simulation != 'NONE':
546             layout.prop(gs, "level_height")
547             layout.prop(gs, "show_obstacle_simulation")
548
549
550 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
551     bl_label = "Navigation Mesh"
552     bl_options = {'DEFAULT_CLOSED'}
553     COMPAT_ENGINES = {'BLENDER_GAME'}
554
555     @classmethod
556     def poll(cls, context):
557         scene = context.scene
558         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
559
560     def draw(self, context):
561         layout = self.layout
562
563         rd = context.scene.game_settings.recast_data
564
565         layout.operator("mesh.navmesh_make", text="Build Navigation Mesh")
566
567         col = layout.column()
568         col.label(text="Rasterization:")
569         row = col.row()
570         row.prop(rd, "cell_size")
571         row.prop(rd, "cell_height")
572
573         col = layout.column()
574         col.label(text="Agent:")
575         split = col.split()
576
577         col = split.column()
578         col.prop(rd, "agent_height", text="Height")
579         col.prop(rd, "agent_radius", text="Radius")
580
581         col = split.column()
582         col.prop(rd, "slope_max")
583         col.prop(rd, "climb_max")
584
585         col = layout.column()
586         col.label(text="Region:")
587         row = col.row()
588         row.prop(rd, "region_min_size")
589         if rd.partitioning != 'LAYERS':
590             row.prop(rd, "region_merge_size")
591
592         col = layout.column()
593         col.prop(rd, "partitioning")
594
595         col = layout.column()
596         col.label(text="Polygonization:")
597         split = col.split()
598
599         col = split.column()
600         col.prop(rd, "edge_max_len")
601         col.prop(rd, "edge_max_error")
602
603         split.prop(rd, "verts_per_poly")
604
605         col = layout.column()
606         col.label(text="Detail Mesh:")
607         row = col.row()
608         row.prop(rd, "sample_dist")
609         row.prop(rd, "sample_max_error")
610
611
612 class SCENE_PT_game_hysteresis(SceneButtonsPanel, Panel):
613     bl_label = "Level of Detail"
614     COMPAT_ENGINES = {'BLENDER_GAME'}
615
616     @classmethod
617     def poll(cls, context):
618         scene = context.scene
619         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
620
621     def draw(self, context):
622         layout = self.layout
623         gs = context.scene.game_settings
624
625         row = layout.row()
626         row.prop(gs, "use_scene_hysteresis", text="Hysteresis")
627         row = layout.row()
628         row.active = gs.use_scene_hysteresis
629         row.prop(gs, "scene_hysteresis_percentage", text="")
630
631
632 class WorldButtonsPanel:
633     bl_space_type = 'PROPERTIES'
634     bl_region_type = 'WINDOW'
635     bl_context = "world"
636
637
638 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
639     bl_label = ""
640     bl_options = {'HIDE_HEADER'}
641     COMPAT_ENGINES = {'BLENDER_GAME'}
642
643     @classmethod
644     def poll(cls, context):
645         rd = context.scene.render
646         return (context.scene) and (rd.engine in cls.COMPAT_ENGINES)
647
648     def draw(self, context):
649         layout = self.layout
650
651         scene = context.scene
652         world = context.world
653         space = context.space_data
654
655         split = layout.split(percentage=0.65)
656         if scene:
657             split.template_ID(scene, "world", new="world.new")
658         elif world:
659             split.template_ID(space, "pin_id")
660
661
662 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
663     bl_label = "World"
664     COMPAT_ENGINES = {'BLENDER_GAME'}
665
666     @classmethod
667     def poll(cls, context):
668         scene = context.scene
669         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
670
671     def draw(self, context):
672         layout = self.layout
673
674         world = context.world
675
676         row = layout.row()
677         row.column().prop(world, "horizon_color")
678         row.column().prop(world, "zenith_color")
679         row.column().prop(world, "ambient_color")
680
681
682 class WORLD_PT_game_environment_lighting(WorldButtonsPanel, Panel):
683     bl_label = "Environment Lighting"
684     COMPAT_ENGINES = {'BLENDER_GAME'}
685
686     @classmethod
687     def poll(cls, context):
688         scene = context.scene
689         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
690
691     def draw_header(self, context):
692         light = context.world.light_settings
693         self.layout.prop(light, "use_environment_light", text="")
694
695     def draw(self, context):
696         layout = self.layout
697
698         light = context.world.light_settings
699
700         layout.active = light.use_environment_light
701
702         split = layout.split()
703         split.prop(light, "environment_energy", text="Energy")
704         split.prop(light, "environment_color", text="")
705
706
707 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
708     bl_label = "Mist"
709     COMPAT_ENGINES = {'BLENDER_GAME'}
710
711     @classmethod
712     def poll(cls, context):
713         scene = context.scene
714         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
715
716     def draw_header(self, context):
717         world = context.world
718
719         self.layout.prop(world.mist_settings, "use_mist", text="")
720
721     def draw(self, context):
722         layout = self.layout
723
724         world = context.world
725
726         layout.active = world.mist_settings.use_mist
727
728         layout.prop(world.mist_settings, "falloff")
729
730         row = layout.row(align=True)
731         row.prop(world.mist_settings, "start")
732         row.prop(world.mist_settings, "depth")
733
734         layout.prop(world.mist_settings, "intensity", text="Minimum Intensity")
735
736
737 class DataButtonsPanel:
738     bl_space_type = 'PROPERTIES'
739     bl_region_type = 'WINDOW'
740     bl_context = "data"
741
742
743 class DATA_PT_shadow_game(DataButtonsPanel, Panel):
744     bl_label = "Shadow"
745     COMPAT_ENGINES = {'BLENDER_GAME'}
746
747     @classmethod
748     def poll(cls, context):
749         COMPAT_LIGHTS = {'SPOT', 'SUN'}
750         lamp = context.lamp
751         engine = context.scene.render.engine
752         return (lamp and lamp.type in COMPAT_LIGHTS) and (engine in cls.COMPAT_ENGINES)
753
754     def draw_header(self, context):
755         lamp = context.lamp
756
757         self.layout.prop(lamp, "use_shadow", text="")
758
759     def draw(self, context):
760         layout = self.layout
761
762         lamp = context.lamp
763
764         layout.active = lamp.use_shadow
765
766         split = layout.split()
767
768         col = split.column()
769         col.prop(lamp, "shadow_color", text="")
770         if lamp.type == 'SUN':
771             col.prop(lamp, "show_shadow_box")
772
773         col = split.column()
774         col.prop(lamp, "use_shadow_layer", text="This Layer Only")
775         col.prop(lamp, "use_only_shadow")
776
777         col = layout.column()
778         col.label("Buffer Type:")
779         col.prop(lamp, "ge_shadow_buffer_type", text="", toggle=True)
780         col.label("Quality:")
781         col = layout.column(align=True)
782         col.prop(lamp, "shadow_buffer_size", text="Size")
783         col.prop(lamp, "shadow_buffer_bias", text="Bias")
784         col.prop(lamp, "shadow_buffer_bleed_bias", text="Bleed Bias")
785
786         row = layout.row()
787         row.label("Clipping:")
788         row = layout.row(align=True)
789         row.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
790         row.prop(lamp, "shadow_buffer_clip_end", text="Clip End")
791
792         if lamp.type == 'SUN':
793             row = layout.row()
794             row.prop(lamp, "shadow_frustum_size", text="Frustum Size")
795
796
797 class ObjectButtonsPanel:
798     bl_space_type = 'PROPERTIES'
799     bl_region_type = 'WINDOW'
800     bl_context = "object"
801
802
803 class OBJECT_MT_lod_tools(Menu):
804     bl_label = "Level Of Detail Tools"
805
806     def draw(self, context):
807         layout = self.layout
808
809         layout.operator("object.lod_by_name", text="Set By Name")
810         layout.operator("object.lod_generate", text="Generate")
811         layout.operator("object.lod_clear_all", text="Clear All", icon='PANEL_CLOSE')
812
813
814 class OBJECT_PT_levels_of_detail(ObjectButtonsPanel, Panel):
815     bl_label = "Levels of Detail"
816     COMPAT_ENGINES = {'BLENDER_GAME'}
817
818     @classmethod
819     def poll(cls, context):
820         return context.scene.render.engine in cls.COMPAT_ENGINES
821
822     def draw(self, context):
823         layout = self.layout
824         ob = context.object
825         gs = context.scene.game_settings
826
827         col = layout.column()
828
829         for i, level in enumerate(ob.lod_levels):
830             if i == 0:
831                 continue
832             box = col.box()
833             row = box.row()
834             row.prop(level, "object", text="")
835             row.operator("object.lod_remove", text="", icon='PANEL_CLOSE').index = i
836
837             row = box.row()
838             row.prop(level, "distance")
839             row = row.row(align=True)
840             row.prop(level, "use_mesh", text="")
841             row.prop(level, "use_material", text="")
842
843             row = box.row()
844             row.active = gs.use_scene_hysteresis
845             row.prop(level, "use_object_hysteresis", text="Hysteresis Override")
846             row = box.row()
847             row.active = gs.use_scene_hysteresis and level.use_object_hysteresis
848             row.prop(level, "object_hysteresis_percentage", text="")
849
850         row = col.row(align=True)
851         row.operator("object.lod_add", text="Add", icon='ZOOMIN')
852         row.menu("OBJECT_MT_lod_tools", text="", icon='TRIA_DOWN')
853
854
855 classes = (
856     DATA_PT_shadow_game,
857     OBJECT_MT_lod_tools,
858     OBJECT_PT_levels_of_detail,
859     PHYSICS_PT_game_collision_bounds,
860     PHYSICS_PT_game_obstacles,
861     PHYSICS_PT_game_physics,
862     RENDER_PT_embedded,
863     RENDER_PT_game_display,
864     RENDER_PT_game_player,
865     RENDER_PT_game_shading,
866     RENDER_PT_game_stereo,
867     RENDER_PT_game_system,
868     SCENE_PT_game_hysteresis,
869     SCENE_PT_game_navmesh,
870     SCENE_PT_game_physics,
871     SCENE_PT_game_physics_obstacles,
872     WORLD_PT_game_context_world,
873     WORLD_PT_game_environment_lighting,
874     WORLD_PT_game_mist,
875     WORLD_PT_game_world,
876 )
877
878 if __name__ == "__main__":  # only for live edit.
879     from bpy.utils import register_class
880     for cls in classes:
881         register_class(cls)