5e33e605be98a50abbb7b4195e367c7fa682f64a
[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_game(RenderButtonsPanel, Panel):
248     bl_label = "Game"
249     COMPAT_ENGINES = {'BLENDER_GAME'}
250
251     def draw(self, context):
252         layout = self.layout
253
254         row = layout.row()
255         row.operator("view3d.game_start", text="Start")
256         row.label()
257
258
259 class RENDER_PT_game_player(RenderButtonsPanel, Panel):
260     bl_label = "Standalone Player"
261     COMPAT_ENGINES = {'BLENDER_GAME'}
262
263     def draw(self, context):
264         layout = self.layout
265
266         gs = context.scene.game_settings
267
268         layout.prop(gs, "show_fullscreen")
269
270         split = layout.split()
271
272         col = split.column()
273         col.label(text="Resolution:")
274         sub = col.column(align=True)
275         sub.prop(gs, "resolution_x", slider=False, text="X")
276         sub.prop(gs, "resolution_y", slider=False, text="Y")
277
278         col = split.column()
279         col.label(text="Quality:")
280         sub = col.column(align=True)
281         sub.prop(gs, "depth", text="Bit Depth", slider=False)
282         sub.prop(gs, "frequency", text="FPS", slider=False)
283
284         # framing:
285         col = layout.column()
286         col.label(text="Framing:")
287         col.row().prop(gs, "frame_type", expand=True)
288         if gs.frame_type == 'LETTERBOX':
289             col.prop(gs, "frame_color", text="")
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 == 'FISHEYE' or \
319                dome_type == 'TRUNCATED_REAR' or \
320                dome_type == 'TRUNCATED_FRONT':
321
322                 col = split.column()
323                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
324                 col.prop(gs, "dome_angle", slider=True)
325
326                 col = split.column()
327                 col.prop(gs, "dome_tesselation", text="Tesselation")
328                 col.prop(gs, "dome_tilt")
329
330             elif dome_type == 'PANORAM_SPH':
331                 col = split.column()
332
333                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
334                 col = split.column()
335                 col.prop(gs, "dome_tesselation", text="Tesselation")
336
337             else:  # cube map
338                 col = split.column()
339                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
340
341                 col = split.column()
342
343             layout.prop(gs, "dome_text")
344
345
346 class RENDER_PT_game_shading(RenderButtonsPanel, Panel):
347     bl_label = "Shading"
348     COMPAT_ENGINES = {'BLENDER_GAME'}
349
350     def draw(self, context):
351         layout = self.layout
352
353         gs = context.scene.game_settings
354
355         layout.prop(gs, "material_mode", expand=True)
356
357         if gs.material_mode == 'GLSL':
358             split = layout.split()
359
360             col = split.column()
361             col.prop(gs, "use_glsl_lights", text="Lights")
362             col.prop(gs, "use_glsl_shaders", text="Shaders")
363             col.prop(gs, "use_glsl_shadows", text="Shadows")
364             col.prop(gs, "use_glsl_color_management", text="Color Management")
365
366             col = split.column()
367             col.prop(gs, "use_glsl_ramps", text="Ramps")
368             col.prop(gs, "use_glsl_nodes", text="Nodes")
369             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
370
371
372 class RENDER_PT_game_performance(RenderButtonsPanel, Panel):
373     bl_label = "Performance"
374     COMPAT_ENGINES = {'BLENDER_GAME'}
375
376     def draw(self, context):
377         layout = self.layout
378
379         gs = context.scene.game_settings
380         col = layout.column()
381         row = col.row()
382         row.prop(gs, "use_frame_rate")
383         row.prop(gs, "use_display_lists")
384
385         col.prop(gs, "restrict_animation_updates")
386
387
388 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
389     bl_label = "Display"
390     COMPAT_ENGINES = {'BLENDER_GAME'}
391
392     def draw(self, context):
393         layout = self.layout
394
395         gs = context.scene.game_settings
396         flow = layout.column_flow()
397         flow.prop(gs, "show_debug_properties", text="Debug Properties")
398         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
399         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
400         flow.prop(gs, "use_deprecation_warnings")
401         flow.prop(gs, "show_mouse", text="Mouse Cursor")
402
403
404 class SceneButtonsPanel():
405     bl_space_type = 'PROPERTIES'
406     bl_region_type = 'WINDOW'
407     bl_context = "scene"
408
409
410 class SCENE_PT_game_navmesh(SceneButtonsPanel, bpy.types.Panel):
411     bl_label = "Navigation mesh"
412     bl_default_closed = True
413     COMPAT_ENGINES = {'BLENDER_GAME'}
414
415     @classmethod
416     def poll(cls, context):
417         scene = context.scene
418         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
419
420     def draw(self, context):
421         layout = self.layout
422
423         rd = context.scene.game_settings.recast_data
424
425         layout.operator("mesh.create_navmesh", text='Build navigation mesh')
426
427         col = layout.column()
428         col.label(text="Rasterization:")
429         row = col.row()
430         row.prop(rd, "cell_size")
431         row.prop(rd, "cell_height")
432
433         col = layout.column()
434         col.label(text="Agent:")
435         split = col.split()
436
437         col = split.column()
438         col.prop(rd, "agent_height", text="Height")
439         col.prop(rd, "agent_radius", text="Radius")
440
441         col = split.column()
442         col.prop(rd, "max_slope")
443         col.prop(rd, "max_climb")
444
445         col = layout.column()
446         col.label(text="Region:")
447         row = col.row()
448         row.prop(rd, "region_min_size")
449         row.prop(rd, "region_merge_size")
450
451         col = layout.column()
452         col.label(text="Polygonization:")
453         split = col.split()
454
455         col = split.column()
456         col.prop(rd, "edge_max_len")
457         col.prop(rd, "edge_max_error")
458
459         split.prop(rd, "verts_per_poly")
460
461         col = layout.column()
462         col.label(text="Detail Mesh:")
463         row = col.row()
464         row.prop(rd, "sample_dist")
465         row.prop(rd, "sample_max_error")
466
467
468 class WorldButtonsPanel():
469     bl_space_type = 'PROPERTIES'
470     bl_region_type = 'WINDOW'
471     bl_context = "world"
472
473
474 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
475     bl_label = ""
476     bl_options = {'HIDE_HEADER'}
477     COMPAT_ENGINES = {'BLENDER_GAME'}
478
479     @classmethod
480     def poll(cls, context):
481         rd = context.scene.render
482         return (context.scene) and (rd.use_game_engine)
483
484     def draw(self, context):
485         layout = self.layout
486
487         scene = context.scene
488         world = context.world
489         space = context.space_data
490
491         split = layout.split(percentage=0.65)
492         if scene:
493             split.template_ID(scene, "world", new="world.new")
494         elif world:
495             split.template_ID(space, "pin_id")
496
497
498 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
499     bl_label = "World"
500     COMPAT_ENGINES = {'BLENDER_GAME'}
501
502     @classmethod
503     def poll(cls, context):
504         scene = context.scene
505         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
506
507     def draw(self, context):
508         layout = self.layout
509
510         world = context.world
511
512         row = layout.row()
513         row.column().prop(world, "horizon_color")
514         row.column().prop(world, "ambient_color")
515
516
517 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
518     bl_label = "Mist"
519     COMPAT_ENGINES = {'BLENDER_GAME'}
520
521     @classmethod
522     def poll(cls, context):
523         scene = context.scene
524         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
525
526     def draw_header(self, context):
527         world = context.world
528
529         self.layout.prop(world.mist_settings, "use_mist", text="")
530
531     def draw(self, context):
532         layout = self.layout
533
534         world = context.world
535
536         layout.active = world.mist_settings.use_mist
537
538         row = layout.row()
539         row.prop(world.mist_settings, "start")
540         row.prop(world.mist_settings, "depth")
541
542
543 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
544     bl_label = "Physics"
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(self, context):
553         layout = self.layout
554
555         gs = context.scene.game_settings
556
557         layout.prop(gs, "physics_engine")
558         if gs.physics_engine != 'NONE':
559             layout.prop(gs, "physics_gravity", text="Gravity")
560
561             split = layout.split()
562
563             col = split.column()
564             col.label(text="Physics Steps:")
565             sub = col.column(align=True)
566             sub.prop(gs, "physics_step_max", text="Max")
567             sub.prop(gs, "physics_step_sub", text="Substeps")
568             col.prop(gs, "fps", text="FPS")
569
570             col = split.column()
571             col.label(text="Logic Steps:")
572             col.prop(gs, "logic_step_max", text="Max")
573
574             col = layout.column()
575             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
576             sub = col.column()
577             sub.active = gs.use_occlusion_culling
578             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
579
580         else:
581             split = layout.split()
582
583             col = split.column()
584             col.label(text="Physics Steps:")
585             col.prop(gs, "fps", text="FPS")
586
587             col = split.column()
588             col.label(text="Logic Steps:")
589             col.prop(gs, "logic_step_max", text="Max")
590
591
592 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
593     bl_label = "Obstacle simulation"
594     COMPAT_ENGINES = {'BLENDER_GAME'}
595
596     @classmethod
597     def poll(cls, context):
598         scene = context.scene
599         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
600
601     def draw(self, context):
602         layout = self.layout
603
604         gs = context.scene.game_settings
605
606         layout.prop(gs, "obstacle_simulation", text="Type")
607         if gs.obstacle_simulation != 'NONE':
608             layout.prop(gs, "level_height")
609             layout.prop(gs, "show_obstacle_simulation")
610
611 if __name__ == "__main__":  # only for live edit.
612     bpy.utils.register_module(__name__)