Use COMPAT_ENGINES instead of RenderEngine.use_game_engine for panel poll methods
[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             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.label()
293         row = layout.row()
294         row.label(text="Resolution:")
295         row = layout.row(align=True)
296         row.prop(rd, "resolution_x", slider=False, text="X")
297         row.prop(rd, "resolution_y", slider=False, text="Y")
298
299
300 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
301     bl_label = "Standalone Player"
302     COMPAT_ENGINES = {'BLENDER_GAME'}
303
304     def draw(self, context):
305         import sys
306         layout = self.layout
307         not_osx = sys.platform != "darwin"
308
309         gs = context.scene.game_settings
310
311         row = layout.row()
312         row.operator("wm.blenderplayer_start", text="Start")
313         row.label()
314
315         row = layout.row()
316         row.label(text="Resolution:")
317         row = layout.row(align=True)
318         row.active = not_osx or not gs.show_fullscreen
319         row.prop(gs, "resolution_x", slider=False, text="X")
320         row.prop(gs, "resolution_y", slider=False, text="Y")
321         row = layout.row()
322         col = row.column()
323         col.prop(gs, "show_fullscreen")
324
325         if not_osx:
326             col = row.column()
327             col.prop(gs, "use_desktop")
328             col.active = gs.show_fullscreen
329
330         col = layout.column()
331         col.label(text="Quality:")
332         col.prop(gs, "samples")
333         col = layout.column(align=True)
334         col.prop(gs, "depth", text="Bit Depth", slider=False)
335         col.prop(gs, "frequency", text="Refresh Rate", slider=False)
336
337
338 class RENDER_PT_game_stereo(RenderButtonsPanel, Panel):
339     bl_label = "Stereo"
340     COMPAT_ENGINES = {'BLENDER_GAME'}
341
342     def draw(self, context):
343         layout = self.layout
344
345         gs = context.scene.game_settings
346         stereo_mode = gs.stereo
347
348         # stereo options:
349         layout.prop(gs, "stereo", expand=True)
350
351         # stereo:
352         if stereo_mode == 'STEREO':
353             layout.prop(gs, "stereo_mode")
354             layout.prop(gs, "stereo_eye_separation")
355
356         # dome:
357         elif stereo_mode == 'DOME':
358             layout.prop(gs, "dome_mode", text="Dome Type")
359
360             dome_type = gs.dome_mode
361
362             split = layout.split()
363
364             if dome_type in {'FISHEYE', 'TRUNCATED_REAR', 'TRUNCATED_FRONT'}:
365                 col = split.column()
366                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
367                 col.prop(gs, "dome_angle", slider=True)
368
369                 col = split.column()
370                 col.prop(gs, "dome_tessellation", text="Tessellation")
371                 col.prop(gs, "dome_tilt")
372
373             elif dome_type == 'PANORAM_SPH':
374                 col = split.column()
375                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
376
377                 col = split.column()
378                 col.prop(gs, "dome_tessellation", text="Tessellation")
379
380             else:  # cube map
381                 col = split.column()
382                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
383
384                 col = split.column()
385
386             layout.prop(gs, "dome_text")
387
388
389 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
390     bl_label = "Shading"
391     COMPAT_ENGINES = {'BLENDER_GAME'}
392
393     def draw(self, context):
394         layout = self.layout
395
396         gs = context.scene.game_settings
397
398         layout.prop(gs, "material_mode", expand=True)
399
400         if gs.material_mode == 'GLSL':
401             split = layout.split()
402
403             col = split.column()
404             col.prop(gs, "use_glsl_lights", text="Lights")
405             col.prop(gs, "use_glsl_shaders", text="Shaders")
406             col.prop(gs, "use_glsl_shadows", text="Shadows")
407             col.prop(gs, "use_glsl_environment_lighting", text="Environment Lighting")
408
409             col = split.column()
410             col.prop(gs, "use_glsl_ramps", text="Ramps")
411             col.prop(gs, "use_glsl_nodes", text="Nodes")
412             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
413
414
415 class RENDER_PT_game_system(RenderButtonsPanel, Panel):
416     bl_label = "System"
417     COMPAT_ENGINES = {'BLENDER_GAME'}
418
419     def draw(self, context):
420         layout = self.layout
421
422         gs = context.scene.game_settings
423         col = layout.column()
424         row = col.row()
425         col = row.column()
426         col.prop(gs, "use_frame_rate")
427         col.prop(gs, "use_restrict_animation_updates")
428         col.prop(gs, "use_material_caching")
429         col = row.column()
430         col.prop(gs, "use_display_lists")
431         col.active = gs.raster_storage != 'VERTEX_BUFFER_OBJECT'
432
433         row = layout.row()
434         row.prop(gs, "vsync")
435
436         row = layout.row()
437         row.prop(gs, "raster_storage")
438
439         row = layout.row()
440         row.label("Exit Key")
441         row.prop(gs, "exit_key", text="", event=True)
442
443
444 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
445     bl_label = "Display"
446     COMPAT_ENGINES = {'BLENDER_GAME'}
447
448     def draw(self, context):
449         layout = self.layout
450
451         gs = context.scene.game_settings
452
453         layout.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
454
455         flow = layout.column_flow()
456         flow.prop(gs, "show_debug_properties", text="Debug Properties")
457         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
458         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
459         flow.prop(gs, "use_deprecation_warnings")
460         flow.prop(gs, "show_mouse", text="Mouse Cursor")
461
462         col = layout.column()
463         col.label(text="Framing:")
464         col.row().prop(gs, "frame_type", expand=True)
465         if gs.frame_type == 'LETTERBOX':
466             col.prop(gs, "frame_color", text="")
467
468
469 class SceneButtonsPanel:
470     bl_space_type = 'PROPERTIES'
471     bl_region_type = 'WINDOW'
472     bl_context = "scene"
473
474
475 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
476     bl_label = "Navigation mesh"
477     bl_options = {'DEFAULT_CLOSED'}
478     COMPAT_ENGINES = {'BLENDER_GAME'}
479
480     @classmethod
481     def poll(cls, context):
482         scene = context.scene
483         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
484
485     def draw(self, context):
486         layout = self.layout
487
488         rd = context.scene.game_settings.recast_data
489
490         layout.operator("mesh.navmesh_make", text="Build navigation mesh")
491
492         col = layout.column()
493         col.label(text="Rasterization:")
494         row = col.row()
495         row.prop(rd, "cell_size")
496         row.prop(rd, "cell_height")
497
498         col = layout.column()
499         col.label(text="Agent:")
500         split = col.split()
501
502         col = split.column()
503         col.prop(rd, "agent_height", text="Height")
504         col.prop(rd, "agent_radius", text="Radius")
505
506         col = split.column()
507         col.prop(rd, "slope_max")
508         col.prop(rd, "climb_max")
509
510         col = layout.column()
511         col.label(text="Region:")
512         row = col.row()
513         row.prop(rd, "region_min_size")
514         if rd.partitioning != 'LAYERS':
515             row.prop(rd, "region_merge_size")
516
517         col = layout.column()
518         col.prop(rd, "partitioning")
519
520         col = layout.column()
521         col.label(text="Polygonization:")
522         split = col.split()
523
524         col = split.column()
525         col.prop(rd, "edge_max_len")
526         col.prop(rd, "edge_max_error")
527
528         split.prop(rd, "verts_per_poly")
529
530         col = layout.column()
531         col.label(text="Detail Mesh:")
532         row = col.row()
533         row.prop(rd, "sample_dist")
534         row.prop(rd, "sample_max_error")
535
536
537 class SCENE_PT_game_hysteresis(SceneButtonsPanel, Panel):
538     bl_label = "Level of Detail"
539     COMPAT_ENGINES = {'BLENDER_GAME'}
540
541     @classmethod
542     def poll(cls, context):
543         scene = context.scene
544         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
545
546     def draw(self, context):
547         layout = self.layout
548         gs = context.scene.game_settings
549
550         row = layout.row()
551         row.prop(gs, "use_scene_hysteresis", text="Hysteresis")
552         row = layout.row()
553         row.active = gs.use_scene_hysteresis
554         row.prop(gs, "scene_hysteresis_percentage", text="")
555
556
557 class WorldButtonsPanel:
558     bl_space_type = 'PROPERTIES'
559     bl_region_type = 'WINDOW'
560     bl_context = "world"
561
562
563 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
564     bl_label = ""
565     bl_options = {'HIDE_HEADER'}
566     COMPAT_ENGINES = {'BLENDER_GAME'}
567
568     @classmethod
569     def poll(cls, context):
570         rd = context.scene.render
571         return (context.scene) and (rd.engine in cls.COMPAT_ENGINES)
572
573     def draw(self, context):
574         layout = self.layout
575
576         scene = context.scene
577         world = context.world
578         space = context.space_data
579
580         split = layout.split(percentage=0.65)
581         if scene:
582             split.template_ID(scene, "world", new="world.new")
583         elif world:
584             split.template_ID(space, "pin_id")
585
586
587 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
588     bl_label = "World"
589     COMPAT_ENGINES = {'BLENDER_GAME'}
590
591     @classmethod
592     def poll(cls, context):
593         scene = context.scene
594         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
595
596     def draw(self, context):
597         layout = self.layout
598
599         world = context.world
600
601         row = layout.row()
602         row.column().prop(world, "horizon_color")
603         row.column().prop(world, "zenith_color")
604         row.column().prop(world, "ambient_color")
605
606
607 class WORLD_PT_game_environment_lighting(WorldButtonsPanel, Panel):
608     bl_label = "Environment Lighting"
609     COMPAT_ENGINES = {'BLENDER_GAME'}
610
611     @classmethod
612     def poll(cls, context):
613         scene = context.scene
614         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
615
616     def draw_header(self, context):
617         light = context.world.light_settings
618         self.layout.prop(light, "use_environment_light", text="")
619
620     def draw(self, context):
621         layout = self.layout
622
623         light = context.world.light_settings
624
625         layout.active = light.use_environment_light
626
627         split = layout.split()
628         split.prop(light, "environment_energy", text="Energy")
629         split.prop(light, "environment_color", text="")
630
631
632 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
633     bl_label = "Mist"
634     COMPAT_ENGINES = {'BLENDER_GAME'}
635
636     @classmethod
637     def poll(cls, context):
638         scene = context.scene
639         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
640
641     def draw_header(self, context):
642         world = context.world
643
644         self.layout.prop(world.mist_settings, "use_mist", text="")
645
646     def draw(self, context):
647         layout = self.layout
648
649         world = context.world
650
651         layout.active = world.mist_settings.use_mist
652
653         layout.prop(world.mist_settings, "falloff")
654
655         row = layout.row(align=True)
656         row.prop(world.mist_settings, "start")
657         row.prop(world.mist_settings, "depth")
658
659         layout.prop(world.mist_settings, "intensity", text="Minimum Intensity")
660
661
662 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
663     bl_label = "Physics"
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         gs = context.scene.game_settings
675
676         layout.prop(gs, "physics_engine", text="Engine")
677         if gs.physics_engine != 'NONE':
678             layout.prop(gs, "physics_gravity", text="Gravity")
679
680             split = layout.split()
681
682             col = split.column()
683             col.label(text="Physics Steps:")
684             sub = col.column(align=True)
685             sub.prop(gs, "physics_step_max", text="Max")
686             sub.prop(gs, "physics_step_sub", text="Substeps")
687             col.prop(gs, "fps", text="FPS")
688
689             col = split.column()
690             col.label(text="Logic Steps:")
691             col.prop(gs, "logic_step_max", text="Max")
692
693             col = layout.column()
694             col.label(text="Physics Deactivation:")
695             sub = col.row(align=True)
696             sub.prop(gs, "deactivation_linear_threshold", text="Linear Threshold")
697             sub.prop(gs, "deactivation_angular_threshold", text="Angular Threshold")
698             sub = col.row()
699             sub.prop(gs, "deactivation_time", text="Time")
700
701             col = layout.column()
702             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
703             sub = col.column()
704             sub.active = gs.use_occlusion_culling
705             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
706
707         else:
708             split = layout.split()
709
710             col = split.column()
711             col.label(text="Physics Steps:")
712             col.prop(gs, "fps", text="FPS")
713
714             col = split.column()
715             col.label(text="Logic Steps:")
716             col.prop(gs, "logic_step_max", text="Max")
717
718
719 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
720     bl_label = "Obstacle simulation"
721     COMPAT_ENGINES = {'BLENDER_GAME'}
722
723     @classmethod
724     def poll(cls, context):
725         scene = context.scene
726         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
727
728     def draw(self, context):
729         layout = self.layout
730
731         gs = context.scene.game_settings
732
733         layout.prop(gs, "obstacle_simulation", text="Type")
734         if gs.obstacle_simulation != 'NONE':
735             layout.prop(gs, "level_height")
736             layout.prop(gs, "show_obstacle_simulation")
737
738
739 class DataButtonsPanel:
740     bl_space_type = 'PROPERTIES'
741     bl_region_type = 'WINDOW'
742     bl_context = "data"
743
744
745 class DATA_PT_shadow_game(DataButtonsPanel, Panel):
746     bl_label = "Shadow"
747     COMPAT_ENGINES = {'BLENDER_GAME'}
748
749     @classmethod
750     def poll(cls, context):
751         COMPAT_LIGHTS = {'SPOT', 'SUN'}
752         lamp = context.lamp
753         engine = context.scene.render.engine
754         return (lamp and lamp.type in COMPAT_LIGHTS) and (engine in cls.COMPAT_ENGINES)
755
756     def draw_header(self, context):
757         lamp = context.lamp
758
759         self.layout.prop(lamp, "use_shadow", text="")
760
761     def draw(self, context):
762         layout = self.layout
763
764         lamp = context.lamp
765
766         layout.active = lamp.use_shadow
767
768         split = layout.split()
769
770         col = split.column()
771         col.prop(lamp, "shadow_color", text="")
772         if lamp.type == 'SUN':
773             col.prop(lamp, "show_shadow_box")
774
775         col = split.column()
776         col.prop(lamp, "use_shadow_layer", text="This Layer Only")
777         col.prop(lamp, "use_only_shadow")
778
779         col = layout.column()
780         col.label("Buffer Type:")
781         col.prop(lamp, "ge_shadow_buffer_type", text="", toggle=True)
782         col.label("Quality:")
783         col = layout.column(align=True)
784         col.prop(lamp, "shadow_buffer_size", text="Size")
785         col.prop(lamp, "shadow_buffer_bias", text="Bias")
786         col.prop(lamp, "shadow_buffer_bleed_bias", text="Bleed Bias")
787
788         row = layout.row()
789         row.label("Clipping:")
790         row = layout.row(align=True)
791         row.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
792         row.prop(lamp, "shadow_buffer_clip_end", text="Clip End")
793
794         if lamp.type == 'SUN':
795             row = layout.row()
796             row.prop(lamp, "shadow_frustum_size", text="Frustum Size")
797
798
799 class ObjectButtonsPanel:
800     bl_space_type = 'PROPERTIES'
801     bl_region_type = 'WINDOW'
802     bl_context = "object"
803
804
805 class OBJECT_MT_lod_tools(Menu):
806     bl_label = "Level Of Detail Tools"
807
808     def draw(self, context):
809         layout = self.layout
810
811         layout.operator("object.lod_by_name", text="Set By Name")
812         layout.operator("object.lod_generate", text="Generate")
813         layout.operator("object.lod_clear_all", text="Clear All", icon='PANEL_CLOSE')
814
815
816 class OBJECT_PT_levels_of_detail(ObjectButtonsPanel, Panel):
817     bl_label = "Levels of Detail"
818     COMPAT_ENGINES = {'BLENDER_GAME'}
819
820     @classmethod
821     def poll(cls, context):
822         return context.scene.render.engine in cls.COMPAT_ENGINES
823
824     def draw(self, context):
825         layout = self.layout
826         ob = context.object
827         gs = context.scene.game_settings
828
829         col = layout.column()
830
831         for i, level in enumerate(ob.lod_levels):
832             if i == 0:
833                 continue
834             box = col.box()
835             row = box.row()
836             row.prop(level, "object", text="")
837             row.operator("object.lod_remove", text="", icon='PANEL_CLOSE').index = i
838
839             row = box.row()
840             row.prop(level, "distance")
841             row = row.row(align=True)
842             row.prop(level, "use_mesh", text="")
843             row.prop(level, "use_material", text="")
844
845             row = box.row()
846             row.active = gs.use_scene_hysteresis
847             row.prop(level, "use_object_hysteresis", text="Hysteresis Override")
848             row = box.row()
849             row.active = gs.use_scene_hysteresis and level.use_object_hysteresis
850             row.prop(level, "object_hysteresis_percentage", text="")
851
852         row = col.row(align=True)
853         row.operator("object.lod_add", text="Add", icon='ZOOMIN')
854         row.menu("OBJECT_MT_lod_tools", text="", icon='TRIA_DOWN')
855
856
857 if __name__ == "__main__":  # only for live edit.
858     bpy.utils.register_module(__name__)