home  previous   next  contents

Shout3D™ 1.0 - User Guide

Java Programming with Shout3D 1.0

Creating New Panels and Applets

In order to create new Applets that behave differently from those provided, you will typically need to create one Applet class subclassed from Shout3DApplet and one Panel class subclassed from Shout3DPanel. Many examples are included in the Shout3d_runtime\codebase\applets directory.

  1. Copy an existing Applet/Panel pair to new files, such as MyNewPanel.java and MyNewApplet.java, keeping these files in the applets package
  2. Edit the constructors and declarations to match these new class names.
  3. In MyNewApplet.java, edit the method initShout3DPanel to create a "new MyNewPanel"
  4. The rest of the changes will be in the MyNewPanel class. Here are some rough guidelines for certain tasks. Refer to the javadocs and Shout3d specification for more guidance.
    1. Picking - is done with the Picker interface, returned by the applet or panel's getNewPicker() method.See MultiTestPanel for an example.
    2. Mouse and Keyboard Input -- may be monitored by registering for DeviceInput using addDeviceObserver(). See any of the demo applets for an example.
    3. Add/remove children between renders-- Because rendering occurs in a separate thread from other applet activity, it is important to add or remove children during an onPreRender() or onPostRender() callback. See MulitTestPanel.java for an example.
  5. Make sure that, in any html files that should use the new Applet, that you change the value of the CODE modifier. (see the chapter on Html files and applet tags). Or, if you are publishing with the Shout3DWizard, make sure to set the "Applet type" parameter to be your new applet class.

Creating New Node Classes

General: New classes may be derived from the Node class or any of its subclasses. The Shout3D API provides ways to add new fields, watch the field values (with FieldObservers) and respond to changes in the field values (with onFieldChanged). The example Shout3d_runtime\codebase\custom_nodes\Pyramid.java shows an example.

Pyramid example: The Pyramid class is a subclass of IndexedFaceSet that adds three fields, width, depth, and height. In the constructor, it sets the coord and coordIndex fields to be a pyramid shape. Then it watches for changes to width/depth/height and adjusts the coords accordingly.

Adding a new Node Class: To add a new Node class, subclass any of the existing Node classes and put the java file in the Shout3d_runtime\codebase\custom_nodes directory (files placed elsewhere will not successfully be read in from .s3d files)

Creating an instance of the New Node Class: Once the new Node class has been created and placed in the custom_nodes directory, any applets should be able to create and use the node class just like any other node.

Reading an instance of the New Node Class from an .s3d file: There is no way to make the vrml2tos3d converter generate files containing anything other than those in the s3d package under codebase. However, .s3d files are vrml-like and may be edited to a minor degree to create files that instance custom nodes. The example Shout3d_runtime\codebase\s3d\onePyramid.s3d is an example of this. So long as the new node class is located in the custom_nodes directory, then instances of the class may be included in the .s3d file.


Copyright© 1999-2000, Shout Interactive, Inc.