Overview
Indexed Face Sets are our Friends
The geometric primitives (Box, Cone, Sphere, etc) are very useful. Much of what we encounter in visual
reality may be decomposed into groups of geometric primitives for reconstruction in virtual reality. However,
irregular surfaces are difficult at best with geometric primitives (even with uneven deformation). The
IndexedFaceSet node is our solution to this problem. By using these nodes, we can build irregular
surfaces.
That pyramid to the right is pretty simple. It is just five faces drawn to join five points together. Because we just want it to be visible from the outside, we draw between the points in a counter-clockwise direction. We end the instructions to draw each face with a minus-one ( -1 ). We also declare it to be solid, as a hint to the rendering engine on the client.
Details of the Week: Indexed Face Set
Creating Non-Uniform Surfaces
you can also access the full code for this simple example use of an IndexedFaceSet node.
<IndexedFaceSet solid="true">
<coord>
-2.0 0.0 2.0
-2.0 0.0 -2.0
2.0 0.0 -2.0
2.0 0.0 2.0
0.0 2.0 0.0
</coord>
<coordIndex>
0 1 2 3 -1
0 4 1 -1
1 4 2 -1
2 4 3 -1
3 4 0 -1
</coordIndex>
</IndexedFaceSet>
Things to Notice
Note how we define the coordinates of the points to connect with a coord element. Note how we define the lines to draw between the points to form the edges of the surfaces by listing the coordIndex sequence. Note that the index of coordinates starts with zero. Note how we end each sequence of edge-line drawing instructions with a minus-one. This indicates we are done defining the edges of that face, and that the client rendering engine should draw the final line (the one that closes off the surface of the face) from the end-point of the last line drawn to the begin-point of the first line drawn.
Example Uses of IndexedFaceSet Nodes
Here is the complete code for our example pyramid:
<?xml version="1.0" encoding="UTF-8"?>
<World xmlns="http://www.xvrml.net/schemas/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xvrml.net/schemas/core http://www.xvrml.net/schemas/xVRML.xsd">
<WorldInfo>
<title>IndexedFaceSet Example</title>
<info>Example of an IndexedFaceSet</info>
<info>converted from VRML97 example at</info>
<info>http://www.cs.iupui.edu/~aharris/mm/vrml4/vrml4.html</info>
</WorldInfo>
<AvatarList>
<Avatar name="default" navigation="ANY">
<children/>
</Avatar>
</AvatarList>
<children>
<Shape>
<appearance>
<Material>
<diffuseColor red="0.75" green="0.5" blue="0.25"/>
</Material>
</appearance>
<geometry>
<IndexedFaceSet solid="true">
<coord>
-2.0 0.0 2.0
-2.0 0.0 -2.0
2.0 0.0 -2.0
2.0 0.0 2.0
0.0 2.0 0.0
</coord>
<coordIndex>
0 1 2 3 -1
0 4 1 -1
1 4 2 -1
2 4 3 -1
3 4 0 -1
</coordIndex>
</IndexedFaceSet>
</geometry>
</Shape>
</children>
</World>
In-Class Exercises
Developing IndexedFaceSet Elements "By Hand"
One: Class-As-a-Whole Exercise
Design & Build a Wall with One Door and Two Windows
The instructor will lead the class through an exercise to design and build an IndexedFaceSet-based standard wall object together.
Two: Individual Exercise
Design & Build a Box With an Open Top
Design on paper a box with five sides (left, right, back, front, bottom), but no top. That means it will need to have faces drawn for the insides, and faces drawn for the outside as well. Sketch the box, labeling the points needed with their coordinates. Draw in arrows indicating the directions in which the lines should be drawn. Show it to the instructor.
Build, Post, & Test
Build what you just designed, and post it to the following URI:
http://www.rit.edu/~yourUserID/VR/IFS_exercise.xwrl
(where ~yourUserID is replaced by your grace user ID)