Using Complex Models
One of the most exciting features of FastScript is the ability to import and render models from CAD or modeling packages and display them. To do this you need to write a wrapper class around any of the file loaders that are available within Java3D. A full listing
of these files along with API details is available on the Java3D site
One of the more famous and popular 3D scene creation packages is LightWave, which has been used in many television and movie special effects. FastScript3D comes with an example page that loads and renders a LightWave scene, and it does this by creating a wrapper for LightWave files. Java3D provides a LightWave loader class called Lw3dLoader in the com.sun.j3d.loaders.lw3d package. This encapsulates the loading and basic parsing of LightWave-format objects.
The code to load a 3D scene from LightWave is very straightforward:
Scene threedsscene = null;
loader = new Lw3dLoader();
threedsscene = loader.load(http://localhost/fs3d/FS_MODEL/run.lws);
The file lightwave.java, available in the download was taken from the JPL site and edited to change the urlbase
variables to http://localhost/fs3d/FS_MODEL
directory as that is where the examples have been installed for the creation of this article. In addition, the download includes the LightWave files to generate a Star Trek
spacecraft (a runabout from Deep Space Nine to be precise) make sure that you place these files in the FS_MODEL
Extending the Language
|Figure 3. Use the Force: Here, FastScript3D is rendering a LightWave object.|
FastScript3D is open source and fully extensible. It is designed so that new commands may be easily integrated. If you create a command that is not part of the core set of FastScript3D commands, and the engine receives this command, it starts calling the extension parsers
that it knows about. The method addparser
allows you to add parsers to the core engine.
A good example of where you may want to add new commands and parsers to the language is in extending the limited number of materials that are available with the MAT commands. This would simply be done by amending the Java class that you use to place the applet on the Web page (in the above examples easy.class and lightwave.class) to add a class that intercepts the new commands (e.g. MATPLASTIC and MATRUBBER), and in the init() method of your applet you would create an instance of this call as pass it to the addparser method.
This example is discussed in detail with source code in the FastScript documentation.
| Author's Note: FastScript3D was created and written by Patti Koenig, Ph.D. of NASA Jet Propulsion Laboratory (JPL) for the California Institute of Technology.