2
# Copyright (C) 2001-2002 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
18
# Lesson 008: File management : saving materials and worlds
20
# This lesson explains how to save materials and worlds into files.
22
# The Soya file management system assumes that:
23
# - ALL your materials and your worlds are saved in a directory. The directory
24
# (sometimes called "PATH") can be different for worlds and material, or it can
28
# In this lesson, we are going to save the textured cube of the lesson 4.
29
# This implies saving the material, and the cube.
31
import soya, soya.soya3d as soya3d, soya.model as model, soya.cube as cube
32
import os, os.path, sys
36
scene = soya3d.World()
39
# Defines the texture, material and world directories. We use the directory
40
# "./data" in the tutorial directory. You may use 3 different directories.
42
data_dir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "data")
44
model.Image .PATH = os.path.join(data_dir, "images")
45
model.Material.PATH = os.path.join(data_dir, "materials")
46
soya3d.World .PATH = os.path.join(data_dir, "worlds")
47
model.Shape .PATH = os.path.join(data_dir, "shapes")
50
# Creates the textured cube -- see lesson 4
52
material = model.Material()
54
material.tex_filename = "block2.tga"
56
cube = cube.Cube(scene, material)
57
cube.rotate_vertical(30.0)
59
light = soya3d.Light(scene)
60
light.set_xyz(0.0, 0.2, 1.0)
62
camera = soya3d.Camera(scene)
64
soya.set_root_widget(camera)
67
# Defines the material's and the cube's filename. The filename is understood to
68
# be located in the material / world PATH.
70
material.filename = "wall_material"
71
cube .filename = "textured_cube"
74
# Saves the material and the cube -- they'll be saved in the corresponding PATH
75
# The save() method can receive an optional FILENAME parameter, which can be used
76
# to save the object into an arbitrary location.
77
# The ".data" extension is automatically added to the file, but it must not be
78
# present in filenames !!!
89
while 1: time.sleep(0.1)
92
# Notice that, if we had saved the cube without saving the material,
93
# Soya3D would have saved the material along with the cube !!!
95
# Saving the material in a separed file is interesting, though: it allows several
96
# worlds to share the same materials.
98
# The availables() methods of the Material / World class can be used to get a list
99
# of the names of all the available Materials / Worlds.