2
# Copyright (C) 2001-2002 Bertrand 'blam!' LAMY
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.
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.
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
19
# ---------------------------------------------------
20
# Lesson 110: Shape and visibility computation (Tree)
21
# ---------------------------------------------------
23
# We will see in this tutorial some technics to speed up rendering
24
# of big Shapes (like the Shape of a level)
37
scene = soya.soya3d.World()
40
light = soya.soya3d.Light(scene)
41
light.set_xyz(0.0, 10.0, 0.0)
43
# Create a world and add some randomized triangles
44
world = soya.soya3d.World()
47
x = random.random() * 10.0
49
z = random.random() * 10.0
50
v1 = soya.model.Vertex (world, x + random.random() * 2.0, y + random.random() * 2.0, z + random.random() * 2.0)
51
v2 = soya.model.Vertex (world, x + random.random() * 2.0, y + random.random() * 2.0, z + random.random() * 2.0)
52
v3 = soya.model.Vertex (world, x + random.random() * 2.0, y + random.random() * 2.0, z + random.random() * 2.0)
53
f = soya.model.Face (world, [v1, v2, v3])
57
# Create the Shape from the world
58
shape = world.shapify()
63
# Construct a sphere tree with all the faces of the shape.
70
# Optimize the tree (try to have a more balanced tree).
71
# For now there are 2 modes of optimization.
74
# This value is used by all the mode of optimization. It means that the
75
# children sphere must have a radius inferior than the parent radius multiplied
76
# by collapse else the child and parent are gathered.
78
# Mode 0: fast. Take 1 parameter: the maximum children radius expressed in percentage
79
# of the parent radius.
80
max_children_radius_percent = 0.5
81
shape._optimize_tree(collapse, 0, max_children_radius_percent)
83
# Mode 0: slow but compute the best possible tree. Take no parameter.
84
shape._optimize_tree(collapse, 1)
87
scene.set_shape(shape)
90
# If you always want to build a tree when your World is turned to Shape, you can
91
# use the shapify_args:
92
world.shapify_args=('tree', { "collapse":0.9, "mode":0, "params":[0.5] })
93
shape = world.shapify()
94
# This shape will have a Tree
95
scene.set_shape(shape)
98
# Add a camera and a loop to render
99
camera = soya.soya3d.Camera(scene)
100
camera.set_xyz(10.0, 2.0, 10.0)
101
camera.look_at(soya.soya3d.Point(scene, 0.0, 0.0, 0.0))
102
soya.set_root_widget(camera)