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