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