change python scripts so modules which register with blender have a register() functi...
[blender.git] / release / scripts / 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
22 narrowui = 180
23
24
25 class PhysicsButtonsPanel(bpy.types.Panel):
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "physics"
29
30     def poll(self, context):
31         ob = context.active_object
32         rd = context.scene.render_data
33         return ob and ob.game and (rd.engine == 'BLENDER_GAME')
34
35
36 class PHYSICS_PT_game_physics(PhysicsButtonsPanel):
37     bl_label = "Physics"
38
39     def draw(self, context):
40         layout = self.layout
41
42         ob = context.active_object
43         game = ob.game
44         soft = ob.game.soft_body
45         wide_ui = context.region.width > narrowui
46
47         if wide_ui:
48             layout.prop(game, "physics_type")
49         else:
50             layout.prop(game, "physics_type", text="")
51         layout.separator()
52
53         #if game.physics_type == 'DYNAMIC':
54         if game.physics_type in ('DYNAMIC', 'RIGID_BODY'):
55             split = layout.split()
56
57             col = split.column()
58             col.prop(game, "actor")
59             col.prop(game, "ghost")
60             col.prop(ob, "restrict_render", text="Invisible") # out of place but useful
61
62             if wide_ui:
63                 col = split.column()
64             col.prop(game, "material_physics")
65             col.prop(game, "rotate_from_normal")
66             col.prop(game, "no_sleeping")
67
68             layout.separator()
69
70             split = layout.split()
71
72             col = split.column()
73             col.label(text="Attributes:")
74             col.prop(game, "mass")
75             col.prop(game, "radius")
76             col.prop(game, "form_factor")
77
78             if wide_ui:
79                 col = split.column()
80             sub = col.column()
81             sub.active = (game.physics_type == 'RIGID_BODY')
82             sub.prop(game, "anisotropic_friction")
83             subsub = sub.column()
84             subsub.active = game.anisotropic_friction
85             subsub.prop(game, "friction_coefficients", text="", slider=True)
86
87             split = layout.split()
88
89             col = split.column()
90             col.label(text="Velocity:")
91             sub = col.column(align=True)
92             sub.prop(game, "minimum_velocity", text="Minimum")
93             sub.prop(game, "maximum_velocity", text="Maximum")
94
95             if wide_ui:
96                 col = split.column()
97             col.label(text="Damping:")
98             sub = col.column(align=True)
99             sub.prop(game, "damping", text="Translation", slider=True)
100             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
101
102             layout.separator()
103
104             split = layout.split()
105
106             col = split.column()
107             col.label(text="Lock Translation:")
108             col.prop(game, "lock_x_axis", text="X")
109             col.prop(game, "lock_y_axis", text="Y")
110             col.prop(game, "lock_z_axis", text="Z")
111
112             col = split.column()
113             col.label(text="Lock Rotation:")
114             col.prop(game, "lock_x_rot_axis", text="X")
115             col.prop(game, "lock_y_rot_axis", text="Y")
116             col.prop(game, "lock_z_rot_axis", text="Z")
117
118         elif game.physics_type == 'SOFT_BODY':
119             col = layout.column()
120             col.prop(game, "actor")
121             col.prop(game, "ghost")
122             col.prop(ob, "restrict_render", text="Invisible")
123
124             layout.separator()
125
126             split = layout.split()
127
128             col = split.column()
129             col.label(text="Attributes:")
130             col.prop(game, "mass")
131             col.prop(soft, "welding")
132             col.prop(soft, "position_iterations")
133             col.prop(soft, "linstiff", slider=True)
134             col.prop(soft, "dynamic_friction", slider=True)
135             col.prop(soft, "margin", slider=True)
136             col.prop(soft, "bending_const", text="Bending Constraints")
137
138             if wide_ui:
139                 col = split.column()
140             col.prop(soft, "shape_match")
141             sub = col.column()
142             sub.active = soft.shape_match
143             sub.prop(soft, "threshold", slider=True)
144
145             col.separator()
146
147             col.label(text="Cluster Collision:")
148             col.prop(soft, "cluster_rigid_to_softbody")
149             col.prop(soft, "cluster_soft_to_softbody")
150             sub = col.column()
151             sub.active = (soft.cluster_rigid_to_softbody or soft.cluster_soft_to_softbody)
152             sub.prop(soft, "cluster_iterations", text="Iterations")
153
154         elif game.physics_type == 'STATIC':
155             col = layout.column()
156             col.prop(game, "actor")
157             col.prop(game, "ghost")
158             col.prop(ob, "restrict_render", text="Invisible")
159
160         elif game.physics_type in ('SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'):
161             layout.prop(ob, "restrict_render", text="Invisible")
162
163
164 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
165     bl_label = "Collision Bounds"
166
167     def poll(self, context):
168         game = context.object.game
169         rd = context.scene.render_data
170         return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
171
172     def draw_header(self, context):
173         game = context.active_object.game
174
175         self.layout.prop(game, "use_collision_bounds", text="")
176
177     def draw(self, context):
178         layout = self.layout
179
180         game = context.active_object.game
181         wide_ui = context.region.width > narrowui
182
183         layout.active = game.use_collision_bounds
184         if wide_ui:
185             layout.prop(game, "collision_bounds", text="Bounds")
186         else:
187             layout.prop(game, "collision_bounds", text="")
188
189         split = layout.split()
190
191         col = split.column()
192         col.prop(game, "collision_margin", text="Margin", slider=True)
193
194         if wide_ui:
195             col = split.column()
196         col.prop(game, "collision_compound", text="Compound")
197
198
199 class RenderButtonsPanel(bpy.types.Panel):
200     bl_space_type = 'PROPERTIES'
201     bl_region_type = 'WINDOW'
202     bl_context = "render"
203
204     def poll(self, context):
205         rd = context.scene.render_data
206         return (rd.engine == 'BLENDER_GAME')
207
208
209 class RENDER_PT_game(RenderButtonsPanel):
210     bl_label = "Game"
211
212     def draw(self, context):
213         layout = self.layout
214
215         row = layout.row()
216         row.operator("view3d.game_start", text="Start")
217         row.label()
218
219
220 class RENDER_PT_game_player(RenderButtonsPanel):
221     bl_label = "Standalone Player"
222
223     def draw(self, context):
224         layout = self.layout
225
226         gs = context.scene.game_data
227         wide_ui = context.region.width > narrowui
228
229         layout.prop(gs, "fullscreen")
230
231         split = layout.split()
232
233         col = split.column()
234         col.label(text="Resolution:")
235         sub = col.column(align=True)
236         sub.prop(gs, "resolution_x", slider=False, text="X")
237         sub.prop(gs, "resolution_y", slider=False, text="Y")
238
239         if wide_ui:
240             col = split.column()
241         col.label(text="Quality:")
242         sub = col.column(align=True)
243         sub.prop(gs, "depth", text="Bit Depth", slider=False)
244         sub.prop(gs, "frequency", text="FPS", slider=False)
245
246         # framing:
247         col = layout.column()
248         col.label(text="Framing:")
249         if wide_ui:
250             col.row().prop(gs, "framing_type", expand=True)
251         else:
252             col.prop(gs, "framing_type", text="")
253         if gs.framing_type == 'LETTERBOX':
254             col.prop(gs, "framing_color", text="")
255
256
257 class RENDER_PT_game_stereo(RenderButtonsPanel):
258     bl_label = "Stereo"
259
260     def draw(self, context):
261         layout = self.layout
262
263         gs = context.scene.game_data
264         stereo_mode = gs.stereo
265         wide_ui = context.region.width > narrowui
266
267         # stereo options:
268         layout.prop(gs, "stereo", expand=True)
269
270         # stereo:
271         if stereo_mode == 'STEREO':
272             layout.prop(gs, "stereo_mode")
273             layout.prop(gs, "eye_separation")
274
275         # dome:
276         elif stereo_mode == 'DOME':
277             if wide_ui:
278                 layout.prop(gs, "dome_mode", text="Dome Type")
279             else:
280                 layout.prop(gs, "dome_mode", text="")
281
282             dome_type = gs.dome_mode
283
284             split = layout.split()
285
286             if dome_type == 'FISHEYE' or \
287                dome_type == 'TRUNCATED_REAR' or \
288                dome_type == 'TRUNCATED_FRONT':
289
290                 col = split.column()
291                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
292                 col.prop(gs, "dome_angle", slider=True)
293
294                 if wide_ui:
295                     col = split.column()
296                 col.prop(gs, "dome_tesselation", text="Tesselation")
297                 col.prop(gs, "dome_tilt")
298
299             elif dome_type == 'PANORAM_SPH':
300                 col = split.column()
301
302                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
303                 if wide_ui:
304                     col = split.column()
305                 col.prop(gs, "dome_tesselation", text="Tesselation")
306
307             else: # cube map
308                 col = split.column()
309                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
310                 if wide_ui:
311                     col = split.column()
312
313             layout.prop(gs, "dome_text")
314
315
316 class RENDER_PT_game_shading(RenderButtonsPanel):
317     bl_label = "Shading"
318
319     def draw(self, context):
320         layout = self.layout
321
322         gs = context.scene.game_data
323         wide_ui = context.region.width > narrowui
324
325         if wide_ui:
326             layout.prop(gs, "material_mode", expand=True)
327         else:
328             layout.prop(gs, "material_mode", text="")
329
330         if gs.material_mode == 'GLSL':
331             split = layout.split()
332
333             col = split.column()
334             col.prop(gs, "glsl_lights", text="Lights")
335             col.prop(gs, "glsl_shaders", text="Shaders")
336             col.prop(gs, "glsl_shadows", text="Shadows")
337
338             col = split.column()
339             col.prop(gs, "glsl_ramps", text="Ramps")
340             col.prop(gs, "glsl_nodes", text="Nodes")
341             col.prop(gs, "glsl_extra_textures", text="Extra Textures")
342
343
344 class RENDER_PT_game_performance(RenderButtonsPanel):
345     bl_label = "Performance"
346
347     def draw(self, context):
348         layout = self.layout
349
350         gs = context.scene.game_data
351         wide_ui = context.region.width > narrowui
352
353         split = layout.split()
354
355         col = split.column()
356         col.label(text="Show:")
357         col.prop(gs, "show_debug_properties", text="Debug Properties")
358         col.prop(gs, "show_framerate_profile", text="Framerate and Profile")
359         col.prop(gs, "show_physics_visualization", text="Physics Visualization")
360         col.prop(gs, "deprecation_warnings")
361
362         if wide_ui:
363             col = split.column()
364         col.label(text="Render:")
365         col.prop(gs, "all_frames")
366         col.prop(gs, "display_lists")
367
368
369 class RENDER_PT_game_sound(RenderButtonsPanel):
370     bl_label = "Sound"
371
372     def draw(self, context):
373         layout = self.layout
374
375         scene = context.scene
376         wide_ui = context.region.width > narrowui
377
378         if wide_ui:
379             layout.prop(scene, "distance_model")
380         else:
381             layout.prop(scene, "distance_model", text="")
382         layout.prop(scene, "speed_of_sound", text="Speed")
383         layout.prop(scene, "doppler_factor")
384
385
386 class WorldButtonsPanel(bpy.types.Panel):
387     bl_space_type = 'PROPERTIES'
388     bl_region_type = 'WINDOW'
389     bl_context = "world"
390
391     def poll(self, context):
392         rd = context.scene.render_data
393         return (rd.engine == 'BLENDER_GAME')
394
395
396 class WORLD_PT_game_context_world(WorldButtonsPanel):
397     bl_label = ""
398     bl_show_header = False
399
400     def poll(self, context):
401         rd = context.scene.render_data
402         return (context.scene) and (rd.use_game_engine)
403
404     def draw(self, context):
405         layout = self.layout
406
407         scene = context.scene
408         world = context.world
409         space = context.space_data
410         wide_ui = context.region.width > narrowui
411
412         if wide_ui:
413             split = layout.split(percentage=0.65)
414             if scene:
415                 split.template_ID(scene, "world", new="world.new")
416             elif world:
417                 split.template_ID(space, "pin_id")
418         else:
419             if scene:
420                 layout.template_ID(scene, "world", new="world.new")
421             elif world:
422                 layout.template_ID(space, "pin_id")
423
424
425 class WORLD_PT_game_world(WorldButtonsPanel):
426     bl_label = "World"
427
428     def draw(self, context):
429         layout = self.layout
430
431         world = context.world
432         wide_ui = context.region.width > narrowui
433
434         split = layout.split()
435
436         col = split.column()
437         col.prop(world, "horizon_color")
438
439         if wide_ui:
440             col = split.column()
441         col.prop(world, "ambient_color")
442
443
444 class WORLD_PT_game_mist(WorldButtonsPanel):
445     bl_label = "Mist"
446
447     def draw_header(self, context):
448         world = context.world
449
450         self.layout.prop(world.mist, "enabled", text="")
451
452     def draw(self, context):
453         layout = self.layout
454
455         world = context.world
456         wide_ui = context.region.width > narrowui
457
458         layout.active = world.mist.enabled
459         split = layout.split()
460
461         col = split.column()
462         col.prop(world.mist, "start")
463
464         if wide_ui:
465             col = split.column()
466         col.prop(world.mist, "depth")
467
468
469 class WORLD_PT_game_physics(WorldButtonsPanel):
470     bl_label = "Physics"
471
472     def draw(self, context):
473         layout = self.layout
474
475         gs = context.scene.game_data
476         wide_ui = context.region.width > narrowui
477
478         layout.prop(gs, "physics_engine")
479         if gs.physics_engine != 'NONE':
480             layout.prop(gs, "physics_gravity", text="Gravity")
481
482             split = layout.split()
483
484             col = split.column()
485             col.label(text="Physics Steps:")
486             sub = col.column(align=True)
487             sub.prop(gs, "physics_step_max", text="Max")
488             sub.prop(gs, "physics_step_sub", text="Substeps")
489             col.prop(gs, "fps", text="FPS")
490
491             if wide_ui:
492                 col = split.column()
493             col.label(text="Logic Steps:")
494             col.prop(gs, "logic_step_max", text="Max")
495
496             col = layout.column()
497             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
498             sub = col.column()
499             sub.active = gs.use_occlusion_culling
500             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
501
502         else:
503             split = layout.split()
504
505             col = split.column()
506             col.label(text="Physics Steps:")
507             col.prop(gs, "fps", text="FPS")
508
509             col = split.column()
510             col.label(text="Logic Steps:")
511             col.prop(gs, "logic_step_max", text="Max")
512
513
514 classes = [
515     PHYSICS_PT_game_physics,
516     PHYSICS_PT_game_collision_bounds,
517
518     RENDER_PT_game,
519     RENDER_PT_game_player,
520     RENDER_PT_game_stereo,
521     RENDER_PT_game_shading,
522     RENDER_PT_game_performance,
523     RENDER_PT_game_sound,
524
525     WORLD_PT_game_context_world,
526     WORLD_PT_game_world,
527     WORLD_PT_game_mist,
528     WORLD_PT_game_physics]
529
530
531 def register():
532     register = bpy.types.register
533     for cls in classes:
534         register(cls)
535
536 def unregister():
537     unregister = bpy.types.unregister
538     for cls in classes:
539         unregister(cls)