Merged changes in the trunk up to revision 49478.
[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                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
341                 col.prop(gs, "dome_angle", slider=True)
342
343                 col = split.column()
344                 col.prop(gs, "dome_tessellation", text="Tessellation")
345                 col.prop(gs, "dome_tilt")
346
347             elif dome_type == 'PANORAM_SPH':
348                 col = split.column()
349                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
350
351                 col = split.column()
352                 col.prop(gs, "dome_tessellation", text="Tessellation")
353
354             else:  # cube map
355                 col = split.column()
356                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
357
358                 col = split.column()
359
360             layout.prop(gs, "dome_text")
361
362
363 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
364     bl_label = "Shading"
365     COMPAT_ENGINES = {'BLENDER_GAME'}
366
367     def draw(self, context):
368         layout = self.layout
369
370         gs = context.scene.game_settings
371
372         layout.prop(gs, "material_mode", expand=True)
373
374         if gs.material_mode == 'GLSL':
375             split = layout.split()
376
377             col = split.column()
378             col.prop(gs, "use_glsl_lights", text="Lights")
379             col.prop(gs, "use_glsl_shaders", text="Shaders")
380             col.prop(gs, "use_glsl_shadows", text="Shadows")
381             col.prop(gs, "use_glsl_color_management", text="Color Management")
382
383             col = split.column()
384             col.prop(gs, "use_glsl_ramps", text="Ramps")
385             col.prop(gs, "use_glsl_nodes", text="Nodes")
386             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
387
388
389 class RENDER_PT_game_system(RenderButtonsPanel, Panel):
390     bl_label = "System"
391     COMPAT_ENGINES = {'BLENDER_GAME'}
392
393     def draw(self, context):
394         layout = self.layout
395
396         gs = context.scene.game_settings
397
398         row = layout.row()
399         row.prop(gs, "use_frame_rate")
400         row.prop(gs, "restrict_animation_updates")
401
402         row = layout.row()
403         row.prop(gs, "use_display_lists")
404
405         row = layout.row()
406         row.label("Exit Key")
407         row.prop(gs, "exit_key", text="", event=True)
408
409
410 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
411     bl_label = "Display"
412     COMPAT_ENGINES = {'BLENDER_GAME'}
413
414     def draw(self, context):
415         layout = self.layout
416
417         gs = context.scene.game_settings
418
419         layout.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
420
421         flow = layout.column_flow()
422         flow.prop(gs, "show_debug_properties", text="Debug Properties")
423         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
424         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
425         flow.prop(gs, "use_deprecation_warnings")
426         flow.prop(gs, "show_mouse", text="Mouse Cursor")
427
428         col = layout.column()
429         col.label(text="Framing:")
430         col.row().prop(gs, "frame_type", expand=True)
431         if gs.frame_type == 'LETTERBOX':
432             col.prop(gs, "frame_color", text="")
433
434
435 class SceneButtonsPanel():
436     bl_space_type = 'PROPERTIES'
437     bl_region_type = 'WINDOW'
438     bl_context = "scene"
439
440
441 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
442     bl_label = "Navigation mesh"
443     bl_options = {'DEFAULT_CLOSED'}
444     COMPAT_ENGINES = {'BLENDER_GAME'}
445
446     @classmethod
447     def poll(cls, context):
448         scene = context.scene
449         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
450
451     def draw(self, context):
452         layout = self.layout
453
454         rd = context.scene.game_settings.recast_data
455
456         layout.operator("mesh.navmesh_make", text="Build navigation mesh")
457
458         col = layout.column()
459         col.label(text="Rasterization:")
460         row = col.row()
461         row.prop(rd, "cell_size")
462         row.prop(rd, "cell_height")
463
464         col = layout.column()
465         col.label(text="Agent:")
466         split = col.split()
467
468         col = split.column()
469         col.prop(rd, "agent_height", text="Height")
470         col.prop(rd, "agent_radius", text="Radius")
471
472         col = split.column()
473         col.prop(rd, "slope_max")
474         col.prop(rd, "climb_max")
475
476         col = layout.column()
477         col.label(text="Region:")
478         row = col.row()
479         row.prop(rd, "region_min_size")
480         row.prop(rd, "region_merge_size")
481
482         col = layout.column()
483         col.label(text="Polygonization:")
484         split = col.split()
485
486         col = split.column()
487         col.prop(rd, "edge_max_len")
488         col.prop(rd, "edge_max_error")
489
490         split.prop(rd, "verts_per_poly")
491
492         col = layout.column()
493         col.label(text="Detail Mesh:")
494         row = col.row()
495         row.prop(rd, "sample_dist")
496         row.prop(rd, "sample_max_error")
497
498
499 class RENDER_PT_game_sound(RenderButtonsPanel, Panel):
500     bl_label = "Sound"
501     COMPAT_ENGINES = {'BLENDER_GAME'}
502
503     def draw(self, context):
504         layout = self.layout
505
506         scene = context.scene
507
508         layout.prop(scene, "audio_distance_model")
509
510         col = layout.column(align=True)
511         col.prop(scene, "audio_doppler_speed", text="Speed")
512         col.prop(scene, "audio_doppler_factor")
513
514
515 class WorldButtonsPanel():
516     bl_space_type = 'PROPERTIES'
517     bl_region_type = 'WINDOW'
518     bl_context = "world"
519
520
521 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
522     bl_label = ""
523     bl_options = {'HIDE_HEADER'}
524     COMPAT_ENGINES = {'BLENDER_GAME'}
525
526     @classmethod
527     def poll(cls, context):
528         rd = context.scene.render
529         return (context.scene) and (rd.use_game_engine)
530
531     def draw(self, context):
532         layout = self.layout
533
534         scene = context.scene
535         world = context.world
536         space = context.space_data
537
538         split = layout.split(percentage=0.65)
539         if scene:
540             split.template_ID(scene, "world", new="world.new")
541         elif world:
542             split.template_ID(space, "pin_id")
543
544
545 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
546     bl_label = "World"
547     COMPAT_ENGINES = {'BLENDER_GAME'}
548
549     @classmethod
550     def poll(cls, context):
551         scene = context.scene
552         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
553
554     def draw(self, context):
555         layout = self.layout
556
557         world = context.world
558
559         row = layout.row()
560         row.column().prop(world, "horizon_color")
561         row.column().prop(world, "ambient_color")
562
563
564 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
565     bl_label = "Mist"
566     COMPAT_ENGINES = {'BLENDER_GAME'}
567
568     @classmethod
569     def poll(cls, context):
570         scene = context.scene
571         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
572
573     def draw_header(self, context):
574         world = context.world
575
576         self.layout.prop(world.mist_settings, "use_mist", text="")
577
578     def draw(self, context):
579         layout = self.layout
580
581         world = context.world
582
583         layout.active = world.mist_settings.use_mist
584
585         layout.prop(world.mist_settings, "falloff")
586
587         row = layout.row(align=True)
588         row.prop(world.mist_settings, "start")
589         row.prop(world.mist_settings, "depth")
590
591         layout.prop(world.mist_settings, "intensity", text="Minimum Intensity")
592
593
594 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
595     bl_label = "Physics"
596     COMPAT_ENGINES = {'BLENDER_GAME'}
597
598     @classmethod
599     def poll(cls, context):
600         scene = context.scene
601         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
602
603     def draw(self, context):
604         layout = self.layout
605
606         gs = context.scene.game_settings
607
608         layout.prop(gs, "physics_engine")
609         if gs.physics_engine != 'NONE':
610             layout.prop(gs, "physics_gravity", text="Gravity")
611
612             split = layout.split()
613
614             col = split.column()
615             col.label(text="Physics Steps:")
616             sub = col.column(align=True)
617             sub.prop(gs, "physics_step_max", text="Max")
618             sub.prop(gs, "physics_step_sub", text="Substeps")
619             col.prop(gs, "fps", text="FPS")
620
621             col = split.column()
622             col.label(text="Logic Steps:")
623             col.prop(gs, "logic_step_max", text="Max")
624
625             col = layout.column()
626             col.label(text="Physics Deactivation:")
627             sub = col.row(align=True)
628             sub.prop(gs, "deactivation_linear_threshold", text="Linear Threshold")
629             sub.prop(gs, "deactivation_angular_threshold", text="Angular Threshold")
630             sub = col.row()
631             sub.prop(gs, "deactivation_time", text="Time")
632
633             col = layout.column()
634             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
635             sub = col.column()
636             sub.active = gs.use_occlusion_culling
637             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
638
639         else:
640             split = layout.split()
641
642             col = split.column()
643             col.label(text="Physics Steps:")
644             col.prop(gs, "fps", text="FPS")
645
646             col = split.column()
647             col.label(text="Logic Steps:")
648             col.prop(gs, "logic_step_max", text="Max")
649
650
651 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
652     bl_label = "Obstacle simulation"
653     COMPAT_ENGINES = {'BLENDER_GAME'}
654
655     @classmethod
656     def poll(cls, context):
657         scene = context.scene
658         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
659
660     def draw(self, context):
661         layout = self.layout
662
663         gs = context.scene.game_settings
664
665         layout.prop(gs, "obstacle_simulation", text="Type")
666         if gs.obstacle_simulation != 'NONE':
667             layout.prop(gs, "level_height")
668             layout.prop(gs, "show_obstacle_simulation")
669
670
671 class DataButtonsPanel():
672     bl_space_type = 'PROPERTIES'
673     bl_region_type = 'WINDOW'
674     bl_context = "data"
675
676
677 class DATA_PT_shadow_game(DataButtonsPanel, Panel):
678     bl_label = "Shadow"
679     COMPAT_ENGINES = {'BLENDER_GAME'}
680
681     @classmethod
682     def poll(cls, context):
683         COMPAT_LIGHTS = {'SPOT', 'SUN'}
684         lamp = context.lamp
685         engine = context.scene.render.engine
686         return (lamp and lamp.type in COMPAT_LIGHTS) and (engine in cls.COMPAT_ENGINES)
687
688     def draw_header(self, context):
689         lamp = context.lamp
690
691         self.layout.prop(lamp, "use_shadow", text="")
692
693     def draw(self, context):
694         layout = self.layout
695
696         lamp = context.lamp
697
698         layout.active = lamp.use_shadow
699
700         split = layout.split()
701
702         col = split.column()
703         col.prop(lamp, "shadow_color", text="")
704
705         col = split.column()
706         col.prop(lamp, "use_shadow_layer", text="This Layer Only")
707         col.prop(lamp, "use_only_shadow")
708
709         col = layout.column()
710         col.label("Buffer Type:")
711         col.prop(lamp, "ge_shadow_buffer_type", text="", toggle=True)
712         col.label("Quality:")
713         col = layout.column(align=True)
714         col.prop(lamp, "shadow_buffer_size", text="Size")
715         col.prop(lamp, "shadow_buffer_bias", text="Bias")
716         col.prop(lamp, "shadow_buffer_bleed_bias", text="Bleed Bias")
717
718         row = layout.row()
719         row.label("Clipping:")
720         row = layout.row(align=True)
721         row.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
722         row.prop(lamp, "shadow_buffer_clip_end", text="Clip End")
723
724         if lamp.type == 'SUN':
725             row = layout.row()
726             row.prop(lamp, "shadow_frustum_size", text="Frustum Size")
727
728
729 if __name__ == "__main__":  # only for live edit.
730     bpy.utils.register_module(__name__)