VRML : Shapes

Generally speaking, in VRML the shapes can be split into 2 groups: "ready-made" shapes, and author-defined shapes. The ready-made shape nodes are AsciiText, Cone, Cube, Cylinder, and Sphere. The author-defined shape nodes are IndexedFaceSet, IndexedLineSet, and PointSet. All shapes are affected by the current cumulative transformation and rotation values. All shapes are drawn using the most recent material definition. It is very easy for a shape to end up in the wrong place unless you carefully use Separator nodes. For info on the transformation and rotation nodes, see the Transformations topic. For info on the material nodes, see theMaterials and Separators topic.


Ready-Made Shapes
AsciiText
The AsciiText node produces characters from the ASCII character set. You specify the text under the string parameter. The first line of text appears with it's baseline at (0,0,0), with additional strings drawn below, with y decreasing by size * spacing (the "size" value is set under the FontStyle node). The justification parameter is used to state wether the LEFT, RIGHT, or CENTER of the string is located at x = 0. The width parameter gives a suggested width for the text, and it's default value is the natural width of the string. A 0 for this parameter uses the natural width of the text.
ParameterDefault Value Data Type
string"" String
spacing1.0 Float
justificationLEFTEnumerated - LEFT | RIGHT | CENTER
width0 Float

Example: drawing the word "hello".

AsciiText {
	string "hello"
}
Cone
This creates a cone with it's central axis lying along the y axis. The bottomRadius parameter sets the radius of the bottom of the cone. The height parameter sets the height, from apex to base, of the cone. The parts parameter defines which parts of the cone are drawn. The Cone is always drawn with it's center at (0,0,0), so use transformations and rotations to get it to where it is wanted. The apex of the cone is by default at the top (i.e. +ve y), and the default height is 2, making the base of the cone at y = -1.
ParameterDefault Value Data Type
bottomRadius1.0Float
height2.0 Float
partsALLEnumerated - ALL | BOTTOM | SIDES

Example: a cone 0.5 units tall, and with radius of 2 (very flat!).

Cone {
	bottomRadius 2
	height 0.5
}
Cube
Creates a cuboid with each face parallel to one of the axes. The width, height, and depth parameters control the dimensions of the object. The cube will be centered at (0,0,0). The default dimensions of the cube are 2 in each dimension (i.e. from -1 to +1 in each direction). As with all objects, use transformations and rotations to get the cube where you want it.
ParameterDefault Value Data Type
depth2.0 Float
height2.0 Float
width2.0 Float

Example: A concrete slab (large and thin cuboid).

Cube {
	depth 10
	height 0.5
	width 10
}
Cylinder
This node creates a cylinder (or tube) centered on the y axis. The height parameter defines the height of the cylinder (or length of the tube). The radius parameter defines the radius of the cylinder (or how fat the tube is). The parts parameter selects which parts of the cylinder are to be draw, selecting from SIDES, TOP, BOTTOM, and ALL. The TOP will be the "cap" at the positive y end. The cylinder is drawn centered at (0,0,0), and has a default height of 2 (i.e. from y = -1 to y = +1), and default radius of 2.
ParameterDefault Value Data Type
height2.0 Float
partsALLEnumerated - ALL | BOTTOM | SIDES | TOP
radius1.0 Float

Example: a coin (a very flat, wide cylinder).

Cylinder {
	height 0.1
	radius 2
}
Sphere
Draws a sphere (or ball) centered at (0,0,0). The radius parameter specifies the radius of the sphere. Obviously, a sphere does not look differant if rotated, so a single transformation is all that is needed to get it into the desired position.
ParameterDefault Value Data Type
radius1.0 Float

Example: a marble.

Sphere {
	radius 0.4
}

Author-Defined Shapes
Of the 3 available author-defined shapes, only the first two are of any practical use. You should note that creating objects using these functions is not easy, and will require a fair amount of tweaking until it works. All three methods use "points" that must be defined before the methods are used. To do this, you must use the Coordinate3 function as described below.
Coordinate3
Defines a series of points in 3-dimensional space, for use with one of methods below. You should note that this node doesn't actually produce any visable result, but must be used with IndexedFaceSet, IndexedLineSet, or PointSet to actually draw a shape. The first coordinate has in index of 0, the 2nd has an index of 1 etc. The last coordinate therefore has an index of (n - 1). If you use this node more than once, then upon reaching the second occurance, all the points in the first set will be replaced by those in the second set, not appended to. The first set is therfore lost. Remember that if you are defining more that one point, you must enclose the list in square brackets.
ParameterDefault Value Data Type
point0 0 0MVector3D

Example: Define the coordinates of a triangle.

Coordinate3 {
	point [0 0 0, 1 2 0, 2 0 0]
}
IndexedFaceSet
This node is arguably the most useful of the 3 available author-defined shapes. This node builds a set of polygon faces using the coordinates defined in the Coordinate3 node. You achieve this by specifying the corners of each polygon, using the index of the point as defined in the Coordinate3 node. To end each polygon, use an index of -1. For example, to build a face from the 1st, 2nd, 8th, and 11th points as defined in a Coordinate3 declaration, you would add this line under the coordIndex parameter :
coordIndex [0, 1, 7, 10, -1]
There are 3 other parameters that can be used with this node, but they are excluded here, basically because they are not that important or useful.
ParameterDefault Value Data Type
coordIndex0MLong

Example: Draw the triangle defined in Coordinate3.

Coordinate3 {
	point [0 0 0, 1 2 0, 2 0 0]
}

IndexedFaceSet {
	coordIndex [0, 1, 2, -1]
}
IndexedLineSet
Similar to IndexedFaceSet, except that instead of producing faces/polygons, this produces "polylines". This basically means a wire-frame version of what IndexedFaceSet produces. Apart from it's name, the node has exactly the same parameters, and behaves in the same way. Again, three unimportant and relatively complicated parameters have been left out.
ParameterDefault Value Data Type
coordIndex0MLong

Example: Draw a wire-frame version of the triangle drawn above.

Coordinate3 {
	point [0 0 0, 1 2 0, 2 0 0]
}

IndexedLineSet {
	coordIndex [0, 1, 2, -1]
}
PointSet
I can't think of any useful purpose for this node, and under the Netscape plugin, it produces no visable output. This node represents a set of points at the coordinates in the most recent Coordinate3 statement. The startIndex parameter defines the index of the first point to plot. The numPoints parameter defines how many points are to be plotted. A value of -1 here uses all the available points.
ParameterDefault Value Data Type
startIndex0 Long
numPoints-1 Long

Example: Plot the corners of the triangle.

Coordinate3 {
	point [0 0 0, 1 2 0, 2 0 0]
}

PointSet {
	startIndex 0
	numPoints -1
}

Next Topic (Cameras and Lights)
Previous Topic (Data Types)
Back to the VRML Reference
Back to the Main Page

©Tom Thurston, 1997
Please feel free to use and redistribute this NONcommercially!