Merged changes in the trunk up to revision 43404.
[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 in {'DYNAMIC', 'RIGID_BODY'}:
53             split = layout.split()
54
55             col = split.column()
56             col.prop(game, "use_actor")
57             col.prop(game, "use_ghost")
58             col.prop(ob, "hide_render", text="Invisible")  # out of place but useful
59
60             col = split.column()
61             col.prop(game, "use_material_physics_fh")
62             col.prop(game, "use_rotate_from_normal")
63             col.prop(game, "use_sleep")
64
65             layout.separator()
66
67             split = layout.split()
68
69             col = split.column()
70             col.label(text="Attributes:")
71             col.prop(game, "mass")
72             col.prop(game, "radius")
73             col.prop(game, "form_factor")
74
75             col = split.column()
76             sub = col.column()
77             sub.prop(game, "use_anisotropic_friction")
78             subsub = sub.column()
79             subsub.active = game.use_anisotropic_friction
80             subsub.prop(game, "friction_coefficients", text="", slider=True)
81
82             split = layout.split()
83
84             col = split.column()
85             col.label(text="Velocity:")
86             sub = col.column(align=True)
87             sub.prop(game, "velocity_min", text="Minimum")
88             sub.prop(game, "velocity_max", text="Maximum")
89
90             col = split.column()
91             col.label(text="Damping:")
92             sub = col.column(align=True)
93             sub.prop(game, "damping", text="Translation", slider=True)
94             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
95
96             layout.separator()
97
98             split = layout.split()
99
100             col = split.column()
101             col.label(text="Lock Translation:")
102             col.prop(game, "lock_location_x", text="X")
103             col.prop(game, "lock_location_y", text="Y")
104             col.prop(game, "lock_location_z", text="Z")
105
106             col = split.column()
107             col.label(text="Lock Rotation:")
108             col.prop(game, "lock_rotation_x", text="X")
109             col.prop(game, "lock_rotation_y", text="Y")
110             col.prop(game, "lock_rotation_z", text="Z")
111
112         elif physics_type == 'SOFT_BODY':
113             col = layout.column()
114             col.prop(game, "use_actor")
115             col.prop(game, "use_ghost")
116             col.prop(ob, "hide_render", text="Invisible")
117
118             layout.separator()
119
120             split = layout.split()
121
122             col = split.column()
123             col.label(text="Attributes:")
124             col.prop(game, "mass")
125             col.prop(soft, "weld_threshold")
126             col.prop(soft, "location_iterations")
127             col.prop(soft, "linear_stiffness", slider=True)
128             col.prop(soft, "dynamic_friction", slider=True)
129             col.prop(soft, "collision_margin", slider=True)
130             col.prop(soft, "use_bending_constraints", text="Bending Constraints")
131
132             col = split.column()
133             col.prop(soft, "use_shape_match")
134             sub = col.column()
135             sub.active = soft.use_shape_match
136             sub.prop(soft, "shape_threshold", slider=True)
137
138             col.separator()
139
140             col.label(text="Cluster Collision:")
141             col.prop(soft, "use_cluster_rigid_to_softbody")
142             col.prop(soft, "use_cluster_soft_to_softbody")
143             sub = col.column()
144             sub.active = (soft.use_cluster_rigid_to_softbody or soft.use_cluster_soft_to_softbody)
145             sub.prop(soft, "cluster_iterations", text="Iterations")
146
147         elif physics_type == 'STATIC':
148             col = layout.column()
149             col.prop(game, "use_actor")
150             col.prop(game, "use_ghost")
151             col.prop(ob, "hide_render", text="Invisible")
152
153             layout.separator()
154
155             split = layout.split()
156
157             col = split.column()
158             col.label(text="Attributes:")
159             col.prop(game, "radius")
160
161             col = split.column()
162             sub = col.column()
163             sub.prop(game, "use_anisotropic_friction")
164             subsub = sub.column()
165             subsub.active = game.use_anisotropic_friction
166             subsub.prop(game, "friction_coefficients", text="", slider=True)
167
168         elif physics_type in {'SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'}:
169             layout.prop(ob, "hide_render", text="Invisible")
170
171         elif physics_type == 'NAVMESH':
172             layout.operator("mesh.navmesh_face_copy")
173             layout.operator("mesh.navmesh_face_add")
174
175             layout.separator()
176
177             layout.operator("mesh.navmesh_reset")
178             layout.operator("mesh.navmesh_clear")
179
180
181 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, Panel):
182     bl_label = "Collision Bounds"
183     COMPAT_ENGINES = {'BLENDER_GAME'}
184
185     @classmethod
186     def poll(cls, context):
187         game = context.object.game
188         rd = context.scene.render
189         return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES)
190
191     def draw_header(self, context):
192         game = context.active_object.game
193
194         self.layout.prop(game, "use_collision_bounds", text="")
195
196     def draw(self, context):
197         layout = self.layout
198
199         game = context.active_object.game
200
201         layout.active = game.use_collision_bounds
202         layout.prop(game, "collision_bounds_type", text="Bounds")
203
204         row = layout.row()
205         row.prop(game, "collision_margin", text="Margin", slider=True)
206         row.prop(game, "use_collision_compound", text="Compound")
207
208
209 class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, Panel):
210     bl_label = "Create Obstacle"
211     COMPAT_ENGINES = {'BLENDER_GAME'}
212
213     @classmethod
214     def poll(cls, context):
215         game = context.object.game
216         rd = context.scene.render
217         return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES)
218
219     def draw_header(self, context):
220         game = context.active_object.game
221
222         self.layout.prop(game, "use_obstacle_create", text="")
223
224     def draw(self, context):
225         layout = self.layout
226
227         game = context.active_object.game
228
229         layout.active = game.use_obstacle_create
230
231         row = layout.row()
232         row.prop(game, "obstacle_radius", text="Radius")
233         row.label()
234
235
236 class RenderButtonsPanel():
237     bl_space_type = 'PROPERTIES'
238     bl_region_type = 'WINDOW'
239     bl_context = "render"
240
241     @classmethod
242     def poll(cls, context):
243         rd = context.scene.render
244         return (rd.engine in cls.COMPAT_ENGINES)
245
246
247 class RENDER_PT_embedded(RenderButtonsPanel, bpy.types.Panel):
248     bl_label = "Embedded Player"
249     COMPAT_ENGINES = {'BLENDER_GAME'}
250
251     def draw(self, context):
252         layout = self.layout
253
254         rd = context.scene.render
255
256         row = layout.row()
257         row.operator("view3d.game_start", text="Start")
258         row.label()
259         row = layout.row()
260         row.label(text="Resolution:")
261         row = layout.row(align=True)
262         row.prop(rd, "resolution_x", slider=False, text="X")
263         row.prop(rd, "resolution_y", slider=False, text="Y")
264
265
266 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
267     bl_label = "Standalone Player"
268     COMPAT_ENGINES = {'BLENDER_GAME'}
269
270     def draw(self, context):
271         layout = self.layout
272
273         gs = context.scene.game_settings
274
275         row = layout.row()
276         row.operator("wm.blenderplayer_start", text="Start")
277         row.label()
278
279         row = layout.row()
280         row.label(text="Resolution:")
281         row = layout.row(align=True)
282         row.prop(gs, "resolution_x", slider=False, text="X")
283         row.prop(gs, "resolution_y", slider=False, text="Y")
284         row = layout.row()
285         col = row.column()
286         col.prop(gs, "show_fullscreen")
287         col = row.column()
288         col.prop(gs, "use_desktop")
289         col.active = gs.show_fullscreen
290         
291         col = layout.column()
292         col.label(text="Quality:")
293         col.prop(gs, "samples")
294         col = layout.column(align=True)
295         col.prop(gs, "depth", text="Bit Depth", slider=False)
296         col.prop(gs, "frequency", text="Refresh Rate", slider=False)
297
298
299 class RENDER_PT_game_stereo(RenderButtonsPanel, Panel):
300     bl_label = "Stereo"
301     COMPAT_ENGINES = {'BLENDER_GAME'}
302
303     def draw(self, context):
304         layout = self.layout
305
306         gs = context.scene.game_settings
307         stereo_mode = gs.stereo
308
309         # stereo options:
310         layout.prop(gs, "stereo", expand=True)
311
312         # stereo:
313         if stereo_mode == 'STEREO':
314             layout.prop(gs, "stereo_mode")
315             layout.prop(gs, "stereo_eye_separation")
316
317         # dome:
318         elif stereo_mode == 'DOME':
319             layout.prop(gs, "dome_mode", text="Dome Type")
320
321             dome_type = gs.dome_mode
322
323             split = layout.split()
324
325             if dome_type in {'FISHEYE', 'TRUNCATED_REAR', 'TRUNCATED_FRONT'}:
326                 col = split.column()
327
328                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
329                 col.prop(gs, "dome_angle", slider=True)
330
331                 col = split.column()
332                 col.prop(gs, "dome_tesselation", text="Tesselation")
333                 col.prop(gs, "dome_tilt")
334
335             elif dome_type == 'PANORAM_SPH':
336                 col = split.column()
337
338                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
339                 col = split.column()
340                 col.prop(gs, "dome_tesselation", text="Tesselation")
341
342             else:  # cube map
343                 col = split.column()
344
345                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
346
347                 col = split.column()
348
349             layout.prop(gs, "dome_text")
350
351
352 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
353     bl_label = "Shading"
354     COMPAT_ENGINES = {'BLENDER_GAME'}
355
356     def draw(self, context):
357         layout = self.layout
358
359         gs = context.scene.game_settings
360
361         layout.prop(gs, "material_mode", expand=True)
362
363         if gs.material_mode == 'GLSL':
364             split = layout.split()
365
366             col = split.column()
367             col.prop(gs, "use_glsl_lights", text="Lights")
368             col.prop(gs, "use_glsl_shaders", text="Shaders")
369             col.prop(gs, "use_glsl_shadows", text="Shadows")
370             col.prop(gs, "use_glsl_color_management", text="Color Management")
371
372             col = split.column()
373             col.prop(gs, "use_glsl_ramps", text="Ramps")
374             col.prop(gs, "use_glsl_nodes", text="Nodes")
375             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
376
377
378 class RENDER_PT_game_system(RenderButtonsPanel, Panel):
379     bl_label = "System"
380     COMPAT_ENGINES = {'BLENDER_GAME'}
381
382     def draw(self, context):
383         layout = self.layout
384
385         gs = context.scene.game_settings
386         row = layout.row()
387         row.prop(gs, "use_frame_rate")
388         row.prop(gs, "restrict_animation_updates")
389
390         row = layout.row()
391         row.prop(gs, "use_display_lists")
392
393         row = layout.row()
394         row.label("Exit Key")
395         row.prop(gs, "exit_key", text="", event=True)
396
397
398 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
399     bl_label = "Display"
400     COMPAT_ENGINES = {'BLENDER_GAME'}
401
402     def draw(self, context):
403         layout = self.layout
404
405         row = layout.row()
406         row.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
407
408         gs = context.scene.game_settings
409         flow = layout.column_flow()
410         flow.prop(gs, "show_debug_properties", text="Debug Properties")
411         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
412         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
413         flow.prop(gs, "use_deprecation_warnings")
414         flow.prop(gs, "show_mouse", text="Mouse Cursor")
415
416         col = layout.column()
417         col.label(text="Framing:")
418         col.row().prop(gs, "frame_type", expand=True)
419         if gs.frame_type == 'LETTERBOX':
420             col.prop(gs, "frame_color", text="")
421
422
423 class SceneButtonsPanel():
424     bl_space_type = 'PROPERTIES'
425     bl_region_type = 'WINDOW'
426     bl_context = "scene"
427
428
429 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
430     bl_label = "Navigation mesh"
431     bl_options = {'DEFAULT_CLOSED'}
432     COMPAT_ENGINES = {'BLENDER_GAME'}
433
434     @classmethod
435     def poll(cls, context):
436         scene = context.scene
437         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
438
439     def draw(self, context):
440         layout = self.layout
441
442         rd = context.scene.game_settings.recast_data
443
444         layout.operator("mesh.navmesh_make", text='Build navigation mesh')
445
446         col = layout.column()
447         col.label(text="Rasterization:")
448         row = col.row()
449         row.prop(rd, "cell_size")
450         row.prop(rd, "cell_height")
451
452         col = layout.column()
453         col.label(text="Agent:")
454         split = col.split()
455
456         col = split.column()
457         col.prop(rd, "agent_height", text="Height")
458         col.prop(rd, "agent_radius", text="Radius")
459
460         col = split.column()
461         col.prop(rd, "slope_max")
462         col.prop(rd, "climb_max")
463
464         col = layout.column()
465         col.label(text="Region:")
466         row = col.row()
467         row.prop(rd, "region_min_size")
468         row.prop(rd, "region_merge_size")
469
470         col = layout.column()
471         col.label(text="Polygonization:")
472         split = col.split()
473
474         col = split.column()
475         col.prop(rd, "edge_max_len")
476         col.prop(rd, "edge_max_error")
477
478         split.prop(rd, "verts_per_poly")
479
480         col = layout.column()
481         col.label(text="Detail Mesh:")
482         row = col.row()
483         row.prop(rd, "sample_dist")
484         row.prop(rd, "sample_max_error")
485
486
487 class RENDER_PT_game_sound(RenderButtonsPanel, Panel):
488     bl_label = "Sound"
489     COMPAT_ENGINES = {'BLENDER_GAME'}
490
491     def draw(self, context):
492         layout = self.layout
493
494         scene = context.scene
495
496         layout.prop(scene, "audio_distance_model")
497
498         col = layout.column(align=True)
499         col.prop(scene, "audio_doppler_speed", text="Speed")
500         col.prop(scene, "audio_doppler_factor")
501
502
503 class WorldButtonsPanel():
504     bl_space_type = 'PROPERTIES'
505     bl_region_type = 'WINDOW'
506     bl_context = "world"
507
508
509 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
510     bl_label = ""
511     bl_options = {'HIDE_HEADER'}
512     COMPAT_ENGINES = {'BLENDER_GAME'}
513
514     @classmethod
515     def poll(cls, context):
516         rd = context.scene.render
517         return (context.scene) and (rd.use_game_engine)
518
519     def draw(self, context):
520         layout = self.layout
521
522         scene = context.scene
523         world = context.world
524         space = context.space_data
525
526         split = layout.split(percentage=0.65)
527         if scene:
528             split.template_ID(scene, "world", new="world.new")
529         elif world:
530             split.template_ID(space, "pin_id")
531
532
533 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
534     bl_label = "World"
535     COMPAT_ENGINES = {'BLENDER_GAME'}
536
537     @classmethod
538     def poll(cls, context):
539         scene = context.scene
540         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
541
542     def draw(self, context):
543         layout = self.layout
544
545         world = context.world
546
547         row = layout.row()
548         row.column().prop(world, "horizon_color")
549         row.column().prop(world, "ambient_color")
550
551
552 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
553     bl_label = "Mist"
554     COMPAT_ENGINES = {'BLENDER_GAME'}
555
556     @classmethod
557     def poll(cls, context):
558         scene = context.scene
559         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
560
561     def draw_header(self, context):
562         world = context.world
563
564         self.layout.prop(world.mist_settings, "use_mist", text="")
565
566     def draw(self, context):
567         layout = self.layout
568
569         world = context.world
570
571         layout.active = world.mist_settings.use_mist
572         row = layout.row()
573         row.prop(world.mist_settings, "falloff")
574
575         row = layout.row(align=True)
576         row.prop(world.mist_settings, "start")
577         row.prop(world.mist_settings, "depth")
578         row = layout.row()
579         row.prop(world.mist_settings, "intensity", text="Minimum Intensity")
580
581
582 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
583     bl_label = "Physics"
584     COMPAT_ENGINES = {'BLENDER_GAME'}
585
586     @classmethod
587     def poll(cls, context):
588         scene = context.scene
589         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
590
591     def draw(self, context):
592         layout = self.layout
593
594         gs = context.scene.game_settings
595
596         layout.prop(gs, "physics_engine")
597         if gs.physics_engine != 'NONE':
598             layout.prop(gs, "physics_gravity", text="Gravity")
599
600             split = layout.split()
601
602             col = split.column()
603             col.label(text="Physics Steps:")
604             sub = col.column(align=True)
605             sub.prop(gs, "physics_step_max", text="Max")
606             sub.prop(gs, "physics_step_sub", text="Substeps")
607             col.prop(gs, "fps", text="FPS")
608
609             col = split.column()
610             col.label(text="Logic Steps:")
611             col.prop(gs, "logic_step_max", text="Max")
612
613             col = layout.column()
614             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
615             sub = col.column()
616             sub.active = gs.use_occlusion_culling
617             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
618
619         else:
620             split = layout.split()
621
622             col = split.column()
623             col.label(text="Physics Steps:")
624             col.prop(gs, "fps", text="FPS")
625
626             col = split.column()
627             col.label(text="Logic Steps:")
628             col.prop(gs, "logic_step_max", text="Max")
629
630
631 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
632     bl_label = "Obstacle simulation"
633     COMPAT_ENGINES = {'BLENDER_GAME'}
634
635     @classmethod
636     def poll(cls, context):
637         scene = context.scene
638         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
639
640     def draw(self, context):
641         layout = self.layout
642
643         gs = context.scene.game_settings
644
645         layout.prop(gs, "obstacle_simulation", text="Type")
646         if gs.obstacle_simulation != 'NONE':
647             layout.prop(gs, "level_height")
648             layout.prop(gs, "show_obstacle_simulation")
649
650 if __name__ == "__main__":  # only for live edit.
651     bpy.utils.register_module(__name__)