355a6771022b554f2f40020fbec2f86713dd444d
[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     def draw(self, context):
251         layout = self.layout
252
253         rd = context.scene.render
254
255         row = layout.row()
256         row.operator("view3d.game_start", text="Start")
257         row.label()
258         row = layout.row()
259         row.label(text="Resolution:")
260         row = layout.row(align=True)
261         row.prop(rd, "resolution_x", slider=False, text="X")
262         row.prop(rd, "resolution_y", slider=False, text="Y")
263
264
265 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
266     bl_label = "Standalone Player"
267     COMPAT_ENGINES = {'BLENDER_GAME'}
268
269     def draw(self, context):
270         layout = self.layout
271
272         gs = context.scene.game_settings
273         
274         row = layout.row()
275         row.operator("wm.blenderplayer_start", text="Start")
276         row.prop(gs, "show_fullscreen")
277         
278         row = layout.row()
279         row.label(text="Resolution:")
280         row = layout.row(align=True)
281         row.prop(gs, "resolution_x", slider=False, text="X")
282         row.prop(gs, "resolution_y", slider=False, text="Y")
283         
284         col = layout.column()
285         col.label(text="Quality:")
286         col = layout.column(align=True)
287         col.prop(gs, "depth", text="Bit Depth", slider=False)
288         col.prop(gs, "frequency", text="Refresh Rate", slider=False)
289
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 class RENDER_PT_game_sound(RenderButtonsPanel, Panel):
480     bl_label = "Sound"
481     COMPAT_ENGINES = {'BLENDER_GAME'}
482
483     def draw(self, context):
484         layout = self.layout
485
486         scene = context.scene
487
488         layout.prop(scene, "audio_distance_model")
489
490         col = layout.column(align=True)
491         col.prop(scene, "audio_doppler_speed", text="Speed")
492         col.prop(scene, "audio_doppler_factor")
493
494 class WorldButtonsPanel():
495     bl_space_type = 'PROPERTIES'
496     bl_region_type = 'WINDOW'
497     bl_context = "world"
498
499
500 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
501     bl_label = ""
502     bl_options = {'HIDE_HEADER'}
503     COMPAT_ENGINES = {'BLENDER_GAME'}
504
505     @classmethod
506     def poll(cls, context):
507         rd = context.scene.render
508         return (context.scene) and (rd.use_game_engine)
509
510     def draw(self, context):
511         layout = self.layout
512
513         scene = context.scene
514         world = context.world
515         space = context.space_data
516
517         split = layout.split(percentage=0.65)
518         if scene:
519             split.template_ID(scene, "world", new="world.new")
520         elif world:
521             split.template_ID(space, "pin_id")
522
523
524 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
525     bl_label = "World"
526     COMPAT_ENGINES = {'BLENDER_GAME'}
527
528     @classmethod
529     def poll(cls, context):
530         scene = context.scene
531         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
532
533     def draw(self, context):
534         layout = self.layout
535
536         world = context.world
537
538         row = layout.row()
539         row.column().prop(world, "horizon_color")
540         row.column().prop(world, "ambient_color")
541
542
543 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
544     bl_label = "Mist"
545     COMPAT_ENGINES = {'BLENDER_GAME'}
546
547     @classmethod
548     def poll(cls, context):
549         scene = context.scene
550         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
551
552     def draw_header(self, context):
553         world = context.world
554
555         self.layout.prop(world.mist_settings, "use_mist", text="")
556
557     def draw(self, context):
558         layout = self.layout
559
560         world = context.world
561
562         layout.active = world.mist_settings.use_mist
563         row = layout.row()
564         row.prop(world.mist_settings, "falloff")
565
566         row = layout.row(align=True)
567         row.prop(world.mist_settings, "start")
568         row.prop(world.mist_settings, "depth")
569         row = layout.row()
570         row.prop(world.mist_settings, "intensity", text="Minimum Intensity")
571
572
573 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
574     bl_label = "Physics"
575     COMPAT_ENGINES = {'BLENDER_GAME'}
576
577     @classmethod
578     def poll(cls, context):
579         scene = context.scene
580         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
581
582     def draw(self, context):
583         layout = self.layout
584
585         gs = context.scene.game_settings
586
587         layout.prop(gs, "physics_engine")
588         if gs.physics_engine != 'NONE':
589             layout.prop(gs, "physics_gravity", text="Gravity")
590
591             split = layout.split()
592
593             col = split.column()
594             col.label(text="Physics Steps:")
595             sub = col.column(align=True)
596             sub.prop(gs, "physics_step_max", text="Max")
597             sub.prop(gs, "physics_step_sub", text="Substeps")
598             col.prop(gs, "fps", text="FPS")
599
600             col = split.column()
601             col.label(text="Logic Steps:")
602             col.prop(gs, "logic_step_max", text="Max")
603
604             col = layout.column()
605             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
606             sub = col.column()
607             sub.active = gs.use_occlusion_culling
608             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
609
610         else:
611             split = layout.split()
612
613             col = split.column()
614             col.label(text="Physics Steps:")
615             col.prop(gs, "fps", text="FPS")
616
617             col = split.column()
618             col.label(text="Logic Steps:")
619             col.prop(gs, "logic_step_max", text="Max")
620
621
622 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
623     bl_label = "Obstacle simulation"
624     COMPAT_ENGINES = {'BLENDER_GAME'}
625
626     @classmethod
627     def poll(cls, context):
628         scene = context.scene
629         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
630
631     def draw(self, context):
632         layout = self.layout
633
634         gs = context.scene.game_settings
635
636         layout.prop(gs, "obstacle_simulation", text="Type")
637         if gs.obstacle_simulation != 'NONE':
638             layout.prop(gs, "level_height")
639             layout.prop(gs, "show_obstacle_simulation")
640
641 if __name__ == "__main__":  # only for live edit.
642     bpy.utils.register_module(__name__)