3158536585e221b6c1491e88f98ee156dcec438a
[blender.git] / release / ui / buttons_game.py
1
2 import bpy
3  
4 class PhysicsButtonsPanel(bpy.types.Panel):
5         __space_type__ = "PROPERTIES"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.active_object
11                 rd = context.scene.render_data
12                 return ob and ob.game and (rd.engine == 'BLENDER_GAME')
13
14 class PHYSICS_PT_game_physics(PhysicsButtonsPanel):
15         __label__ = "Physics"
16
17         def draw(self, context):
18                 layout = self.layout
19                 
20                 ob = context.active_object
21                 game = ob.game
22                 soft = ob.game.soft_body
23
24                 layout.itemR(game, "physics_type")
25                 layout.itemS()
26                 
27                 #if game.physics_type == 'DYNAMIC':
28                 if game.physics_type in ('DYNAMIC', 'RIGID_BODY'):
29
30                         split = layout.split()
31                         
32                         col = split.column()
33                         col.itemR(game, "actor")
34                         col.itemR(game, "ghost")
35                         col.itemR(ob, "restrict_render", text="Invisible") # out of place but useful
36                         
37                         col = split.column()
38                         col.itemR(game, "material_physics")
39                         col.itemR(game, "rotate_from_normal")
40                         col.itemR(game, "no_sleeping")
41                         
42                         layout.itemS()
43                         
44                         split = layout.split()
45                         
46                         col = split.column()
47                         col.itemL(text="Attributes:")
48                         sub = col.column()
49                         sub.itemR(game, "mass")
50                         sub.itemR(game, "radius")
51                         sub.itemR(game, "form_factor")
52                         
53                         col = split.column()
54                         sub = col.column()
55                         sub.active = (game.physics_type == 'RIGID_BODY')
56                         sub.itemR(game, "anisotropic_friction")
57                         subsub = sub.column()
58                         subsub.active = game.anisotropic_friction
59                         subsub.itemR(game, "friction_coefficients", text="", slider=True)
60                         
61                         split = layout.split()
62                         
63                         col = split.column()
64                         col.itemL(text="Velocity:")
65                         sub = col.column(align=True)
66                         sub.itemR(game, "minimum_velocity", text="Minimum")
67                         sub.itemR(game, "maximum_velocity", text="Maximum")
68                         
69                         col = split.column()
70                         col.itemL(text="Damping:")
71                         sub = col.column(align=True)
72                         sub.itemR(game, "damping", text="Translation", slider=True)
73                         sub.itemR(game, "rotation_damping", text="Rotation", slider=True)
74                         
75                         layout.itemS()
76                         
77                         split = layout.split()
78                         
79                         col = split.column()
80                         col.itemL(text="Lock Translation:")
81                         col.itemR(game, "lock_x_axis", text="X")
82                         col.itemR(game, "lock_y_axis", text="Y")
83                         col.itemR(game, "lock_z_axis", text="Z")
84                         
85                         col = split.column()
86                         col.itemL(text="Lock Rotation:")
87                         col.itemR(game, "lock_x_rot_axis", text="X")
88                         col.itemR(game, "lock_y_rot_axis", text="Y")
89                         col.itemR(game, "lock_z_rot_axis", text="Z")
90                 
91                 elif game.physics_type == 'SOFT_BODY':
92
93                         col = layout.column()
94                         col.itemR(game, "actor")
95                         col.itemR(game, "ghost")
96                         col.itemR(ob, "restrict_render", text="Invisible")
97                         
98                         layout.itemS()
99                         
100                         split = layout.split()
101                         
102                         col = split.column()
103                         col.itemL(text="Attributes:")
104                         col.itemR(game, "mass")
105                         col.itemR(soft, "welding")
106                         col.itemR(soft, "position_iterations")
107                         col.itemR(soft, "linstiff", slider=True)
108                         col.itemR(soft, "dynamic_friction", slider=True)
109                         col.itemR(soft, "margin", slider=True)
110                         col.itemR(soft, "bending_const", text="Bending Constraints")
111                         
112                         
113                         col = split.column()
114                         col.itemR(soft, "shape_match")
115                         sub = col.column()
116                         sub.active = soft.shape_match
117                         sub.itemR(soft, "threshold", slider=True)
118                         
119                         col.itemS()
120                         
121                         col.itemL(text="Cluster Collision:")
122                         col.itemR(soft, "cluster_rigid_to_softbody")
123                         col.itemR(soft, "cluster_soft_to_softbody")
124                         sub  = col.column()
125                         sub.active = (soft.cluster_rigid_to_softbody or soft.cluster_soft_to_softbody)
126                         sub.itemR(soft, "cluster_iterations", text="Iterations")
127                 
128                 elif game.physics_type == 'STATIC':
129                         
130                         col = layout.column()
131                         col.itemR(game, "actor")
132                         col.itemR(game, "ghost")
133                         col.itemR(ob, "restrict_render", text="Invisible")
134                         
135                 elif game.physics_type in ('SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'):
136                         
137                         col = layout.column()
138                         col.itemR(ob, "restrict_render", text="Invisible")
139                         
140 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
141         __label__ = "Collision Bounds"
142
143         def poll(self, context):
144                 ob = context.active_object
145                 game = ob.game
146                 rd = context.scene.render_data
147                 return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
148
149         def draw_header(self, context):
150                 layout = self.layout
151                 
152                 ob = context.active_object
153                 game = ob.game
154
155                 layout.itemR(game, "use_collision_bounds", text="")
156         
157         def draw(self, context):
158                 layout = self.layout
159                 
160                 ob = context.scene.objects[0]
161                 game = ob.game
162                 
163                 layout.active = game.use_collision_bounds
164                 layout.itemR(game, "collision_bounds", text="Bounds")
165                 
166                 row = layout.row()
167                 row.itemR(game, "collision_compound", text="Compound")
168                 row.itemR(game, "collision_margin", text="Margin", slider=True)
169
170 bpy.types.register(PHYSICS_PT_game_physics)
171 bpy.types.register(PHYSICS_PT_game_collision_bounds)
172
173 class SceneButtonsPanel(bpy.types.Panel):
174         __space_type__ = "PROPERTIES"
175         __region_type__ = "WINDOW"
176         __context__ = "scene"
177
178         def poll(self, context):
179                 rd = context.scene.render_data
180                 return (rd.engine == 'BLENDER_GAME')
181
182 class SCENE_PT_game(SceneButtonsPanel):
183         __label__ = "Game"
184
185         def draw(self, context):
186                 layout = self.layout
187                 
188                 rd = context.scene.render_data
189
190                 row = layout.row()
191                 row.itemO("view3d.game_start", text="Start")
192                 row.itemL()
193
194 class SCENE_PT_game_player(SceneButtonsPanel):
195         __label__ = "Player"
196
197         def draw(self, context):
198                 layout = self.layout
199                 
200                 gs = context.scene.game_data
201                 
202                 layout.itemR(gs, "fullscreen")
203
204                 split = layout.split()
205                 
206                 col = split.column()
207                 col.itemL(text="Resolution:")
208                 sub = col.column(align=True)
209                 sub.itemR(gs, "resolution_x", slider=False, text="X")
210                 sub.itemR(gs, "resolution_y", slider=False, text="Y")
211
212                 col = split.column()
213                 col.itemL(text="Quality:")
214                 sub = col.column(align=True)
215                 sub.itemR(gs, "depth", text="Bit Depth", slider=False)
216                 sub.itemR(gs, "frequency", text="FPS", slider=False)
217
218                 # framing:
219                 col = layout.column()
220                 col.itemL(text="Framing:")
221                 col.row().itemR(gs, "framing_type", expand=True)
222                 sub = col.column()
223                 sub.itemR(gs, "framing_color", text="")
224
225 class SCENE_PT_game_stereo(SceneButtonsPanel):
226         __label__ = "Stereo"
227
228         def draw(self, context):
229                 layout = self.layout
230                 
231                 gs = context.scene.game_data
232                 stereo_mode = gs.stereo
233
234                 # stereo options:
235                 layout.itemR(gs, "stereo", expand=True)
236  
237                 # stereo:
238                 if stereo_mode == 'STEREO':
239                         layout.itemR(gs, "stereo_mode")
240                         layout.itemL(text="To do: Focal Length")
241                         layout.itemL(text="To do: Eye Separation")
242
243                 # dome:
244                 elif stereo_mode == 'DOME':
245                         layout.itemR(gs, "dome_mode", text="Dome Type")
246
247                         dome_type = gs.dome_mode
248
249                         split=layout.split()
250
251                         if dome_type == 'FISHEYE' or \
252                            dome_type == 'TRUNCATED_REAR' or \
253                            dome_type == 'TRUNCATED_FRONT':
254                                 
255                                 col=split.column()
256                                 col.itemR(gs, "dome_angle", slider=True)
257                                 col.itemR(gs, "dome_tilt")
258
259                                 col=split.column()
260                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
261                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
262
263                         elif dome_type == 'PANORAM_SPH':
264                                 col=split.column()
265                                 col.itemR(gs, "dome_tesselation", text="Tesselation")
266                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
267
268                         else: # cube map
269                                 col=split.column()
270                                 col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
271                 
272                         layout.itemR(gs, "dome_text")
273
274 bpy.types.register(SCENE_PT_game)
275 bpy.types.register(SCENE_PT_game_player)
276 bpy.types.register(SCENE_PT_game_stereo)
277
278 class WorldButtonsPanel(bpy.types.Panel):
279         __space_type__ = "PROPERTIES"
280         __region_type__ = "WINDOW"
281         __context__ = "world"
282
283         def poll(self, context):
284                 rd = context.scene.render_data
285                 return (rd.engine == 'BLENDER_GAME')
286
287 class WORLD_PT_game_context_world(WorldButtonsPanel):
288         __show_header__ = False
289
290         def poll(self, context):
291                 rd = context.scene.render_data
292                 return (context.scene) and (rd.use_game_engine)
293
294         def draw(self, context):
295                 layout = self.layout
296                 
297                 scene = context.scene
298                 world = context.world
299                 space = context.space_data
300
301                 split = layout.split(percentage=0.65)
302
303                 if scene:
304                         split.template_ID(scene, "world", new="world.new")
305                 elif world:
306                         split.template_ID(space, "pin_id")
307
308 class WORLD_PT_game_world(WorldButtonsPanel):
309         __label__ = "World"
310
311         def draw(self, context):
312                 layout = self.layout
313                 
314                 world = context.world
315
316                 row = layout.row()
317                 row.column().itemR(world, "horizon_color")
318                 row.column().itemR(world, "ambient_color")
319
320                 layout.itemR(world.mist, "enabled", text="Mist")
321
322                 row = layout.column_flow()
323                 row.active = world.mist.enabled
324                 row.itemR(world.mist, "start")
325                 row.itemR(world.mist, "depth")
326
327 class WORLD_PT_game_physics(WorldButtonsPanel):
328         __label__ = "Physics"
329  
330         def draw(self, context):
331                 layout = self.layout
332                 
333                 gs = context.scene.game_data
334                 
335                 layout.itemR(gs, "physics_engine")
336                 if gs.physics_engine != 'NONE':
337                         layout.itemR(gs, "physics_gravity", text="Gravity")
338  
339                         split = layout.split()
340                         
341                         col = split.column()
342                         col.itemL(text="Physics Steps:")
343                         sub = col.column(align=True)
344                         sub.itemR(gs, "physics_step_max", text="Max")
345                         sub.itemR(gs, "physics_step_sub", text="Substeps")
346                         col.itemR(gs, "fps", text="FPS")
347                         
348                         col = split.column()
349                         col.itemL(text="Logic Steps:")
350                         col.itemR(gs, "logic_step_max", text="Max")
351                         
352                         col = layout.column()
353                         col.itemR(gs, "use_occlusion_culling", text="Occlusion Culling")
354                         sub = col.column()
355                         sub.active = gs.use_occlusion_culling
356                         sub.itemR(gs, "occlusion_culling_resolution", text="Resolution")
357
358                 else:
359                         split = layout.split()
360                         
361                         col = split.column()
362                         col.itemL(text="Physics Steps:")
363                         col.itemR(gs, "fps", text="FPS")
364                         
365                         col = split.column()
366                         col.itemL(text="Logic Steps:")
367                         col.itemR(gs, "logic_step_max", text="Max")
368
369 bpy.types.register(WORLD_PT_game_context_world)
370 bpy.types.register(WORLD_PT_game_world)
371 bpy.types.register(WORLD_PT_game_physics)