Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / character-animation-1.pyOpen in CoCalc
Author: William A. Stein
1# Soya 3D tutorial
2# Copyright (C) 2001-2004 Jean-Baptiste LAMY
3#
4# This program is free software; you can redistribute it and/or modify
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-1: Character animation with Cal3D : here comes Balazar the Sorcerer !
20
21
22# Or how to write a Cal3D viewer in less that 20 lines...
23
24# For information, this character has been created in Blender and exported to Cal3D
25# with my Blender2Cal3D script: http://oomadness.nekeme.net/en/blender2cal3d/index.html
26
27# See Cal3D documentation for more info, and Cal3dShape and Cal3dVolume docstrings for
29
30
31# Imports and inits Soya.
32
33import sys, os, os.path, soya, soya.widget as widget
34
35soya.init()
36soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
37
38# Creates the scene.
39
40scene = soya.World()
41
43# Cal3D shapes are saved in the 'shapes' subdirectory of soya.path ; each cal3d model
44# is a subdirectory and not a file (see tutorial/data/shapes/balazar). It contains
45# skeleton, animation, mesh and material files, and a ".cfg" file with the same name
46# that the subdirectory.
47
48# You can also use cal3d.parse_cfg_file(filename).
49
50sorcerer_shape = soya.Cal3dShape.get("balazar")
51
52# You can get the list of available mesh and animation names
53# as following:
54
55print "Available meshes    :", sorcerer_shape.meshes    .keys()
56print "Available animations:", sorcerer_shape.animations.keys()
57
58# Creates a Cal3D volume, using the sorcerer_shape.
59# See the docstrings of the soya.cal3d module to learn about mesh attachment and
60# detachment possibilities (see Volume.__init__, Volume.attach and Volume.detach).
61# It can be used e.g. for dismembering, or changing the weapon of a character.
62
63sorcerer = soya.Cal3dVolume(scene, sorcerer_shape)
64
65# Rotates Balazar the sorcerer
66
67sorcerer.rotate_lateral(-120.0)
68
69# Starts playing the animation called "marche" in cycle ("marche" is the French for walk).
70
71sorcerer.animate_blend_cycle("marche")
72
73# To stop playing the animation:
74#
75#sorcerer.animate_clear_cycle("marche")
76#
77# For non-cyclic movment, do:
78#
79#sorcerer.animate_execute_action("marche")
80#
82
83
84# Adds a camera, an FPS label, a light and starts the main loop.
85
86camera = soya.Camera(scene)
87camera.set_xyz(0.0, 1.5, 3.0)
88
89soya.set_root_widget(widget.Group())