1# Soya 3D tutorial
2# Copyright (C) 2001-2004 Jean-Baptiste LAMY
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
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.
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
19# modeling-2: Shape : displaying two pyramids
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.
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.
29# Imports and inits Soya.
31import sys, os, os.path, soya
36# Creates the scene.
38scene = soya.World()
40# Loads the pyramid model that we have created and saved in the modeling-basic-1.py
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.
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.
50pyramid_model = soya.Shape.get("pyramid")
52# Creates a Volume in the scene, that displays the pyramid.
54pyramid1 = soya.Volume(scene, pyramid_model)
56# Moves and rotates the pyramid (for a better view)
58pyramid1.x = -0.7
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).
65pyramid2 = soya.Volume(scene, pyramid_model)
66pyramid2.x = 0.8
69# Creates a light.
71light = soya.Light(scene)
72light.set_xyz(1.0, 0.7, 1.0)
74# Creates a camera.
76camera = soya.Camera(scene)
77camera.set_xyz(0.0, -0.6, 2.0)