Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / character-animation-2.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-2: Mixing Cal3D and Soya : Balazar with a sword
20
21
# In this lesson, we add a sword in the right hand of Balazar, the sorcerer of the
22
# previous lesson.
23
# The sword is a Soya object, wich is added inside the Cal3D character, and moves along
24
# with it!
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
# Loads the sorcerer shape.
39
40
sorcerer_shape = soya.Cal3dShape.get("balazar")
41
42
# Creates the sorcerer.
43
# We need the sorcerer to be a World, in order to add other objects in it (= the sword).
44
# The Cal3D volume is now added in the sorcerer world.
45
46
sorcerer = soya.World(scene)
47
sorcerer.rotate_lateral(-120.0)
48
sorcerer_volume = soya.Cal3dVolume(sorcerer, sorcerer_shape)
49
sorcerer_volume.animate_blend_cycle("marche")
50
51
# Creates a right hand world in the sorcerer, and attach it to the bone called 'mainD'
52
# (French abbrev for 'right hand').
53
54
right_hand = soya.World(sorcerer)
55
sorcerer_volume.attach_to_bone(right_hand, "mainD")
56
57
# Creates a right_hand_item Volume, with a sword shape, inside the right hand.
58
59
#sword = soya.World()
60
#soya.Face(sword, [soya.Vertex(sword, 0.0, 0.0, 0.0), soya.Vertex(sword, 0.0, 1.0, 0.0), soya.Vertex(sword, 1.0, 0.0, 0.0)])
61
#epee = soya.Volume(scene, sword.shapify())
62
63
right_hand_item = soya.Volume(right_hand)
64
right_hand_item = soya.Volume(right_hand, soya.Shape.get("sword"))
65
right_hand_item.rotate_incline(180.0)
66
right_hand_item.set_xyz(0.05, 0.1, 0.0)
67
68
# By using right_hand_item.set_shape(...), you can easily replace the sword with an axe
69
# or a gun !
70
# Use Soya system coordinate conversion facilities for collision detection
71
# (e.g. Point(right_hand_item, 0.0, 0.0, -3.0) is the end of the sword)
72
73
camera = soya.Camera(scene)
74
camera.set_xyz(0.0, 1.5, 3.0)
75
76
soya.set_root_widget(widget.Group())
77
soya.root_widget.add(camera)
78
soya.root_widget.add(widget.FPSLabel())
79
80
soya.Light(scene).set_xyz(5.0, 5.0, 8.0)
81
82
soya.Idler(scene).idle()
83