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