[Javascript] FastScript3D

Patti M. Koenig Patti.M.Koenig at jpl.nasa.gov
Wed Dec 4 16:41:59 CST 2002


In response to some of the emails that I have received, I wanted to post a 
very simple example of how FastScript3D makes it easy to create java3D web 
applets via JavaScript and HTML. You do have to have Java and Java3D 
installed properly on your machine and working right with your browser. 
Once you have that, though, it is very easy to create applets with Java3D 
content. The following script shows three 3D cubes, the right and left ones 
are rotating continuously. Here is the script code:

Here is the script:
EASY.HTML

<!-- Easiest FastScript3D Model Ever -->

<title>FastScript3D - Easy Model</title>
Easiest FastScript3D Model Ever

<FORM name="Model">

<!-- press button to call model creation function -->
<input type="button" value="Press here to start applet"
    onclick="demo();">

<!-- defines yout FastScript3D applet -->
<applet align=middle
      name="fs3d" code="easy.class"
      archive="fs.jar"
      width="275" height="275">
<blockquote> <hr>
If you were using a Java-capable browser,
you would see the graphics window here.
</hr>< /blockquote>
</applet>

</FORM>

<!-- uses scripting language -->
<SCRIPT LANGUAGE="JavaScript">

      function model() {
           fs3d.parse("MODELCLEAR");

           fs3d.parse("NAME redbox");
           fs3d.parse("COLOR red");
           fs3d.parse("HINGE 1 0 0");
           fs3d.parse("MOVABLE");
           fs3d.parse("OFFSET -0.5 0 0");
           fs3d.parse("GEOMBOX 0.25");

           fs3d.parse("NAME greenbox");
           fs3d.parse("COLOR green");
           fs3d.parse("GEOMBOX 0.25");

           fs3d.parse("NAME bluebox");
           fs3d.parse("HINGE 1 0 0");
           fs3d.parse("MOVABLE");
           fs3d.parse("COLOR blue");
           fs3d.parse("OFFSET 0.5 0 0");
           fs3d.parse("GEOMBOX 0.25");

           fs3d.parse("MODELBUILD");
      }

      function sim() {
           fs3d.parse("SIMNAME movethem");
           for (i=0; i<120; i++) {
                fs3d.parse("FNUM " + i + " RR redbox " + 3);
                fs3d.parse("FNUM " + i + " RR bluebox " + -3);
           }
      }

      function demo() {
           model();
           sim();
           fs3d.parse("PLAYAUTOON");
           fs3d.parse("PLAYRUN");
      }


</SCRIPT>


Here is the applet:
EASY.JAVA

import java.applet.Applet;
import com.sun.j3d.utils.applet.MainFrame;
import fscore.fastscript.*;
import fscore.fastscript3d.*;
^M
public class easy extends FS3D {
      public void init() {
           fs3dinit();
      }
      public static void main(String[] args) {
           new MainFrame(new easy(),400,400);
      }
}


You can see this example running and other applets at
http://fastscript3d.jpl.nasa.gov

Please send me your feedback!
Patti Koenig




More information about the Javascript mailing list