fix for crash with GLSL material when image couldn't be loaded.
[blender-staging.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
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")
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         split = layout.split()
194
195         col = split.column()
196         col.prop(game, "collision_margin", text="Margin", slider=True)
197
198         col = split.column()
199         col.prop(game, "use_collision_compound", text="Compound")
200
201
202 class RenderButtonsPanel():
203     bl_space_type = 'PROPERTIES'
204     bl_region_type = 'WINDOW'
205     bl_context = "render"
206
207     @classmethod
208     def poll(cls, context):
209         rd = context.scene.render
210         return (rd.engine in cls.COMPAT_ENGINES)
211
212
213 class RENDER_PT_game(RenderButtonsPanel, bpy.types.Panel):
214     bl_label = "Game"
215     COMPAT_ENGINES = {'BLENDER_GAME'}
216
217     def draw(self, context):
218         layout = self.layout
219
220         row = layout.row()
221         row.operator("view3d.game_start", text="Start")
222         row.label()
223
224
225 class RENDER_PT_game_player(RenderButtonsPanel, bpy.types.Panel):
226     bl_label = "Standalone Player"
227     COMPAT_ENGINES = {'BLENDER_GAME'}
228
229     def draw(self, context):
230         layout = self.layout
231
232         gs = context.scene.game_settings
233
234         layout.prop(gs, "show_fullscreen")
235
236         split = layout.split()
237
238         col = split.column()
239         col.label(text="Resolution:")
240         sub = col.column(align=True)
241         sub.prop(gs, "resolution_x", slider=False, text="X")
242         sub.prop(gs, "resolution_y", slider=False, text="Y")
243
244         col = split.column()
245         col.label(text="Quality:")
246         sub = col.column(align=True)
247         sub.prop(gs, "depth", text="Bit Depth", slider=False)
248         sub.prop(gs, "frequency", text="FPS", slider=False)
249
250         # framing:
251         col = layout.column()
252         col.label(text="Framing:")
253         col.row().prop(gs, "frame_type", expand=True)
254         if gs.frame_type == 'LETTERBOX':
255             col.prop(gs, "frame_color", text="")
256
257
258 class RENDER_PT_game_stereo(RenderButtonsPanel, bpy.types.Panel):
259     bl_label = "Stereo"
260     COMPAT_ENGINES = {'BLENDER_GAME'}
261
262     def draw(self, context):
263         layout = self.layout
264
265         gs = context.scene.game_settings
266         stereo_mode = gs.stereo
267
268         # stereo options:
269         layout.prop(gs, "stereo", expand=True)
270
271         # stereo:
272         if stereo_mode == 'STEREO':
273             layout.prop(gs, "stereo_mode")
274             layout.prop(gs, "stereo_eye_separation")
275
276         # dome:
277         elif stereo_mode == 'DOME':
278             layout.prop(gs, "dome_mode", text="Dome Type")
279
280             dome_type = gs.dome_mode
281
282             split = layout.split()
283
284             if dome_type == 'FISHEYE' or \
285                dome_type == 'TRUNCATED_REAR' or \
286                dome_type == 'TRUNCATED_FRONT':
287
288                 col = split.column()
289                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
290                 col.prop(gs, "dome_angle", slider=True)
291
292                 col = split.column()
293                 col.prop(gs, "dome_tesselation", text="Tesselation")
294                 col.prop(gs, "dome_tilt")
295
296             elif dome_type == 'PANORAM_SPH':
297                 col = split.column()
298
299                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
300                 col = split.column()
301                 col.prop(gs, "dome_tesselation", text="Tesselation")
302
303             else:  # cube map
304                 col = split.column()
305                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
306
307                 col = split.column()
308
309             layout.prop(gs, "dome_text")
310
311
312 class RENDER_PT_game_shading(RenderButtonsPanel, bpy.types.Panel):
313     bl_label = "Shading"
314     COMPAT_ENGINES = {'BLENDER_GAME'}
315
316     def draw(self, context):
317         layout = self.layout
318
319         gs = context.scene.game_settings
320
321         layout.prop(gs, "material_mode", expand=True)
322
323         if gs.material_mode == 'GLSL':
324             split = layout.split()
325
326             col = split.column()
327             col.prop(gs, "use_glsl_lights", text="Lights")
328             col.prop(gs, "use_glsl_shaders", text="Shaders")
329             col.prop(gs, "use_glsl_shadows", text="Shadows")
330
331             col = split.column()
332             col.prop(gs, "use_glsl_ramps", text="Ramps")
333             col.prop(gs, "use_glsl_nodes", text="Nodes")
334             col.prop(gs, "use_glsl_extra_textures", text="Extra Textures")
335
336
337 class RENDER_PT_game_performance(RenderButtonsPanel, bpy.types.Panel):
338     bl_label = "Performance"
339     COMPAT_ENGINES = {'BLENDER_GAME'}
340
341     def draw(self, context):
342         layout = self.layout
343
344         gs = context.scene.game_settings
345         row = layout.row()
346         row.prop(gs, "use_frame_rate")
347         row.prop(gs, "use_display_lists")
348
349
350 class RENDER_PT_game_display(RenderButtonsPanel, bpy.types.Panel):
351     bl_label = "Display"
352     COMPAT_ENGINES = {'BLENDER_GAME'}
353
354     def draw(self, context):
355         layout = self.layout
356
357         gs = context.scene.game_settings
358         flow = layout.column_flow()
359         flow.prop(gs, "show_debug_properties", text="Debug Properties")
360         flow.prop(gs, "show_framerate_profile", text="Framerate and Profile")
361         flow.prop(gs, "show_physics_visualization", text="Physics Visualization")
362         flow.prop(gs, "use_deprecation_warnings")
363         flow.prop(gs, "show_mouse")
364
365
366 class RENDER_PT_game_sound(RenderButtonsPanel, bpy.types.Panel):
367     bl_label = "Sound"
368     COMPAT_ENGINES = {'BLENDER_GAME'}
369
370     def draw(self, context):
371         layout = self.layout
372
373         scene = context.scene
374
375         layout.prop(scene, "audio_distance_model")
376
377         layout.prop(scene, "audio_doppler_speed", text="Speed")
378         layout.prop(scene, "audio_doppler_factor")
379
380
381 class WorldButtonsPanel():
382     bl_space_type = 'PROPERTIES'
383     bl_region_type = 'WINDOW'
384     bl_context = "world"
385
386
387 class WORLD_PT_game_context_world(WorldButtonsPanel, bpy.types.Panel):
388     bl_label = ""
389     bl_options = {'HIDE_HEADER'}
390     COMPAT_ENGINES = {'BLENDER_GAME'}
391
392     @classmethod
393     def poll(cls, context):
394         rd = context.scene.render
395         return (context.scene) and (rd.use_game_engine)
396
397     def draw(self, context):
398         layout = self.layout
399
400         scene = context.scene
401         world = context.world
402         space = context.space_data
403
404         split = layout.split(percentage=0.65)
405         if scene:
406             split.template_ID(scene, "world", new="world.new")
407         elif world:
408             split.template_ID(space, "pin_id")
409
410
411 class WORLD_PT_game_world(WorldButtonsPanel, bpy.types.Panel):
412     bl_label = "World"
413     COMPAT_ENGINES = {'BLENDER_GAME'}
414
415     @classmethod
416     def poll(cls, context):
417         scene = context.scene
418         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
419
420     def draw(self, context):
421         layout = self.layout
422
423         world = context.world
424
425         split = layout.split()
426
427         col = split.column()
428         col.prop(world, "horizon_color")
429
430         col = split.column()
431         col.prop(world, "ambient_color")
432
433
434 class WORLD_PT_game_mist(WorldButtonsPanel, bpy.types.Panel):
435     bl_label = "Mist"
436     COMPAT_ENGINES = {'BLENDER_GAME'}
437
438     @classmethod
439     def poll(cls, context):
440         scene = context.scene
441         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
442
443     def draw_header(self, context):
444         world = context.world
445
446         self.layout.prop(world.mist_settings, "use_mist", text="")
447
448     def draw(self, context):
449         layout = self.layout
450
451         world = context.world
452
453         layout.active = world.mist_settings.use_mist
454         split = layout.split()
455
456         col = split.column()
457         col.prop(world.mist_settings, "start")
458
459         col = split.column()
460         col.prop(world.mist_settings, "depth")
461
462
463 class WORLD_PT_game_physics(WorldButtonsPanel, bpy.types.Panel):
464     bl_label = "Physics"
465     COMPAT_ENGINES = {'BLENDER_GAME'}
466
467     @classmethod
468     def poll(cls, context):
469         scene = context.scene
470         return (scene.world and scene.render.engine in cls.COMPAT_ENGINES)
471
472     def draw(self, context):
473         layout = self.layout
474
475         gs = context.scene.game_settings
476
477         layout.prop(gs, "physics_engine")
478         if gs.physics_engine != 'NONE':
479             layout.prop(gs, "physics_gravity", text="Gravity")
480
481             split = layout.split()
482
483             col = split.column()
484             col.label(text="Physics Steps:")
485             sub = col.column(align=True)
486             sub.prop(gs, "physics_step_max", text="Max")
487             sub.prop(gs, "physics_step_sub", text="Substeps")
488             col.prop(gs, "fps", text="FPS")
489
490             col = split.column()
491             col.label(text="Logic Steps:")
492             col.prop(gs, "logic_step_max", text="Max")
493
494             col = layout.column()
495             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
496             sub = col.column()
497             sub.active = gs.use_occlusion_culling
498             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
499
500         else:
501             split = layout.split()
502
503             col = split.column()
504             col.label(text="Physics Steps:")
505             col.prop(gs, "fps", text="FPS")
506
507             col = split.column()
508             col.label(text="Logic Steps:")
509             col.prop(gs, "logic_step_max", text="Max")
510
511
512 def register():
513     pass
514
515
516 def unregister():
517     pass
518
519 if __name__ == "__main__":
520     register()