Browse DevX
Sign up for e-mail newsletters from DevX


Take Your Web Pages to the Next Dimension with FastScript3D : Page 3

Rocket-power your Web pages with the new Java technology from NASA's Jet Propulsion Laboratory.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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(); loader.setBaseUrl(http://localhost/fs3d/FS_MODEL); 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 and urlname 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 directory.

Figure 3. Use the Force: Here, FastScript3D is rendering a LightWave object.
Extending the Language
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.

FastScript3D is a great technology that empowers you to develop in Java3D without getting into all the low-level programming that would normally be required for generating and manipulating 3D objects and scenes. Its extensibility allows you to generate your own scenes, commands, and object types for powerful customization. Because it is a simple scripting language, it opens up a new box of tricks for JavaScript (or indeed VBScript) developers. This is most useful in that it can offer simple, firewall friendly access to complicated applications. The API is far more detailed than can be gone into on this site, and is certainly worth a detailed look. If you want to make your pages stand out from the crowd, then this is certainly a great place to start!

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.

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date