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
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
27
28
29# Import the Soya module.
30
31import sys, os, os.path, soya, soya.facecutter
32
33soya.init()
34soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
35
36# Creates a scene.
37
38scene = 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
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
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
55soya.facecutter.cut(sword2, 80)
56
57# Creates 2 volumes, one for each sword.
58
59volume1 = soya.Volume(scene, sword1.shapify())
60volume1.set_xyz(-1.0, -0.5, 0.0)
61volume1.rotate_vertical(90.0)
62volume1.rotate_lateral (90.0)
63
64volume2 = soya.Volume(scene, sword2.shapify())
65volume2.set_xyz(1.0, -0.5, 0.0)
66volume2.rotate_vertical(90.0)
67volume2.rotate_lateral (90.0)
68
69# Renders the scene in wireframe mode -- it's easier to see the facecutter action
70# in wireframe.
71
72soya.toggle_wireframe()
73
74# Creates a light.
75
76light = soya.Light(scene)
77light.set_xyz(2.0, 5.0, 0.0)
78
79# Creates a camera.
80
81camera = soya.Camera(scene)
82soya.set_root_widget(camera)
83camera.set_xyz(0.0, 0.0, 3.0)
84
85# Starts the main loop.
86
87soya.Idler(scene).idle()
88