Merged changes in the trunk up to revision 43219.
[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             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.prop(gs, "show_fullscreen")
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
285         col = layout.column()
286         col.label(text="Quality:")
287         col = layout.column(align=True)
288         col.prop(gs, "depth", text="Bit Depth", slider=False)
289         col.prop(gs, "frequency", text="Refresh Rate", slider=False)
290
291
292 class RENDER_PT_game_stereo(RenderButtonsPanel, Panel):
293     bl_label = "Stereo"
294     COMPAT_ENGINES = {'BLENDER_GAME'}
295
296     def draw(self, context):
297         layout = self.layout
298
299         gs = context.scene.game_settings
300         stereo_mode = gs.stereo
301
302         # stereo options:
303         layout.prop(gs, "stereo", expand=True)
304
305         # stereo:
306         if stereo_mode == 'STEREO':
307             layout.prop(gs, "stereo_mode")
308             layout.prop(gs, "stereo_eye_separation")
309
310         # dome:
311         elif stereo_mode == 'DOME':
312             layout.prop(gs, "dome_mode", text="Dome Type")
313
314             dome_type = gs.dome_mode
315
316             split = layout.split()
317
318             if dome_type in {'FISHEYE', 'TRUNCATED_REAR', 'TRUNCATED_FRONT'}:
319                 col = split.column()
320
321                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
322                 col.prop(gs, "dome_angle", slider=True)
323
324                 col = split.column()
325                 col.prop(gs, "dome_tesselation", text="Tesselation")
326                 col.prop(gs, "dome_tilt")
327
328             elif dome_type == 'PANORAM_SPH':
329                 col = split.column()
330
331                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
332                 col = split.column()
333                 col.prop(gs, "dome_tesselation", text="Tesselation")
334
335             else:  # cube map
336                 col = split.column()
337
338                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
339
340                 col = split.column()
341
342             layout.prop(gs, "dome_text")
343
344
345 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
346     bl_label = "Shading"
347     COMPAT_ENGINES = {'BLENDER_GAME'}
348
349     def draw(self, context):
350         layout = self.layout
351
352         gs = context.scene.game_settings
353
354         layout.prop(gs, "material_mode", expand=True)
355
356         if gs.material_mode == 'GLSL':
357             split = layout.split()
358
359             col = split.column()
360             col.prop(gs, "use_glsl_lights", text="Lights")
361             col.prop(gs, "use_glsl_shaders", text="Shaders")
362             col.prop(gs, "use_glsl_shadows", text="Shadows")
363             col.prop(gs, "use_glsl_color_management", text="Color Management")
364
365             col = split.column()
366             col.prop(gs, "use_glsl_ramps", text="Ramps")
367             col.prop(gs, "use_glsl_nodes", text="Nodes")
368             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
369
370
371 class RENDER_PT_game_system(RenderButtonsPanel, Panel):
372     bl_label = "System"
373     COMPAT_ENGINES = {'BLENDER_GAME'}
374
375     def draw(self, context):
376         layout = self.layout
377
378         gs = context.scene.game_settings
379         row = layout.row()
380         row.prop(gs, "use_frame_rate")
381         row.prop(gs, "restrict_animation_updates")
382
383         row = layout.row()
384         row.prop(gs, "use_display_lists")
385
386         row = layout.row()
387         row.label("Exit Key")
388         row.prop(gs, "exit_key", text="", event=True)
389
390
391 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
392     bl_label = "Display"
393     COMPAT_ENGINES = {'BLENDER_GAME'}
394
395     def draw(self, context):
396         layout = self.layout
397
398         row = layout.row()
399         row.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False)
400
401         gs = context.scene.game_settings
402         flow = layout.column_flow()
403         flow.prop(gs, "show_debug_properties", text="Debug Properties")
404         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
405         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
406         flow.prop(gs, "use_deprecation_warnings")
407         flow.prop(gs, "show_mouse", text="Mouse Cursor")
408
409         col = layout.column()
410         col.label(text="Framing:")
411         col.row().prop(gs, "frame_type", expand=True)
412         if gs.frame_type == 'LETTERBOX':
413             col.prop(gs, "frame_color", text="")
414
415
416 class SceneButtonsPanel():
417     bl_space_type = 'PROPERTIES'
418     bl_region_type = 'WINDOW'
419     bl_context = "scene"
420
421
422 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
423     bl_label = "Navigation mesh"
424     bl_options = {'DEFAULT_CLOSED'}
425     COMPAT_ENGINES = {'BLENDER_GAME'}
426
427     @classmethod
428     def poll(cls, context):
429         scene = context.scene
430         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
431
432     def draw(self, context):
433         layout = self.layout
434
435         rd = context.scene.game_settings.recast_data
436
437         layout.operator("mesh.navmesh_make", text='Build navigation mesh')
438
439         col = layout.column()
440         col.label(text="Rasterization:")
441         row = col.row()
442         row.prop(rd, "cell_size")
443         row.prop(rd, "cell_height")
444
445         col = layout.column()
446         col.label(text="Agent:")
447         split = col.split()
448
449         col = split.column()
450         col.prop(rd, "agent_height", text="Height")
451         col.prop(rd, "agent_radius", text="Radius")
452
453         col = split.column()
454         col.prop(rd, "slope_max")
455         col.prop(rd, "climb_max")
456
457         col = layout.column()
458         col.label(text="Region:")
459         row = col.row()
460         row.prop(rd, "region_min_size")
461         row.prop(rd, "region_merge_size")
462
463         col = layout.column()
464         col.label(text="Polygonization:")
465         split = col.split()
466
467         col = split.column()
468         col.prop(rd, "edge_max_len")
469         col.prop(rd, "edge_max_error")
470
471         split.prop(rd, "verts_per_poly")
472
473         col = layout.column()
474         col.label(text="Detail Mesh:")
475         row = col.row()
476         row.prop(rd, "sample_dist")
477         row.prop(rd, "sample_max_error")
478
479
480 class RENDER_PT_game_sound(RenderButtonsPanel, Panel):
481     bl_label = "Sound"
482     COMPAT_ENGINES = {'BLENDER_GAME'}
483
484     def draw(self, context):
485         layout = self.layout
486
487         scene = context.scene
488
489         layout.prop(scene, "audio_distance_model")
490
491         col = layout.column(align=True)
492         col.prop(scene, "audio_doppler_speed", text="Speed")
493         col.prop(scene, "audio_doppler_factor")
494
495
496 class WorldButtonsPanel():
497     bl_space_type = 'PROPERTIES'
498     bl_region_type = 'WINDOW'
499     bl_context = "world"
500
501
502 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
503     bl_label = ""
504     bl_options = {'HIDE_HEADER'}
505     COMPAT_ENGINES = {'BLENDER_GAME'}
506
507     @classmethod
508     def poll(cls, context):
509         rd = context.scene.render
510         return (context.scene) and (rd.use_game_engine)
511
512     def draw(self, context):
513         layout = self.layout
514
515         scene = context.scene
516         world = context.world
517         space = context.space_data
518
519         split = layout.split(percentage=0.65)
520         if scene:
521             split.template_ID(scene, "world", new="world.new")
522         elif world:
523             split.template_ID(space, "pin_id")
524
525
526 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
527     bl_label = "World"
528     COMPAT_ENGINES = {'BLENDER_GAME'}
529
530     @classmethod
531     def poll(cls, context):
532         scene = context.scene
533         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
534
535     def draw(self, context):
536         layout = self.layout
537
538         world = context.world
539
540         row = layout.row()
541         row.column().prop(world, "horizon_color")
542         row.column().prop(world, "ambient_color")
543
544
545 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
546     bl_label = "Mist"
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_header(self, context):
555         world = context.world
556
557         self.layout.prop(world.mist_settings, "use_mist", text="")
558
559     def draw(self, context):
560         layout = self.layout
561
562         world = context.world
563
564         layout.active = world.mist_settings.use_mist
565         row = layout.row()
566         row.prop(world.mist_settings, "falloff")
567
568         row = layout.row(align=True)
569         row.prop(world.mist_settings, "start")
570         row.prop(world.mist_settings, "depth")
571         row = layout.row()
572         row.prop(world.mist_settings, "intensity", text="Minimum Intensity")
573
574
575 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
576     bl_label = "Physics"
577     COMPAT_ENGINES = {'BLENDER_GAME'}
578
579     @classmethod
580     def poll(cls, context):
581         scene = context.scene
582         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
583
584     def draw(self, context):
585         layout = self.layout
586
587         gs = context.scene.game_settings
588
589         layout.prop(gs, "physics_engine")
590         if gs.physics_engine != 'NONE':
591             layout.prop(gs, "physics_gravity", text="Gravity")
592
593             split = layout.split()
594
595             col = split.column()
596             col.label(text="Physics Steps:")
597             sub = col.column(align=True)
598             sub.prop(gs, "physics_step_max", text="Max")
599             sub.prop(gs, "physics_step_sub", text="Substeps")
600             col.prop(gs, "fps", text="FPS")
601
602             col = split.column()
603             col.label(text="Logic Steps:")
604             col.prop(gs, "logic_step_max", text="Max")
605
606             col = layout.column()
607             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
608             sub = col.column()
609             sub.active = gs.use_occlusion_culling
610             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
611
612         else:
613             split = layout.split()
614
615             col = split.column()
616             col.label(text="Physics Steps:")
617             col.prop(gs, "fps", text="FPS")
618
619             col = split.column()
620             col.label(text="Logic Steps:")
621             col.prop(gs, "logic_step_max", text="Max")
622
623
624 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
625     bl_label = "Obstacle simulation"
626     COMPAT_ENGINES = {'BLENDER_GAME'}
627
628     @classmethod
629     def poll(cls, context):
630         scene = context.scene
631         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
632
633     def draw(self, context):
634         layout = self.layout
635
636         gs = context.scene.game_settings
637
638         layout.prop(gs, "obstacle_simulation", text="Type")
639         if gs.obstacle_simulation != 'NONE':
640             layout.prop(gs, "level_height")
641             layout.prop(gs, "show_obstacle_simulation")
642
643 if __name__ == "__main__":  # only for live edit.
644     bpy.utils.register_module(__name__)