Merging r41937 through r42061 from trunk into soc-2011-tomato
[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_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 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_performance(RenderButtonsPanel, Panel):
372     bl_label = "Performance"
373     COMPAT_ENGINES = {'BLENDER_GAME'}
374
375     def draw(self, context):
376         layout = self.layout
377
378         gs = context.scene.game_settings
379         col = layout.column()
380         row = col.row()
381         row.prop(gs, "use_frame_rate")
382         row.prop(gs, "use_display_lists")
383
384         col.prop(gs, "restrict_animation_updates")
385
386
387 class RENDER_PT_game_display(RenderButtonsPanel, Panel):
388     bl_label = "Display"
389     COMPAT_ENGINES = {'BLENDER_GAME'}
390
391     def draw(self, context):
392         layout = self.layout
393
394         gs = context.scene.game_settings
395         flow = layout.column_flow()
396         flow.prop(gs, "show_debug_properties", text="Debug Properties")
397         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
398         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
399         flow.prop(gs, "use_deprecation_warnings")
400         flow.prop(gs, "show_mouse", text="Mouse Cursor")
401
402
403 class SceneButtonsPanel():
404     bl_space_type = 'PROPERTIES'
405     bl_region_type = 'WINDOW'
406     bl_context = "scene"
407
408
409 class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
410     bl_label = "Navigation mesh"
411     bl_options = {'DEFAULT_CLOSED'}
412     COMPAT_ENGINES = {'BLENDER_GAME'}
413
414     @classmethod
415     def poll(cls, context):
416         scene = context.scene
417         return (scene and scene.render.engine in cls.COMPAT_ENGINES)
418
419     def draw(self, context):
420         layout = self.layout
421
422         rd = context.scene.game_settings.recast_data
423
424         layout.operator("mesh.navmesh_make", text='Build navigation mesh')
425
426         col = layout.column()
427         col.label(text="Rasterization:")
428         row = col.row()
429         row.prop(rd, "cell_size")
430         row.prop(rd, "cell_height")
431
432         col = layout.column()
433         col.label(text="Agent:")
434         split = col.split()
435
436         col = split.column()
437         col.prop(rd, "agent_height", text="Height")
438         col.prop(rd, "agent_radius", text="Radius")
439
440         col = split.column()
441         col.prop(rd, "slope_max")
442         col.prop(rd, "climb_max")
443
444         col = layout.column()
445         col.label(text="Region:")
446         row = col.row()
447         row.prop(rd, "region_min_size")
448         row.prop(rd, "region_merge_size")
449
450         col = layout.column()
451         col.label(text="Polygonization:")
452         split = col.split()
453
454         col = split.column()
455         col.prop(rd, "edge_max_len")
456         col.prop(rd, "edge_max_error")
457
458         split.prop(rd, "verts_per_poly")
459
460         col = layout.column()
461         col.label(text="Detail Mesh:")
462         row = col.row()
463         row.prop(rd, "sample_dist")
464         row.prop(rd, "sample_max_error")
465
466
467 class WorldButtonsPanel():
468     bl_space_type = 'PROPERTIES'
469     bl_region_type = 'WINDOW'
470     bl_context = "world"
471
472
473 class WORLD_PT_game_context_world(WorldButtonsPanel, Panel):
474     bl_label = ""
475     bl_options = {'HIDE_HEADER'}
476     COMPAT_ENGINES = {'BLENDER_GAME'}
477
478     @classmethod
479     def poll(cls, context):
480         rd = context.scene.render
481         return (context.scene) and (rd.use_game_engine)
482
483     def draw(self, context):
484         layout = self.layout
485
486         scene = context.scene
487         world = context.world
488         space = context.space_data
489
490         split = layout.split(percentage=0.65)
491         if scene:
492             split.template_ID(scene, "world", new="world.new")
493         elif world:
494             split.template_ID(space, "pin_id")
495
496
497 class WORLD_PT_game_world(WorldButtonsPanel, Panel):
498     bl_label = "World"
499     COMPAT_ENGINES = {'BLENDER_GAME'}
500
501     @classmethod
502     def poll(cls, context):
503         scene = context.scene
504         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
505
506     def draw(self, context):
507         layout = self.layout
508
509         world = context.world
510
511         row = layout.row()
512         row.column().prop(world, "horizon_color")
513         row.column().prop(world, "ambient_color")
514
515
516 class WORLD_PT_game_mist(WorldButtonsPanel, Panel):
517     bl_label = "Mist"
518     COMPAT_ENGINES = {'BLENDER_GAME'}
519
520     @classmethod
521     def poll(cls, context):
522         scene = context.scene
523         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
524
525     def draw_header(self, context):
526         world = context.world
527
528         self.layout.prop(world.mist_settings, "use_mist", text="")
529
530     def draw(self, context):
531         layout = self.layout
532
533         world = context.world
534
535         layout.active = world.mist_settings.use_mist
536
537         row = layout.row()
538         row.prop(world.mist_settings, "start")
539         row.prop(world.mist_settings, "depth")
540
541
542 class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
543     bl_label = "Physics"
544     COMPAT_ENGINES = {'BLENDER_GAME'}
545
546     @classmethod
547     def poll(cls, context):
548         scene = context.scene
549         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
550
551     def draw(self, context):
552         layout = self.layout
553
554         gs = context.scene.game_settings
555
556         layout.prop(gs, "physics_engine")
557         if gs.physics_engine != 'NONE':
558             layout.prop(gs, "physics_gravity", text="Gravity")
559
560             split = layout.split()
561
562             col = split.column()
563             col.label(text="Physics Steps:")
564             sub = col.column(align=True)
565             sub.prop(gs, "physics_step_max", text="Max")
566             sub.prop(gs, "physics_step_sub", text="Substeps")
567             col.prop(gs, "fps", text="FPS")
568
569             col = split.column()
570             col.label(text="Logic Steps:")
571             col.prop(gs, "logic_step_max", text="Max")
572
573             col = layout.column()
574             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
575             sub = col.column()
576             sub.active = gs.use_occlusion_culling
577             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
578
579         else:
580             split = layout.split()
581
582             col = split.column()
583             col.label(text="Physics Steps:")
584             col.prop(gs, "fps", text="FPS")
585
586             col = split.column()
587             col.label(text="Logic Steps:")
588             col.prop(gs, "logic_step_max", text="Max")
589
590
591 class WORLD_PT_game_physics_obstacles(WorldButtonsPanel, Panel):
592     bl_label = "Obstacle simulation"
593     COMPAT_ENGINES = {'BLENDER_GAME'}
594
595     @classmethod
596     def poll(cls, context):
597         scene = context.scene
598         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
599
600     def draw(self, context):
601         layout = self.layout
602
603         gs = context.scene.game_settings
604
605         layout.prop(gs, "obstacle_simulation", text="Type")
606         if gs.obstacle_simulation != 'NONE':
607             layout.prop(gs, "level_height")
608             layout.prop(gs, "show_obstacle_simulation")
609
610 if __name__ == "__main__":  # only for live edit.
611     bpy.utils.register_module(__name__)