Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / character-animation-shadow-cellshading-1.pyOpen in CoCalc
Author: William A. Stein
1
# Soya 3D tutorial
2
# Copyright (C) 2001-2002 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
# character-animation-shadow-cellshading-1: shadowed and cellshaded Cal3D animated character
20
21
# In this lesson, we add shadow and cell-shading to Balazar.
22
#
23
# See lessons modeling-shadow and modeling-cellshading for more info on shadow or
24
# cell-shading.
25
26
27
# Imports and inits Soya.
28
29
import sys, os, os.path, soya, soya.widget as widget
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
# Set up an atmosphere, so as the background is gray (in order to see the black outline
39
# of the cell-shading).
40
41
scene.atmosphere = soya.Atmosphere()
42
scene.atmosphere.bg_color = (0.6, 0.6, 0.6, 1.0)
43
44
# Loads the sorcerer shape.
45
46
sorcerer_shape = soya.Cal3dShape.get("balazar")
47
48
# Enables shadows on Balazar !
49
50
sorcerer_shape.shadow = 1
51
52
# Enables cell-shading on Balazar !
53
# Arguments (all are optional):
54
# - shader (defaults to soya.SHADER_DEFAULT_MATERIAL)
55
# - outline_color (defaults to black)
56
# - outline_width (defaults to 4.0)
57
# - outline_attenuation (defaults to 0.3)
58
#
59
# See lesson modeling-cellshading-1 for more info on these parameters
60
61
sorcerer_shape.set_cellshading()
62
63
# Notice that you can also add the following attribute in the Cal3D .cfg file (e.g.
64
# balazar/balazar.cfg) :
65
#
66
#double_sided=1
67
#shadow=1
68
#cellshading=1
69
#cellshading_outline_color=1.0, 1.0, 1.0, 1.0
70
#cellshading_outline_width=4.0
71
#cellshading_outline_attenuation=0.0
72
#
73
# double_sided draws the Cal3D shape with double sided face (equivalent to
74
# Face.double_sided). Other attributes have obvious meaning!
75
#
76
# And remember : don't put ANY space before or after the "=" !
77
78
# Create a sorcerer volume
79
80
sorcerer = soya.Cal3dVolume(scene, sorcerer_shape)
81
82
# Rotates Balazar the sorcerer
83
84
sorcerer.rotate_lateral(-120.0)
85
86
# Starts playing the animation called "marche" in cycle ("marche" is the French for walk).
87
88
sorcerer.animate_blend_cycle("marche")
89
90
91
# Creates a wall, to receive the shadow.
92
# Notice that the wall can be any object (including e.g. a landscape,...) : receiving
93
# shadows doesn't require any particular property.
94
95
wall_model = soya.World()
96
wall_face = soya.Face(wall_model, [
97
soya.Vertex(wall_model, -5.0, 0.0, -5.0),
98
soya.Vertex(wall_model, -5.0, 0.0, 5.0),
99
soya.Vertex(wall_model, 5.0, 0.0, 5.0),
100
soya.Vertex(wall_model, 5.0, 0.0, -5.0),
101
])
102
wall_face.double_sided = 1
103
wall = soya.Volume(scene, wall_model.shapify())
104
wall.set_xyz(-1.0, 0.0, 0.0)
105
106
# Adds a camera and a light and starts the main loop.
107
108
light = soya.Light(scene)
109
light.set_xyz(2.0, 5.0, -1.0)
110
light.cast_shadow = 1
111
light.shadow_color = (0.0, 0.0, 0.0, 0.5)
112
113
camera = soya.Camera(scene)
114
camera.set_xyz(0.0, 1.0, 4.0)
115
116
soya.set_root_widget(camera)
117
118
soya.Idler(scene).idle()
119