Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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

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


advertisement
Developing in FastScript3D
Examine the HTML page for the example in this article and you'll find the following script.

this.document.fs3d.parse("MODELCLEAR"); this.document.fs3d.parse("NAME redbox"); this.document.fs3d.parse("COLOR red"); this.document.fs3d.parse("HINGE 1 0 0"); this.document.fs3d.parse("MOVABLE"); this.document.fs3d.parse("OFFSET -0.5 0 0"); this.document.fs3d.parse("GEOMBOX 0.25"); this.document.fs3d.parse("NAME greenbox"); this.document.fs3d.parse("COLOR green"); this.document.fs3d.parse("GEOMBOX 0.25"); this.document.fs3d.parse("NAME bluebox"); this.document.fs3d.parse("HINGE 1 0 0"); this.document.fs3d.parse("MOVABLE"); this.document.fs3d.parse("COLOR blue"); this.document.fs3d.parse("OFFSET 0.5 0 0"); this.document.fs3d.parse("GEOMBOX 0.25"); this.document.fs3d.parse("MODELBUILD");

Fastscript3D commands are constructed as a string and passed to the 'parse' method of the applet. The command string is always constructed in the same way with the keyword in capitals followed by the parameters that the keyword requires. It is in this form:

KEYWORD <arguments>

For example:


OFFSET -0.5 0 0

(Note that parameters are space delimited.)

The command always returns a string containing the status of the command. If your command was successfully passed to the engine and successfully parsed, the return string will be "1" followed by the command, otherwise it will be "0" followed by the command and an error message detailing the problem.

Objects in your 3D world are called models in FastScript3D. To begin a new application you use the MODELCLEAR command, to clear up space and ready it for new drawings.

After that define your models and their attributes. Your models are defined using the commands that are prefixed GEOM. Table 1 lists the available models and their associated commands.

Command Description
GEOMNULL No shape or erase current shape
GEOMBOX Draw a cube
GEOMRECT Draw a 3d Rectangle
GEOMSPHERE Draw a Sphere
GEOMELLIPSE Create an ellipse
GEOMAXIS Create a new co-ordinate axis
GEOMCYL Create a cylinder
GEOMTEXT Create some 3D Text
GEOMLABEL Create a label, this is similar to text except that it faces forward at all times
GEOMOBJ Implemented to interface with SUN WaveFront technology.
Table 1.GEOM Commands

 

Once you have your model, you can specify its appearance using a variety of commands. The most basic command for configuring your model is the COLOR command, which takes two overloaded parameter sets. The first is simply the textual description of the color such as:

COLOR blue

The second allows you to specify normalized RGB colors such as:

COLOR 0 0.5 1

In addition to colors, different materials and textures may be added to your model. There are many different materials built into the language, including MATGOLD, MATBRASS, MATCHROME, MATEMERALD, and MATCOPPER. The language is also extensible to allow you to add your own materials.

If you use both COLOR and MAT commands to enhance your model, you can make the colors and materials blend into each other with the MATSEEPON command. The model may also be made transparent using the OPACITY command where a parameter value of 0 is opaque and 1 is totally transparent, but you can use any decimal in between for partial transparency.

Your object may also be textured using a JPEG file. This file should be placed in the FS_TEXTURE directory.

TEXTURE me.jpg

Movement
In addition to defining how your object appears, there are many other commands for how your object behaves. For example movement can be defined. You specify the object as being movable with the MOVABLE command. A neat command for defining how the object moves is the HINGE command. This takes parameters defining the axis on which the object will move. For example, if you want your object to move on the Y axis, simulating, for example, a rotating planet where the spin axis is generally seen as the vertical one, you would issue the following command:

HINGE 0 1 0

The code below contains an example of putting a few of these commands together. This is implemented in the download as earth.htm and creates a rotating globe. The Earth.JPG file is necessary, and should be placed in the FS_TEXTURE directory.

this.document.fs3d.parse("MODELCLEAR"); this.document.fs3d.parse("NAME Earth"); this.document.fs3d.parse("HINGE 0 1 0"); this.document.fs3d.parse("MOVABLE"); this.document.fs3d.parse("TEXTURE Earth.jpg"); this.document.fs3d.parse("GEOMSPHERE 0.5"); this.document.fs3d.parse("MODELBUILD");

The output of this script is shown in Figure 2. You can see that the API has handled wrapping the texture around the sphere and has added default lighting. Because the model has been declared as MOVEABLE, you can also drag on it with the mouse to affect its behavior.

Figure 2. Spanning the Globe: This rotating Earth is rendered with FastScript3D.
Animation
There are a number of commands available for animating your models. First you must select which model you want to animate. This is done with the REFER command. In the above example, there is only one object, called Earth, so to initialize it for animation you would use the REFER Earth command. Once you have a reference to an object you can animate it with commands such as TA, which translates the object to an absolute set of coordinates; TR, which translates the object to a relative set of coordinates; RA, which rotates it to an absolute position; and RR, which rotates to a relative position. Examples of these are:

  • TA 1 1 1—Move the object to location {1,1,1}
  • TR 1 1 1—Move the location from its present location {x,y,z} to {x+1, y+1, z+1}
  • RA 90 —Rotate the object to 90 degrees rotation
  • RR 5—Rotate the object by 5 degrees.

Animations can be aggregated into simulations, which can then be activated using the appropriate simulation/playlist commands. Check the FastScript3D documentation for more details.



Comment and Contribute

 

 

 

 

 


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

 

 

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