CoCalc Public Fileswww / talks / 2006-05-09-sage-digipen / tutorial / modeling-2.py
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-2: Shape : displaying two pyramids
20
21# The pyramid model we create in the previous lesson was still in a scratchy form :
22# all faces and vertices were python object, and were rendered individually, which
23# implies a performance lost.
24
25# In this lesson we'll see how to "compile" our pyramid model into a Shape,
26# and how to use it in the same way we use the sword model in the basic-1.py lesson.
27
28
29# Imports and inits Soya.
30
31import sys, os, os.path, soya
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# Loads the pyramid model that we have created and saved in the modeling-basic-1.py
41# lesson.
42# We ask Soya for s Shape called "pyramid", though it does not exist ! Remember, we have
43# created a World pyramid, not a Shape. In this case, Shape.get automatically loads the
44# pyramid World, compiles it into a Shape, and saves the Shape in the "./shapes" directory
45# in soya.path[0].
46# Soya Shape compilation behaves like Python compilation of .py files in .pyc : whenever
47# the World file is changed, Shape.get will recompile it automatically.
48# You can also use the World.shapify() to compile a World into a Shape without saving it.
49
50pyramid_model = soya.Shape.get("pyramid")
51
52# Creates a Volume in the scene, that displays the pyramid.
53
54pyramid1 = soya.Volume(scene, pyramid_model)
55
56# Moves and rotates the pyramid (for a better view)
57
58pyramid1.x = -0.7
59pyramid1.rotate_lateral(60.0)
60
61# Creates a second pyramid. Contrary to World, Shape model can be displayed several
62# time at different position.
63# Soya separates the model part (the Shape) from the position part (the Volume).
64
65pyramid2 = soya.Volume(scene, pyramid_model)
66pyramid2.x = 0.8
67pyramid2.rotate_lateral(45.0)
68
69# Creates a light.
70
71light = soya.Light(scene)
72light.set_xyz(1.0, 0.7, 1.0)
73
74# Creates a camera.
75
76camera = soya.Camera(scene)
77camera.set_xyz(0.0, -0.6, 2.0)
78soya.set_root_widget(camera)
79
80soya.Idler(scene).idle()
81
82