
![]()
|
Don't Be a Primitive, Use PrimitivesEvery once in a while VRML gives you, the developer, a little break. You can consider the addition of primitives to the language as one of these breaks. Primitives are predefined shapes that have already been made into nodes for easy use, so you wouldn't have to continuously make your own shapes even if they were very simple. These primitives include the box, cone, cylinder, and sphere. All of the nodes that represent these shapes fit inside a field of the Shape node:
Shape {
appearance NULL # exposedField SFNode
geometry NULL # exposedField SFNode
}
The Box
Box {
size 2.0 2.0 2.0 # field SFVec3f
}
The The ConeCones are a little bit more exciting than simple boxes. First of all, they have curved sides, all of which you can choose to build or not to build:
Cone {
bottomRadius 1.0 # field SFFloat
height 2.0 # field SFFloat
side TRUE # field SFBool
bottom TRUE # field SFBool
}
As you might expect, The CylinderTheCylinder node has just one more attribute:
Cylinder {
radius 1.0 # field SFFloat
height 2.0 # field SFFloat
side TRUE # field SFBool
top TRUE # field SFBool
bootom TRUE # field SFBool
}
The The SphereThe last primitive is the sphere:
Sphere {
radius 1.0 # field SFFloat
}
The sphere has only one field, Experimenting with the PrimitivesAnd no, this isn't some socio-political survey on the behavior of people on a distant island. Let's attempt something easy, like a default box:
#VRML V2.0 utf8
Shape {
# Make the box gray
appearance Appearance {
material Material {}
}
geometry Box {}
}
Easy enough, right? Now let's make this box taller and thinner by manipulating its attribute:
#VRML V2.0 utf8
Shape {
appearance Appearance {
material Material {}
}
geometry Box {
size 1.0 3.0 2.0
}
}
The cylinder can be manipulated just as easily. Here's one that's been flattened:
#VRML V2.0 utf8
Shape {
appearance Appearance {
material Material {}
}
geometry Cylinder {
height 0.5
}
}
If you then disable the top and bottom of the cylinder, you get a circular ribbon with some pretty interesting shading:
#VRML V2.0 utf8
Shape {
appearance Appearance {
material Material {}
}
geometry Cylinder {
height 0.5
top FALSE
bottom FALSE
}
}
In closing, don't be a primitive. Use primitives. |