Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / modeling-smoothlit-1.pyOpen in CoCalc
Author: William A. Stein
1
# Soya 3D tutorial
2
# Copyright (C) 2004 Jean-Baptiste LAMY
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-smoothlit-1: Smooth lit : the sphere and the faceted ball
20
21
# Smooth-lit is one of the most important modeling attribute, but also one of the
22
# most difficult to understand. I hope this tutorial helps ;-)
23
24
# Smooth-lit is used for model that must look smooth, like sphere or characters.
25
# (if you have some 3D technical backgrounds, smooth-lit corresponds to per-vertex normal
26
# vector, instead of per-face normal vector).
27
28
# In Blender, smooth-lit corresponds to the "set smooth" and "set solid" buttons in
29
# the "link and materials" panel.
30
31
32
# Imports and inits Soya (see lesson basic-1.py).
33
34
import sys, os, os.path, soya, soya.sphere
35
36
soya.init()
37
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
38
39
# Creates the scene.
40
41
scene = soya.World()
42
43
# The soya.sphere module contains a Sphere function that creates and returns a World
44
# with several faces inside, organized in a sphere (see soya.sphere.Sphere.__doc__
45
# for more info).
46
# By default, soya.sphere creates smooth-lit faces.
47
48
sphere_world = soya.sphere.Sphere()
49
50
# Creates another sphere.
51
52
faceted_ball_world = soya.sphere.Sphere()
53
54
# By default, faces are not smooth-lit, but soya.sphere adds the smooth-lit
55
# so we must remove it on the faceted ball.
56
# For each face in the faceted ball's children, we set its smooth_lit attributes to 0.
57
58
for face in faceted_ball_world.children:
59
face.smooth_lit = 0
60
61
# Compiles sphere_world and faceted_ball_world into Shape.
62
# Creates a sphere Volume in the scene, using the compilation of sphere_word as Shape.
63
# Notice the use of World.shapify() to compile a World.
64
65
sphere = soya.Volume(scene, sphere_world.shapify())
66
67
# Moves the sphere on the left.
68
69
sphere.x = -1.2
70
71
# Does the same with the faceted ball.
72
73
faceted_ball = soya.Volume(scene, faceted_ball_world.shapify())
74
faceted_ball.x = 1.2
75
76
# Creates a light.
77
78
light = soya.Light(scene)
79
light.set_xyz(0.0, 0.7, 2.0)
80
81
# Creates a camera.
82
83
camera = soya.Camera(scene)
84
camera.set_xyz(0.0, 0.0, 3.5)
85
soya.set_root_widget(camera)
86
87
soya.Idler(scene).idle()
88
89