Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / modeling-solid-shape-1.pyOpen in CoCalc
Author: William A. Stein
1# Soya 3D tutorial
2# Copyright (C) 2001-2004 Jean-Baptiste LAMY
3#
4# This program is free software; you can redistribute it and/or modify
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19# modeling-solid-shape-1: Solid Shape : the cutted cube
20
21# Solid shapes are similar to simple shapes, but when they are cut by the camera front,
22# plane the section is drawn, so as they appear as "solid / plain" and not "empty".
23
24# Solid shapes are slower than simple shape, thus you should use them only
25# when the shape is often cut by the camera. They are usefull for light effect, e.g.
26# light cones,...
27
28
29# Imports and inits Soya (see lesson basic-1.py).
30
31import sys, os, os.path, soya, soya.cube
32
33soya.init()
34soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
35
36# Creates the scene.
37
38scene = soya.World()
39
40# Creates a normal cube world
41
42empty_cube_world = soya.cube.Cube()
43
44# Creates a cube world that will yield a solid shape
45# (solid shapes can only be used on shapes, NOT with faces)
46
47solid_cube_world = soya.cube.Cube()
48solid_cube_world.shapifier = soya.SolidShapifier()
49
50
51# Creates a volume using the normal cube
52
53empty_cube = soya.Volume(scene, empty_cube_world.shapify())
54empty_cube.x = -1.0
55empty_cube.rotate_lateral (45.0)
56empty_cube.rotate_vertical(45.0)
57
58# Creates a volume using the solid shape cube
59
60solid_cube = soya.Volume(scene, solid_cube_world.shapify())
61solid_cube.x =  1.0
62solid_cube.rotate_lateral (45.0)
63solid_cube.rotate_vertical(45.0)
64
65
66# Creates a light.
67
68light = soya.Light(scene)
69light.set_xyz(1.0, 0.7, 1.0)
70
71# Creates a camera.
72
73camera = soya.Camera(scene)
74camera.set_xyz(0.0, 0.0, 3.0)
75
76# Increases the camera's front plane, in order to cut the two cubes.
77
78camera.front = 2.5
79
80soya.set_root_widget(camera)
81
82soya.Idler(scene).idle()
83
84