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