Lighthouse3d.com        VRML Script Tutorial
Full list

VRML Interactive Tutorial

Introduction
VRML File Structure
Drawing: Shape node
Geometry Nodes:
Appearance Let there be Light Materials with Colored Lights
Hierarchical Node Structures
Inlining Files
Defining and Instancing Nodes
Defining Levels of Detail
Events in VRML
 Creating Paths between events: ROUTE Generating Events based on Timers or User Actions Example: Proximity sensor
Interpolators Let the Music Play Bindable Nodes
 Who Am I: NavigationInfo Where Am I: ViewPoint   �

# Extrusion Node

The IndexedFaceSet node although a very powerful node, requires you to define all the faces in the shape. For certain shapes this requires loads of points and faces. For other shapes this is almost impossible. For instance consider designing a sphere with an indexed face set.

Extrusion is a very powerful node which allows you to define very complex shapes using only a small amount of points.

Syntax:
 Extrusion { beginCap TRUE endCap TRUE ccw TRUE convex TRUE creaseAngle 0 crossSection [1 1,1 -1, -1-1, -1 0, 1 1] orientation 0 0 1 0 scale 1 1 solid TRUE spine [0 0 0, 0 1 0] }

The basis of an extruded shape is a 2-D cross section of the final shape. For example, consider a cube. The cross section is a square. Cross sections are defined in the XZ plane. The cross section for a cube could be defined using the following points: Note the Z axis orientation, the Z axis is positive downwards, not upwards. In 3D, using the default View Point this means that points closer to you have a higher Z value than points further away.

Another concept needed in an extrusion is the spine. The spine defines the path that the cross section will travel to create the shape. In the above example, trying to build a cube, one could start with the cross section at (0,-1,0) and move it upwards to (0,1,0). The following figures shows this spine for the cube, and the respective path for the cross section.  The spine in the above figure is defined by two points, (0,-1,0) and (0,1,0). The list of steps that the browser does to draw an extruded shape with two spine points are:
• Translate the cross section to the first spine point
• Reorient the cross section, defined in the XZ plane so that the Y axis coincides with the direction obtained with the two spine points (in the example above this step is not necessary).
• Move the cross section to the last spine point.
• When executing the last step the browser will create the side walls of the cube. The end result is presented in the following figure. Source code for the above figure (without the axes)

Example:
#VRML V2.0 utf8
Transform {
children
Shape{ appearance Appearance { material Material {}}
geometry Extrusion{
crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]
spine [0 -1 0 , 0 1 0 ]}
}
}

The fields beginCap and endCap specify if the extruded shape is open or closed at the ends. For instance if in the above example both endCap and beginCap were set to false the following figure would be produced Notice that you can only see two sides of the cube, the ones that face you. This is because the field solid is set to TRUE by default. Setting this field to false yields the following result In the above examples the spine had only two points. That is the simplest spine you can have. However there is nothing preventing you from having more spine points, for example to draw a V shape, or even something more complicated.

The principle is always the same however there is something which deserves to be mentioned. As mentioned before, when using a two point spine, the cross section is oriented so that the Y axis coincides with the direction defined by the two spine points. When using more spine points this is only valid for the first spine point. The remaining spine points behave slightly differently.

The second and subsequent spine points orient the cross section so that is perpendicular to the tangent of the spine. The following figure, presented in 2D for simplicity reasons, shows the cross section orientation in a 3 point spine. The points in the figure are the spine points. The dotted lines show the path defined by the spine. At each spine point the cross section's orientation is presented. Note that the cross section's orientation for the second point is perpendicular to the spine's tangent.

A V shaped spine, defined by the points: (3,5,0), (0,0,0), (-3,5,0), with the square cross section produces the following result: Source code for the above figure (without the axes)

Example:
#VRML V2.0 utf8
Transform {
children
Shape{ appearance Appearance { material Material {}}
geometry Extrusion{
crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]
spine [3 5 0 , 0 0 0, -3 5 0]}
}
}

Extrusion can also be used to create surfaces of revolution using a circular spine. The following example describes how to build a cone by using extrusion as a surface of revolution.

The cross section is defined by the following points: (-1,0), (0,0), (-2,-1), (-1,0). Note that the cross section repeats the first point, if you don't do that then you may end up with a non-solid shape. The spine is defined by selecting eight equally spread points in a unitary circle. The following figure depicts the cross section (note that the Z axis points downwards), and a circular spine defined in the XY plane.  Please take notice of the cross section points. The point (0,0) is the point that coincides with the spine's point. The end result is the following figure: Source code for the example above (without the axes):

Example:
#VRML V2.0 utf8
Transform {
children
Shape{ appearance Appearance { material Material { }}
geometry Extrusion{
crossSection [ -1 0, 0 0, -1 -2, -1 0]
spine [1 0 0 , 0.707 0 0.707 , 0 0 1 ,-0.707 0 0.707 ,
-1 0 0 ,-0.707 0 -0.707 , 0 0 -1 ,0.707 0 -0.707 ,1 0 0]
}
}
}

Wait, there's still more, you can scale and orient the cross section for each spine point specified. In the cube example presented above, you can scale the cross section for the second spine point by (0,0), thereby reducing it to a point, to obtain a pyramid as in the following figure. When using the field scale you either specify one scale for the whole shape, or a list of scale factors for each spine point ( note that scales are provided in 2D because they relate to the cross section).

Source code for the above figure (without the axes)

Example:
#VRML V2.0 utf8
Transform {
children
Shape{ appearance Appearance { material Material {}}
geometry Extrusion{
crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]
spine [0 -1 0 , 0 1 0 ]
scale [1 1, 0 0]
}
}
}

Or you could twist the spine's path using rotations to obtain the following picture Similarly to the scale field, when using the field orientation you either specify one orientation for the whole shape, or a list of orientation factors for each spine point. Orientations require four values each: three to define the axis of rotation and one to define the angle.

Source code for the above figure (without the axes)

Example:
#VRML V2.0 utf8
Transform {
children
Shape{ appearance Appearance { material Material {}}
geometry Extrusion{
crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]
spine [0 -1 0 , 0 1 0 ]
orientation[0 1 0 0, 0 1 0 3.14]
}
}
}

The ccw field specifies if the points which define the cross section are present counterclockwise, TRUE, or clockwise or unknown order, FALSE.

The convex field specifies if the cross section is convex or not. When presented with concave cross sections, the browser splits the cross section into smaller convex cross sections. This is a time consuming task. If you are sure that the cross section is convex then setting this field to TRUE tells the browser not to worry splitting the cross section therefore saving time.

The creaseAngle specifies an angle threshold. If two adjacent faces make an angle bigger than the creaseAngle then you'll see clearly where the two faces meet, the edge linking the two faces is sharp. Otherwise the edge linking the two faces will be smooth.   