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