VRML : Materials and Separators
You can apply both materials and textures to objects in your VRML world.
Materials are easier, mean the user has to download less data (usually),
and are probably quicker to render (draw to the screen). Due to these
reasons, I'm only going to discuss materials here. The topic of Separators
doesn't really fit with materials, but it is of such importance that it
can't be left till later!
Materials
- Material
- The Material node defines the current default material for your world.
All shapes drawn after a node are drawn using that material. Differant
objects "use" materials in a differant manner. You should also bear in
mind that differant browsers will give slightly different results for the
same values. Both the
shininess
and transparency
parameters are self explanitory. The 4 differant colour
parameters may seem a litte confusing. If you just want a fairly standard
colour, set the diffuseColor
parameter, and leave the rest
blank. It is possible to define more than 1 material with this node,
but this isn't often neccisary or desireable.
Example: define a nice shiny green material.
Material {
ambientColor 0.0 0.4 0.0
diffuseColor 0.0 1.0 0.0
shininess 0.7
}
- MaterialBinding
- Defines how a material is applied to objects. This node isn't very
important, and certainly doesn't need to be used. If you specify more that
one material in the
Material
node, then this node defines how
these various materials are put onto a shape. Generally speaking, it
defines how the various materials are cycled. The best way to use this is
by trial and error. For a more detailed description, I recomend you use
a book or other available internet material.This node has no
effect when you only define a single material in a
Material
node statement.
Parameter | Default Value |
Data Type |
value | DEFAULT | Enumerated - DEFAULT | OVERALL | PER_PART
| PER_PART_INDEXED | PER_FACE | PER_FACE_INDEXED | PER_VERTEX |
PER_VERTEX_INDEXED |
Example: Cycle the 3 primary colours over different faces of a cube.
Material {
diffuseColor [1 0 0, 0 1 0, 0 0 1]
ambientColor [0.3 0 0, 0 0.3 0, 0 0 0.3]
}
MaterialBinding {
value PER_FACE
}
Cube {}
Separators
Separators are basically essential in VRML files. Why? Because otherwise
the cumulative effects of many objects build up and make it near imposible
to work out what's what. It also offers a degree of control. For example,
a light placed under a Separator
node will only affect the
objects created under that separator. More importantly, as each
VRML file is only allowed one node, it must be one of these nodes as they
are allowed to contain other nodes.
- Separator
- This node basically saves the current state (i.e. material, lighting,
transformation etc.) when it is encountered, and restores the state once it
is closed. This is a useful way to reset the transformation and rotation
values. It has one parameter, but this is not in the scope of this
discusion, and I have certainly never found any need to use it.
Example: place a cube at (4,4,4) and a cylinder at (-2,0,-1), with it's
central axis along the x axis.
Separator {
Translation {
translation -2 0 -1
}
Rotation {
rotation 0 0 1 1.570796
}
Cylinder {}
}
#-----Upon reaching the '}' above, the translation and rotation values
#-----are lost, so the axes are the 'right-way-round' again.
Separator {
Transformation {
transformation 4 4 4
}
Cube {}
}
- TransformSeparator
- Similar to the
Separator
node, but this node only restores
the transformation values upon it's termination. In other words, materials
or lights inside a TransformSeparator
will affect nodes
appearing outside and after this node, whereas they wouldn't if they were
placed inside a Separator
node.
Example: the first cube in this world will appear blue, as will the next,
but the last will appear red.
Material {
diffuseColor 0 0 1
}
Cube {}
Separator {
Material {
diffuseColor 1 0 0
}
} #<<<<---"Red" material is lost here.
Cube {}
TransformSeparator {
Material {
diffuseColor 1 0 0
}
} #<<<<---This time, "red" is kept.
Cube {}
- SpinGroup
- A really usefull node, but one that should be used carefully. It
basically spins every object inside it in an author defineable manner. It
has one parameter,
rotation
which specifies the axis and rate
of spin.
Parameter | Default Value |
Data Type |
rotation | (unknown) | Rotation |
Example: let's spin a Colour-Cycled Cube! This is a fully valid
VRML file, and you can see what it does by clicking the here.
#VRML V1.0 ascii
SpinGroup {
rotation 1 1 -0.2 0.08
DirectionalLight {}
PerspectiveCamera {
position 0 0 5
}
Material {
diffuseColor [1 0 0, 0 1 0, 0 0 1]
ambientColor [0.1 0 0, 0 0.1 0, 0 0 0.1]
shininess [0.4, 0.4, 0.4]
}
MaterialBinding {
value PER_FACE
}
Cube {}
}
Next Topic (Transformations)
Previous Topic (Cameras and Lights)
Back to the VRML Reference
Back to the Main Page
©Tom Thurston, 1997
Please feel free to use and redistribute this NONcommercially!