VRML 2.0 provides a number of powerful nodes that allow the artist to do complex modeling and interactions. One of the least used, but more powerful nodes, is the Extrusion node. The Extrusion node defines a 2D polygon along the X and Z axes that is then swept out along a path through space. It is an excellent way to produce fairly complex geometry and often more efficient than an IndexedFaceSet.
Here's the syntax for an Extrusion, an illustration and a VRML file. If you're familiar with the fields of the average VRML primitive, some of these fields may seem new to you, but we'll examine them in detail later on...
spine [ 0 0 0, 0 1 0 ] crossSection [ 1 1, 1 -1, -1 -1, -1 1, 1 1 ] scale [ 1 1 ] orientation [ 0 0 1 0 ] beginCap TRUE endCap TRUE ccw TRUE solid TRUE convex TRUE creaseAngle 0}
As you can see, the default Extrusion is little more than a box-like object, one unit tall, and 2 units in width and depth. As shown in the illustration above, the key ingredients of the Extrusion are the fields crossSection and spine. The crossSection is the series of vertices specified along the xz plane (note that there are four vertices listed, with a fifth to close off the shape). The spine is the series of xyz coordinates that describe the path upon which the crossSection shape will be extruded in space.
By taking the above, and adding some additional vertices to the crossSection, we can make the shape a bit more interesting...
crossSection [ 1 0, 0.7 -0.7, 0 -1, -0.7 -0.7, -1 0, -0.7 0.7, 0 1, 0.7 0.7, 1 0 ]
...and create an octagon. Note in the illustration that the points are ordered counterclockwise, hence the ccw = TRUE field in the default node.
One advantage of the extrusion node over the more complex IndexedFaceSet is the way in which you can smooth out the shape by using the creaseAngle field. By default, the shape will appear very faceted. creaseAngle allows you to specify a value in radians (between 0 and 3.142) that will make the edge between two faces appear smoother. By changing the value to, say, 1.62 (about 92 degrees), you can create a fairly smooth transition between the faces. The beginCap and endCap fields allow you to specify whether or not you want a polygon "sealing" the bottom and top (respectively) of the shape. In general, if you set either or both of these to FALSE (no caps), then you'll want to change the solid field to FALSE as well. Like any VRML shape with the solid field (or primitives, which are always solid), solid=TRUE tells the browser not to bother rendering the inside of the object. If you remove the caps of the Extrusion, though, you'll probably want to be able to see the inside. Here is an example of the Extrusion we've been building taken a few steps further... smoothed out with creaseAngle, the endCap removed, and solid set to FALSE (note: Cosmo Player beta 3a ignored the creaseAngle setting, but Cosmo beta5a in Netscape Communicator renders it correctly).
Up to this point, we haven't done anything with the spine field, which actually extrudes the shape of the object outwards. Let's add an additional set of coordinates, 0 2 0, stretching one further unit up the y axis. At the same time, let's look at the scale field. The scale field represents factors in the x and z directions, has its corresponding point specified in the spine field, and is applied to the crossSection at that spine point. Therefore, an Extrusion with the following values:
spine [ 0 0 0, 0 1 0, 0 2 0 ] scale [ 1 1, 0.3 0.3, 1 1 ]
would result in an goblet shape like that pictured here. The first and third set of points in the spine would look just like the crossSection as given, but the second joint in the spine would be scaled down by 0.3 in x and z.
Like the scale field, the orientation field is applied to the crossSection at its corresponding joint in the spine. So, if we wanted to twist the very top of this shape, we could give orientation a value like:
orientation [ 0 0 1 0, 0 0 1 0, 0 1 0 1.0472 ]
and see the shape change accordingly. Each value of orientation specifies a rotation in terms of the xyz axes, and is expressed in radians. In this example, the top was rotated counterclockwise around the y axis about 60 degrees.
An alternate approach to the Extrusion node is to use a closed spine and an unusual crossSection to sculpt a shape much like one would with a lathe. In this example, the spine is a closed circle, and the crossSection is like half a profile of the object. The spine sweeps the crossSection around, resulting in a fountain shape. The code for the spine and crossSection are a bit complex, but can be examined via the previous link. A couple of things worth noting, though. First, the whole shape is inside a Transform to rotate the object into an "upright" position. Also, note that there is only one entry each for the orientation and scale fields. If only one value is specified for these fields, it applies to all the joints of the spine.
In this example, Extrusion was used to create the limbs and torso of this walking alien, a file that is only 11kb without compression (2.2 g-zipped!). In addition, because you can ROUTE events to the spine, crossSection, scale and orientation fields of Extrusion, it's possible to create morphing, animated objects.
There really are all sorts of unusual things that can be done with Extrusion, so the best thing to do is experiment!
Robert W. Saint John is Administrator of VRML Development (nope, no clue what that means!) for Integrated Data Systems in San Francisco. He spends his days cranking out VRML worlds with V-Realm Builder 2.0 and struggling to find new and interesting things to say in his bio. His recent articles on VRML have appeared in VRMLSite magazine and ZDNet, and he is currently working on a VRML 2.0 online course.
1996 Silicon Graphics, Inc. All Rights Reserved.|
Comments: email@example.com or firstname.lastname@example.org