Related to bug #27004: there is now an option to disable color management for
[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
22
23 class PhysicsButtonsPanel():
24     bl_space_type = 'PROPERTIES'
25     bl_region_type = 'WINDOW'
26     bl_context = "physics"
27
28
29 class PHYSICS_PT_game_physics(PhysicsButtonsPanel, bpy.types.Panel):
30     bl_label = "Physics"
31     COMPAT_ENGINES = {'BLENDER_GAME'}
32
33     @classmethod
34     def poll(cls, context):
35         ob = context.active_object
36         rd = context.scene.render
37         return ob and ob.game and (rd.engine in cls.COMPAT_ENGINES)
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
46         layout.prop(game, "physics_type")
47         layout.separator()
48
49         #if game.physics_type == 'DYNAMIC':
50         if game.physics_type in {'DYNAMIC', 'RIGID_BODY'}:
51             split = layout.split()
52
53             col = split.column()
54             col.prop(game, "use_actor")
55             col.prop(game, "use_ghost")
56             col.prop(ob, "hide_render", text="Invisible")  # out of place but useful
57
58             col = split.column()
59             col.prop(game, "use_material_physics_fh")
60             col.prop(game, "use_rotate_from_normal")
61             col.prop(game, "use_sleep")
62
63             layout.separator()
64
65             split = layout.split()
66
67             col = split.column()
68             col.label(text="Attributes:")
69             col.prop(game, "mass")
70             col.prop(game, "radius")
71             col.prop(game, "form_factor")
72
73             col = split.column()
74             sub = col.column()
75             sub.prop(game, "use_anisotropic_friction")
76             subsub = sub.column()
77             subsub.active = game.use_anisotropic_friction
78             subsub.prop(game, "friction_coefficients", text="", slider=True)
79
80             split = layout.split()
81
82             col = split.column()
83             col.label(text="Velocity:")
84             sub = col.column(align=True)
85             sub.prop(game, "velocity_min", text="Minimum")
86             sub.prop(game, "velocity_max", text="Maximum")
87
88             col = split.column()
89             col.label(text="Damping:")
90             sub = col.column(align=True)
91             sub.prop(game, "damping", text="Translation", slider=True)
92             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
93
94             layout.separator()
95
96             split = layout.split()
97
98             col = split.column()
99             col.label(text="Lock Translation:")
100             col.prop(game, "lock_location_x", text="X")
101             col.prop(game, "lock_location_y", text="Y")
102             col.prop(game, "lock_location_z", text="Z")
103
104             col = split.column()
105             col.label(text="Lock Rotation:")
106             col.prop(game, "lock_rotation_x", text="X")
107             col.prop(game, "lock_rotation_y", text="Y")
108             col.prop(game, "lock_rotation_z", text="Z")
109
110         elif game.physics_type == 'SOFT_BODY':
111             col = layout.column()
112             col.prop(game, "use_actor")
113             col.prop(game, "use_ghost")
114             col.prop(ob, "hide_render", text="Invisible")
115
116             layout.separator()
117
118             split = layout.split()
119
120             col = split.column()
121             col.label(text="Attributes:")
122             col.prop(game, "mass")
123             col.prop(soft, "weld_threshold")
124             col.prop(soft, "location_iterations")
125             col.prop(soft, "linear_stiffness", slider=True)
126             col.prop(soft, "dynamic_friction", slider=True)
127             col.prop(soft, "collision_margin", slider=True)
128             col.prop(soft, "use_bending_constraints", text="Bending Constraints")
129
130             col = split.column()
131             col.prop(soft, "use_shape_match")
132             sub = col.column()
133             sub.active = soft.use_shape_match
134             sub.prop(soft, "shape_threshold", slider=True)
135
136             col.separator()
137
138             col.label(text="Cluster Collision:")
139             col.prop(soft, "use_cluster_rigid_to_softbody")
140             col.prop(soft, "use_cluster_soft_to_softbody")
141             sub = col.column()
142             sub.active = (soft.use_cluster_rigid_to_softbody or soft.use_cluster_soft_to_softbody)
143             sub.prop(soft, "cluster_iterations", text="Iterations")
144
145         elif game.physics_type == 'STATIC':
146             col = layout.column()
147             col.prop(game, "use_actor")
148             col.prop(game, "use_ghost")
149             col.prop(ob, "hide_render", text="Invisible")
150
151             layout.separator()
152
153             split = layout.split()
154
155             col = split.column()
156             col.label(text="Attributes:")
157             col.prop(game, "radius")
158
159             col = split.column()
160             sub = col.column()
161             sub.prop(game, "use_anisotropic_friction")
162             subsub = sub.column()
163             subsub.active = game.use_anisotropic_friction
164             subsub.prop(game, "friction_coefficients", text="", slider=True)
165
166         elif game.physics_type in {'SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'}:
167             layout.prop(ob, "hide_render", text="Invisible")
168
169
170 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, bpy.types.Panel):
171     bl_label = "Collision Bounds"
172     COMPAT_ENGINES = {'BLENDER_GAME'}
173
174     @classmethod
175     def poll(cls, context):
176         game = context.object.game
177         rd = context.scene.render
178         return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES)
179
180     def draw_header(self, context):
181         game = context.active_object.game
182
183         self.layout.prop(game, "use_collision_bounds", text="")
184
185     def draw(self, context):
186         layout = self.layout
187
188         game = context.active_object.game
189
190         layout.active = game.use_collision_bounds
191         layout.prop(game, "collision_bounds_type", text="Bounds")
192
193         row = layout.row()
194         row.prop(game, "collision_margin", text="Margin", slider=True)
195         row.prop(game, "use_collision_compound", text="Compound")
196
197
198 class RenderButtonsPanel():
199     bl_space_type = 'PROPERTIES'
200     bl_region_type = 'WINDOW'
201     bl_context = "render"
202
203     @classmethod
204     def poll(cls, context):
205         rd = context.scene.render
206         return (rd.engine in cls.COMPAT_ENGINES)
207
208
209 class RENDER_PT_game(RenderButtonsPanel, bpy.types.Panel):
210     bl_label = "Game"
211     COMPAT_ENGINES = {'BLENDER_GAME'}
212
213     def draw(self, context):
214         layout = self.layout
215
216         row = layout.row()
217         row.operator("view3d.game_start", text="Start")
218         row.label()
219
220
221 class RENDER_PT_game_player(RenderButtonsPanel, bpy.types.Panel):
222     bl_label = "Standalone Player"
223     COMPAT_ENGINES = {'BLENDER_GAME'}
224
225     def draw(self, context):
226         layout = self.layout
227
228         gs = context.scene.game_settings
229
230         layout.prop(gs, "show_fullscreen")
231
232         split = layout.split()
233
234         col = split.column()
235         col.label(text="Resolution:")
236         sub = col.column(align=True)
237         sub.prop(gs, "resolution_x", slider=False, text="X")
238         sub.prop(gs, "resolution_y", slider=False, text="Y")
239
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         col.row().prop(gs, "frame_type", expand=True)
250         if gs.frame_type == 'LETTERBOX':
251             col.prop(gs, "frame_color", text="")
252
253
254 class RENDER_PT_game_stereo(RenderButtonsPanel, bpy.types.Panel):
255     bl_label = "Stereo"
256     COMPAT_ENGINES = {'BLENDER_GAME'}
257
258     def draw(self, context):
259         layout = self.layout
260
261         gs = context.scene.game_settings
262         stereo_mode = gs.stereo
263
264         # stereo options:
265         layout.prop(gs, "stereo", expand=True)
266
267         # stereo:
268         if stereo_mode == 'STEREO':
269             layout.prop(gs, "stereo_mode")
270             layout.prop(gs, "stereo_eye_separation")
271
272         # dome:
273         elif stereo_mode == 'DOME':
274             layout.prop(gs, "dome_mode", text="Dome Type")
275
276             dome_type = gs.dome_mode
277
278             split = layout.split()
279
280             if dome_type == 'FISHEYE' or \
281                dome_type == 'TRUNCATED_REAR' or \
282                dome_type == 'TRUNCATED_FRONT':
283
284                 col = split.column()
285                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
286                 col.prop(gs, "dome_angle", slider=True)
287
288                 col = split.column()
289                 col.prop(gs, "dome_tesselation", text="Tesselation")
290                 col.prop(gs, "dome_tilt")
291
292             elif dome_type == 'PANORAM_SPH':
293                 col = split.column()
294
295                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
296                 col = split.column()
297                 col.prop(gs, "dome_tesselation", text="Tesselation")
298
299             else:  # cube map
300                 col = split.column()
301                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
302
303                 col = split.column()
304
305             layout.prop(gs, "dome_text")
306
307
308 class RENDER_PT_game_shading(RenderButtonsPanel, bpy.types.Panel):
309     bl_label = "Shading"
310     COMPAT_ENGINES = {'BLENDER_GAME'}
311
312     def draw(self, context):
313         layout = self.layout
314
315         gs = context.scene.game_settings
316
317         layout.prop(gs, "material_mode", expand=True)
318
319         if gs.material_mode == 'GLSL':
320             split = layout.split()
321
322             col = split.column()
323             col.prop(gs, "use_glsl_lights", text="Lights")
324             col.prop(gs, "use_glsl_shaders", text="Shaders")
325             col.prop(gs, "use_glsl_shadows", text="Shadows")
326             col.prop(gs, "use_glsl_color_management", text="Color Management")
327
328             col = split.column()
329             col.prop(gs, "use_glsl_ramps", text="Ramps")
330             col.prop(gs, "use_glsl_nodes", text="Nodes")
331             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
332
333
334 class RENDER_PT_game_performance(RenderButtonsPanel, bpy.types.Panel):
335     bl_label = "Performance"
336     COMPAT_ENGINES = {'BLENDER_GAME'}
337
338     def draw(self, context):
339         layout = self.layout
340
341         gs = context.scene.game_settings
342         row = layout.row()
343         row.prop(gs, "use_frame_rate")
344         row.prop(gs, "use_display_lists")
345
346
347 class RENDER_PT_game_display(RenderButtonsPanel, bpy.types.Panel):
348     bl_label = "Display"
349     COMPAT_ENGINES = {'BLENDER_GAME'}
350
351     def draw(self, context):
352         layout = self.layout
353
354         gs = context.scene.game_settings
355         flow = layout.column_flow()
356         flow.prop(gs, "show_debug_properties", text="Debug Properties")
357         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
358         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
359         flow.prop(gs, "use_deprecation_warnings")
360         flow.prop(gs, "show_mouse", text="Mouse Cursor")
361
362
363 class RENDER_PT_game_sound(RenderButtonsPanel, bpy.types.Panel):
364     bl_label = "Sound"
365     COMPAT_ENGINES = {'BLENDER_GAME'}
366
367     def draw(self, context):
368         layout = self.layout
369
370         scene = context.scene
371
372         layout.prop(scene, "audio_distance_model")
373
374         layout.prop(scene, "audio_doppler_speed", text="Speed")
375         layout.prop(scene, "audio_doppler_factor")
376
377
378 class WorldButtonsPanel():
379     bl_space_type = 'PROPERTIES'
380     bl_region_type = 'WINDOW'
381     bl_context = "world"
382
383
384 class WORLD_PT_game_context_world(WorldButtonsPanel, bpy.types.Panel):
385     bl_label = ""
386     bl_options = {'HIDE_HEADER'}
387     COMPAT_ENGINES = {'BLENDER_GAME'}
388
389     @classmethod
390     def poll(cls, context):
391         rd = context.scene.render
392         return (context.scene) and (rd.use_game_engine)
393
394     def draw(self, context):
395         layout = self.layout
396
397         scene = context.scene
398         world = context.world
399         space = context.space_data
400
401         split = layout.split(percentage=0.65)
402         if scene:
403             split.template_ID(scene, "world", new="world.new")
404         elif world:
405             split.template_ID(space, "pin_id")
406
407
408 class WORLD_PT_game_world(WorldButtonsPanel, bpy.types.Panel):
409     bl_label = "World"
410     COMPAT_ENGINES = {'BLENDER_GAME'}
411
412     @classmethod
413     def poll(cls, context):
414         scene = context.scene
415         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
416
417     def draw(self, context):
418         layout = self.layout
419
420         world = context.world
421
422         row = layout.row()
423         row.column().prop(world, "horizon_color")
424         row.column().prop(world, "ambient_color")
425
426
427 class WORLD_PT_game_mist(WorldButtonsPanel, bpy.types.Panel):
428     bl_label = "Mist"
429     COMPAT_ENGINES = {'BLENDER_GAME'}
430
431     @classmethod
432     def poll(cls, context):
433         scene = context.scene
434         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
435
436     def draw_header(self, context):
437         world = context.world
438
439         self.layout.prop(world.mist_settings, "use_mist", text="")
440
441     def draw(self, context):
442         layout = self.layout
443
444         world = context.world
445
446         layout.active = world.mist_settings.use_mist
447
448         row = layout.row()
449         row.prop(world.mist_settings, "start")
450         row.prop(world.mist_settings, "depth")
451
452
453 class WORLD_PT_game_physics(WorldButtonsPanel, bpy.types.Panel):
454     bl_label = "Physics"
455     COMPAT_ENGINES = {'BLENDER_GAME'}
456
457     @classmethod
458     def poll(cls, context):
459         scene = context.scene
460         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
461
462     def draw(self, context):
463         layout = self.layout
464
465         gs = context.scene.game_settings
466
467         layout.prop(gs, "physics_engine")
468         if gs.physics_engine != 'NONE':
469             layout.prop(gs, "physics_gravity", text="Gravity")
470
471             split = layout.split()
472
473             col = split.column()
474             col.label(text="Physics Steps:")
475             sub = col.column(align=True)
476             sub.prop(gs, "physics_step_max", text="Max")
477             sub.prop(gs, "physics_step_sub", text="Substeps")
478             col.prop(gs, "fps", text="FPS")
479
480             col = split.column()
481             col.label(text="Logic Steps:")
482             col.prop(gs, "logic_step_max", text="Max")
483
484             col = layout.column()
485             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
486             sub = col.column()
487             sub.active = gs.use_occlusion_culling
488             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
489
490         else:
491             split = layout.split()
492
493             col = split.column()
494             col.label(text="Physics Steps:")
495             col.prop(gs, "fps", text="FPS")
496
497             col = split.column()
498             col.label(text="Logic Steps:")
499             col.prop(gs, "logic_step_max", text="Max")
500
501 if __name__ == "__main__":  # only for live edit.
502     bpy.utils.register_module(__name__)