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