Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / modeling-env-mapping-1.pyOpen in CoCalc
Author: William A. Stein
1
# Soya 3D tutorial
2
# Copyright (C) 2004 Thomas Paviot
3
#
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.
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-env-mapping-1: Environment Mapping
20
21
# Environment Mapping can be used to simulate reflection, using a particular texture
22
# called a "sphere map".
23
# You can create such texture from a panorama using e.g. the Polar coordinate
24
# effect of Gimp.
25
26
27
# Imports and inits Soya (see lesson basic-1.py).
28
29
import sys, os, os.path, soya, soya.sphere,soya.cube
30
31
soya.init()
32
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
33
34
# Creates the scene.
35
36
scene = soya.World()
37
38
material = soya.Material()
39
material.environment_mapping = 1 # Specifies environment mapping is active
40
material.texture = soya.Image.get("sphere_map.jpg")# The textured sphere map
41
42
ball_world=soya.sphere.Sphere()
43
faceted_ball_world = soya.sphere.Sphere()
44
cube_world=soya.cube.Cube()
45
46
# Sets the material to each face
47
for face in faceted_ball_world.children:
48
face.smooth_lit=0
49
face.material=material
50
for face in ball_world.children:
51
face.smooth_lit=1
52
face.material=material
53
for face in cube_world.children:
54
face.smooth_lit=0
55
face.material=material
56
57
class RotatingVolume(soya.Volume):
58
def advance_time(self, proportion):
59
self.rotate_lateral(2.0 * proportion)
60
61
62
ball = RotatingVolume(scene, ball_world .shapify())
63
cube = RotatingVolume(scene, cube_world .shapify())
64
faceted_ball = RotatingVolume(scene, faceted_ball_world.shapify())
65
ball.x = -1
66
ball.y = 1
67
cube.x = 1.2
68
cube.y = 0.5
69
faceted_ball.y = -1
70
71
72
# Creates a light.
73
74
light = soya.Light(scene)
75
light.set_xyz(0.0, 0.7, 2.0)
76
77
# Creates a camera.
78
79
camera = soya.Camera(scene)
80
camera.set_xyz(0.0, 0.0, 3.5)
81
soya.set_root_widget(camera)
82
83
soya.Idler(scene).idle()
84
85