Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / facecutter-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
# facecutter-1: Face cutter : a model beautifier
20
21
# The facecutter is a model beautifier : it automatically improves your model by increasing
22
# the number of faces.
23
# On smooth_lit faces, the facecutter performs interpolation, so as the faces really look
24
# smooth (as in this tuto).
25
26
# See soya.facecutter.cut.__doc__ for more info.
27
28
29
# Import the Soya module.
30
31
import sys, os, os.path, soya, soya.facecutter
32
33
soya.init()
34
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
35
36
# Creates a scene.
37
38
scene = soya.World()
39
40
# Loads the sword model twice
41
# (we use 'load' instead of 'get' since get would have returned the same object :
42
# we want 2 DIFFERENT swords, since we are going to modify one of them)
43
44
sword1 = soya.World.load("sword")
45
sword2 = soya.World.load("sword")
46
47
# Cuts at least 80 triangles / quads of the second sword.
48
# Cut triangles / quads are replaced by two triangles, so this mean the sword will have at
49
# least 80 additionnal faces.
50
51
# You can also call the cut fonction by giving the maximum length of the face's edge ;
52
# every edge longer that the given value will be cut :
53
# soya.facecutter.cut(sword2, max_length = 1.0)
54
55
soya.facecutter.cut(sword2, 80)
56
57
# Creates 2 volumes, one for each sword.
58
59
volume1 = soya.Volume(scene, sword1.shapify())
60
volume1.set_xyz(-1.0, -0.5, 0.0)
61
volume1.rotate_vertical(90.0)
62
volume1.rotate_lateral (90.0)
63
64
volume2 = soya.Volume(scene, sword2.shapify())
65
volume2.set_xyz(1.0, -0.5, 0.0)
66
volume2.rotate_vertical(90.0)
67
volume2.rotate_lateral (90.0)
68
69
# Renders the scene in wireframe mode -- it's easier to see the facecutter action
70
# in wireframe.
71
72
soya.toggle_wireframe()
73
74
# Creates a light.
75
76
light = soya.Light(scene)
77
light.set_xyz(2.0, 5.0, 0.0)
78
79
# Creates a camera.
80
81
camera = soya.Camera(scene)
82
soya.set_root_widget(camera)
83
camera.set_xyz(0.0, 0.0, 3.0)
84
85
# Starts the main loop.
86
87
soya.Idler(scene).idle()
88