In this exercise you will build a 3D volume filled with vectors (arrows). Each vector will point in a different direction and have a different color. Next you will animate the vector field to show several time steps in a simulation.
In visualization, vector fields are often used to indicate the flow of a fluid through a volume. Each arrow indicates the direction and magnitude of the flow at a point in the volume. To show changes in the fluid flow, the vector field is animated, causing the vectors to change direction, length, and color.
This exercise focuses upon use of IndexedFaceSet, Coordinate, Switch, Inline, and Script nodes. This exercise also introduces the PROTO and EXTERNPROTO syntax.
In the file, build an arrow-shape using an IndexedFaceSet geometry node. Make the arrow conform to the following specifications:
| Parameter | Dimension |
| total vector height | 1.0 |
| body width | 0.2 |
| body height | 0.75 |
| tip width | 0.5 |
| tip height | 0.25 |
| origin | center base of arrow body |
HINT: Build the tip with one triangle and the base with one rectangle.
HINT: Remember, use a "-1" index value to delimit faces.
| Field | Value |
| emissiveColor | 0.0 0.0 0.0 |
| diffuseColor | 0.8 0.8 0.8 |
| ambientIntensity | 0.0 |
HINT: Once you have constructed one arrow in the X/Y plane, USE another instance of it rotated 90 degrees around the Y axis. This will produce a copy in the Z/Y plane to add apparent depth to the otherwise flat geometry.
SOLUTION: vector1.wrl
To build a vector field you're going to need dozens of arrows, all with approximately the same shape. Wouldn't it be nice if there was a Vector node? Your task is to modify the vector2.wrl file to create a Vector node. Add a PROTO wrapper around the vector shape. Make sure that it conforms to the following specifications:
| Data Type | Field Name | Default Value |
| SFVec3f | translation | 0.0 0.0 0.0 |
| SFVec3f | scale | 1.0 1.0 1.0 |
| SFRotation | rotation | 0.0 1.0 0.0 0.0 |
| SFColor | color | 0.8 0.8 0.8 |
HINT: Connect the translation, rotation, scale, and color fields of the PROTO interface to your vector shape using the IS syntax.
You can test your new Vector node by temporarily adding a line to the end of your file, like this:
Try adding translation, scale, rotation, and color fields and values to your Vector node test. Remember to get rid of this test node before you move on to the next task.
SOLUTION: vector2.wrl
The program generates a volume of vectors, each one positioned, oriented, scaled, and colored based upon a function the program computes. Each vector is rendered by using your Vector node! The program's "vecfield.wrl" output uses your Vector node by using an EXTERNPROTO statement at the top of the file. That statement tells the browser to get your Vector PROTO from your file "vector2.wrl".
SOLUTION: vecfield.c, vecfield.wrl
INTERMEDIATE SOLUTION: vecfld1.wrl, vecfld2.wrl, vecfld3.wrl, vecfld4.wrl, vecfld5.wrl, vecfld6.wrl, vecfld7.wrl, vecfld8.wrl, vecfld9.wrl, vecfld10.wrl
Don't bother viewing each of the individual VRML files. Your task is to build an animation that automatically cycles between these 10 files, treating each one like a "frame" in an animation sequence.
Create and edit a new VRML file:
In this new VRML file, use a grouping node to switch between the 10 vector fields, each one inlined from its own file.
HINT: Use Inline nodes to incorporate each of the 10 vector fields.
To animate the switch you'll need to build a new interpolator using your own script. You'll need a Script node and the usual TimeSensor node. For the script, you'll need a fractional time input and an SFInt32 output. On each fractional time input event (varying from 0.0 to 1.0), generate an integer output event (varying from 0 to 10). Route that integer event into the whichChoice field of the switch.
HINT: You can use 3 "tricks" to compute the conversion value:
1) The fractional values run from 0.0 to 1.0
2) The whichChoice values run from 1 to 10
3) JavaScript can round a fractional value to an integer value
View the resulting "multivec.wrl" VRML scene. Be patient: it takes a while to load.
SOLUTION: multivec.wrl