[COPY AT TECFA, LIKELY OUTDATED !!!!: Please consult the original at http://www.tomco.net/~raf/faqs/eaifaq.html. The link was dead for a while, this is why we keep this copy]

VRML 2.0 EAI FAQ




This is the official Frequently Asked Questions and startup information for the VRML 2.0 External Authoring Interface.



About the EAI

What is the EAI?

The EAI allows you to control the contents of a VRML browser window embedded in a web page from a Java (tm) applet on the same page. It does this with a browser plugin interface that allows embedded objects on web page to communicate with each other..

Here is the web page for the actual EAI specification as written by Chris Marrin: http://www.vrml.org/WorkingGroups/vrml-eai/ExternalInterface.html

EAI and Script Nodes

There are two specified methods to use Java with VRML. One method is to use Script nodes. There is a normative Java script node implementation annex to VRML, Annex B. The Java Appendix to VRML specification defines required implementation for Java functionality from Script Nodes.

The EAI is the other way to use Java with VRML. It is not required but several browsers have implemented it.

What is the difference between internal Script Nodes and External Authoring Interface?

Here are some statements to help clarify functional difference between internal Script Node and EAI:

Tim Regan:

"Both the internal Java Script Node and the External Authoring Interface allow programmers to control the nodes in the scene graph from within Java. The choice between them is largely down to the taste of the programmer though many follow a fish bowl metaphor, using the script node for behaviours purely within the world and the external interface for behaviours linking outside. Within a WWW browser the EAI provides simple access from an applet on the same page as the VRML browser, currently using Live Connect."


Marrin:

"You can check out a paper I wrote on the subject:

http://www.marrin.com/vrml/papers/InternalExternal/Chris_Marrin_1.html

Executive summary of that paper: "Use Java in a Script node when you want to add composable behavior to individual objects in a VRML world. Use the EAI when you want to create integrated multi-media presentations, of which VRML is one media type of many."


It might help to think of Script Nodes as hard wired control nodes. They are flexible in scene graph and handle internal events. External interface is useful for systemic node and dynamic event handling.

The difference between EAI and internal Script node is that External Interface offers generalized method to access nodes and event in the VRML browser's scene graph, by connecting to a VRML browser plugin through a browser plugin architecture like LiveConnect or ActiveX/COM. Internal Script Nodes have node access through definition within a VRML Script Node within a VRML scene graph. The External Authoring Interface lets you use and affect events and fields on a dynamic basis, while the Script Nodes' definitions consist of predefined fields and events.

As an example of this, a vrml.external.Browser object is created from a plugin aware applet or embedded object within a browser frame.

import vrml.external.Browser;
import vrml.external.Node;
import java.applet.Applet;
Depending on your platform, the implementation of the applet returns a handle to the VRML browser plugin object. Here is an example:

public class AnApplet extends Applet{

    Browser browser=Browser.getBrowser(this);


Then, one can get access to a node in the VRML Browser that has been DEF'd in the VRML language.

    Node rootnode=browser.getNode("ROOT");

}


Then, any or all events or leaf nodes of the Node can be observed and/or modified.

The Script node, which is VRML syntax, affects Nodes and sends events through the Node's event structure that are the parameters of the Node. Only the fields and nodes defined in the Script node syntax can be affected through Script node.

Whether to use Script Node or External Interface depends on specific project. Both solutions are very flexible and powerful. In most cases, either can be used.

Standards/ Compliance

Is the External Authoring Interface a standard protocol?

The EAI is a proposed Informative Annex to the VRML specification. That means that browser implementations can choose whether or not to implement the EAI and still have complete VRML 2.0 compliance.

A current proposal is underway to make the EAI a normative annex. See next question. Is the EAI static?

Marrin: "The EAI is in the WG process, so it is subject to change. Every user of the EAI needs to be aware of this."

An updated version of the EAI Proposal from Marrin, VRML 2.0 Proposal: External Authoring Interface Reference, is online at http://www.vrml.org/WorkingGroups/vrml-eai/ExternalInterface.html. This proposal has extensions to the Browser object to allow a VRML world to be used as a Java component.

J. Couch has developed a refinement of the original EAI that is on the ISO standards track. ECMAScript EAI access guidelines are also under development.

For more information on the current state of the EAI, see the External Authoring Interface Working Group page.

Browsers

Which browsers support EAI?

Here is the current system that it runs on:

Browser VRML 2.0 Plugin Cosmo Software Cosmo Player and WorldView by Intervista have EAI support. Newfire browser has plan to implement EAI. Sony said unofficially that they would support EAI if it was standard, although they are less into plugin architecture. For information on VRwave EAI see VRwave release notes. For more information on CC3D EAI, see blaxxunCC3D Online Docs.

Install and Classpath

What else is necessary when installing?

For Netscape 3.01 and Cosmo Player for Win95, the installation program will set everything up. Be sure that when you try to use Cosmo Player that it works for regular VRML files.

For IRIX users install Netscape and Cosmo Player and edit your mailcap file for the MIME type for VRML.

Which classes are necessary in CLASSPATH?

Java uses an enviroment variable called classpath. When Java Virtual Machine needs classes it looks for them in classpath. You need these classes in your classpath to develop with EAI:

For older versions of Netscape (3.0) these classes are also necessary. Where can I find the packages beginning with "vrml" and "netscape"? - Howard Reiken

VRML external classes come with CosmoPlayer 1.0, 2.0 and WorldView 2.0. The required Netscape classes such as JSObject are in your java30 or java301 file under your netscape directory, or the npcosmop.zip file with Cosmo Player 2.0. You can rename java_301 to a zip file and extract the JSObject class itself, put it in a directory in your classpath under netscape/plugin directory.

For Netscape 4.0 and Cosmo Player 1.0 or 2.0 the vrml classes are in the file npcosmop.zip and the netscape classes are in the java40.jar file.

What are the CLASSPATH settings for specific browser combinations?

Your classpath should look something like this to access needed classes to compile EAI applets:

Netscape Navigator 3.0, Win32:
set CLASSPATH=C:\java\lib\classes.zip;C:\Program Files\Netscape\Navigator\Program\java\classes;C:\java\classes\vrml\;
Netscape Navigator 3.0, IRIX:
setenv CLASSPATH="/usr/local/java/lib/class.zip:/usr/CosmoPlayer/classes:/usr/local/lib/netscape/java301"
Sameer Raheja wrote:
I was able to get the EAI working w/ Cosmoplayer 1.0.2 on an Indy R5k,
so if anyone is interested, here's what i did:
1. Intall the SGI version of Netscape 3.01, called Netscape 3.01S from
http://www.sgi.com/Products/Evaluation/evaluation.html
2. Install CosmoPlayer 1.0.2 from http://vrml.sgi.com/cosmoplayer
3. Now for a hack:  as root, copy the directory
/usr/CosmoPlayer/classes/vrml to /usr/local/lib/netscape/plugins
        cp -r /usr/CosmoPlayer /usr/local/lib/netscape/plugins
This will create a directory called /usr/local/lib/netscape/plugins/vrml
with all the appropriate vrml.external.* files.
Moving files here means Netscape can find the classes by default without
having to set the CLASSPATH variable to something special, and without
having to play with java_301.
If you do not have access to /usr/local/lib/netscape, here is a
workaround:
3a. Create a directory called ~/.netscape/plugins, unless it already
exists (it does not by defalut).
3b. Copy the files from the CP dir to there:
        cp -r /usr/CosmoPlayer ~/.netscape/plugins
4. Make sure your CLASSPATH env variable is not set.
5. Quit netscape, and restart.
You should get the new version of netscape w/ the SGI logo.  Only the
EAI stuff works, no java script nodes.  (test with
http://vrml.sgi.com/moving-worlds/spec/RGBTest/)  If the applet does
not load, try reloading the page.  You can also get it to work by
setting the CLASSPATH env variable, but I prefer not to mess with that.
good luck!
Microsoft Internet Explorer 3.0, Win32:

If using WorldView 2.0, see WorldView 2.0 Developer's Guide, WorldView 2.1, see WorldView 2.1 Developer's Guide.

Netscape Communicator 4.04, Win32:

No classpath adjustments are necessary to run EAI applets, to compile aginst EAI classes put the EAI classes distributed with your browser on your compiler's classpath.

For Cosmo Player, expand the npcosmop.zip file into your compiler's classpath. Alternatively, use these classpath settings:
SET CLASSPATH=%CLASSPATH%;C:\Program Files\Netscape\Communicator\Program\Java\Classes
SET CLASSPATH=%CLASSPATH%;C:\Program Files\Netscape\Communicator\Program\Plugins\Npcosmop.zip
Microsoft Internet Explorer 4.0, Win32:

Using Cosmo Player 2.0 with Internet Explorer, Aktihanoglu notes:
The Microsoft Java VM looks for java classes in the directories
specified in the registry key :

HKLM\Software\Microsoft\Java VM\Classpath

So you have to append D:\Cosmo\npcosmop.zip; to that entry.
If using WorldView 2.0, see WorldView 2.0 Developer's Guide, WorldView 2.1, see WorldView 2.1 Developer's Guide.

Netscape Communicator 4.04, IRIX:

Stephen F. White notes:
- don't set your CLASSPATH in the shell
- compile using javac -classpath /usr/local/lib/netscape/java_301:/usr/CosmoPlayer/classes:/usr/java/classes:. foo.java

i use netscape's classes is because i'm using jdk 1.1 and compiling
against jdk's classes may issue warnings about 1.0-style use of AWT,
and may generate incompatible code.  you can also use
/usr/local/communicator/java/classes/java40.jar instead if you like.

my makefile looks something like this:

SHELL = /bin/sh

JAVAC = javac
JFLAGS =  -classpath /usr/local/lib/netscape/java_301:/usr/CosmoPlayer/classes:/usr/java/classes:.
If the browser doesn't load into EAI, you should load a page with an embedded file to initialize Cosmo Player and then go the EAI applet page.

David Chamberlin:
                                   ..., the way I got the EAI to work
under Ns4.04 and Irix CP1.0.2 is to have the CLASSPATH unset and either
copy the /usr/CosmoPlayer/classes directory into the
/usr/local/lib/netscape/plugins directory, or make a symlink.  (i.e.,)

cp -r /usr/CosmoPlayer/classes/* /usr/local/lib/netscape/plugins
or 
ln -s /usr/CosmoPlayer/classes/vrml /usr/local/lib/netscape/plugins/vrml 
Matthew Lewis notes:
I'm finding that I *must* use the java_301 file, because I get lots of
error messages if I try to put the java40.jar file in my CLASSPATH or
specify it in the javac command line classpath.
On SGI it depends on what version of Java is in effect, if version 3.0 then the java40.jar file should work, if version 3.1 there is a possible bug and the java301 solution is suggested as a workaround.

Netscape Communicator 4.05, Win32:

I deinstalled Netscape Communicator 4.04 and Cosmo Player and installed Netscape Communicator 4.05 and then Cosmo Player. It worked for JDK 1.02 applets. To get 1.1 support, you have to get the Netscape Communicator 4.05 JDK 1.1 Preview Complete Install.

For development With Cosmo Player have the correct version's Java classes from the npcosmop.jar file in your compiler's classpath. The console will tell you if you have the wrong version.

If you can't load VRML files from disk to Netscape then check the Registry Key HKR\.wrl. It should be model/vrml not x-world/x-vrml.

If Netscape crashes while you are developing make sure that it exits completely. You might have to stop it's process manually. Sometimes Netscape will spawn an Rnaapp on Windows95 which if killed can prevent some crashes.

Netscape Communicator 4.0, Macintosh:

Amit Bleiweiss wrote:
On the MAC, you need to explicitly "include" in your project the jar
file containing the vrml classes, when compiling a new EAI applet which
contains those classes. The jar file is CosmoPlayer.jar and is contained
in the Netscape plugins directory. 

Amit 

Tchavdarov Ludmil wrote:
> 
> we've recently installed Cosmo Player 2.1a on our MacOS8.1. EAI works
> fine but when we try to compile new classes importing vrml.external.*
> and
> netscape.javascript.JSObject the compiler doesn't find them. We've also
> tried to set the Class Path but it doesn't work anyway. Does anybody
> know
> how this whole procedure works on Mac?Thanks for your help!
> - Massimo
How do I use EAI classes with an IDE?

To use these classes with an IDE add them to your IDE's classpath per IDE documentation.

When using Symantec Visual Cafe to build EAI applets, it might be necessary to use Sun compiler instead of Symantec compiler. George Birbilis wrote:
The vrml.external.XXX classes can't be found by the Symantec compiler and
also it issues numeric underflow errors for many of the float constants
used in those sources... Just changing the compiler option at
Project/Settings/Build to "Use Sun's javac compiler" compiles fine!!!
For Windows 95 machines in general, to set environment variables you might have to extend the command shell memory.

Niclas Olofsson wrote:
... Thus,
Put the following line (or change it) into config.sys:

    SHELL=c:\windows\command.com C:\ /E:4096 /P

SHELL tells witch shell dos is using (c:\command.com?) and the /E:4096
tells it how much memory it should reserve. (C:\ = root; /P = Permanent
shell [~UNIX login])
For Windows NT set the environment variables from the Control Panel.

Netscape Navigator 4.5, IRIX:

For Cosmo Player 2.1 on IRIX 6.5 Glenn Shute notes:
There should be nothing special that needs to be done to enable the
EAI. Of course you need to have JAVA enabled in the browser. And
if you have a CLASSPATH set (which you should not need at all) but
if you do then you need to make sure these items are on the path in
this order:

/var/netscape/communicator/java/classes:
/var/netscape/communicator/java/classes/java40.jar:
/var/netscape/communicator/java/classes/npcosmop.jar

I have found that even if the jar files are in the same directory
they have to listed explicitly.
Contact your system administrator.

Which languages can I use to program to EAI?

Most browsers support Java as the primary language interface to program to the EAI. This document's examples use Java. Several browsers have implemented COM interfaces to the EAI, notably blaxxun interactive's CC3D, Cosmo Software Cosmo Player, and Intervista Software's WorldView for Developers.

Theoretically, any language could be used to program to the EAI.

How do I work with multiple browsers?

Both of the 4.0 browsers that support EAI (Internet Explorer and Netscape Communicator) support the same versions of file syntax for the current versions of their supporting VRML browsers (WorldView and Cosmo Player). This is the default environment discussed throughout the rest of this document. Earlier versions of Internet Explorer with WorldView require extra stuff and are incompatible with default environment. See WorldView notes above.

For some more notes on setting up Win95 with multiple browsers see these classpath install notes by Bob Crispen.

Note these are typical scenarios for install, install according to your own system setup.

HTML Syntax Stuff

What tags do I add to HTML file containing VRML .wrl file and applet?

The HTML file that has the embedded wrls and applets only has one required semantic, mayscript in the applet tag so the applet can get the vrml plugin browser object instance from the browser. The mayscript field in the applet tag allows the applet to access JavaScript methods built into Netscape Navigator and get an instance of the plugin object. This same method is functional in Internet Explorer 4.01 and later.
	<EMBED SRC="VRMLFile.wrl" >

	<APPLET code="ExternalApplet.class" MAYSCRIPT>
	</APPLET>
VRML 2.0 Syntax Stuff

How do I make Nodes in .wrl file available to external interface?

To access nodes in the VRML world they have to be DEF'd in the VRML file, that is their defined names must be within the name scope of the top level VRML file.
	#VRML V2.0 utf8

	DEF NODE Transform{}
Once a node is DEF'd in the VRML file it is available to the external interface through the Browser.getNode() method. The spec is difficult to interpret on how it handles multiple instantiations of DEF, like DEF in PROTOs.

Marrin:
To be safe, only access DEF names in the root world and outside any PROTOs. Also, if the root world has duplicate DEF names, only the last one is accessible.


Java Syntax Stuff

What are EAI specifics for Java?

You should have a good working knowledge of Java.

External Applet

How do I make External Applet?

The external applet extends Applet. The applet connects to the VRML browser plugin. Then, it can access the nodes in the scene graph of the VRML browser. Events can be sent directly to VRML nodes from the applet. The applet can implement the vrml.external.field.EventOutObserver interface if you are using the applet as the EventOutObserver to handle VRML events.

As part of the applet's import declarations, import the classes of the EAI Java API that will be used in the applet. All applets will have at minimum this set of classes to import:
	import vrml.external.Browser;
The rest of the classes used depend upon what node types and events are used in the applet. For example, if the applet affects one node's SFVec3f location, these classes would be necessary in import declaration.
	import vrml.external.node.Node;
	import vrml.external.field.EventInSFVec3f;
	import vrml.external.exception.InvalidEventInException;
It is easiest to just import all of them.
	import vrml.external.*;
	import vrml.external.field.*;
	import vrml.external.exception.*;
The applet's Java class declaration should inherit from Applet. This allows the vrml.external.Browser class to call getBrowser() method.
	public class ExternalApplet extends Applet{


Here are some initial variables to include:

		Browser browser;


The Browser

How do I connect to Browser plugin instance?

Most browsers support static getBrowser() method. In the start() method of your applet you need to get an instance of the browser object.
		browser= Browser.getBrowser(this);
This is the recommended method to get vrml.external.Browser instance from applet.

Put this in start() instead of init() method so browser interface is reconnected on reload.

To work with multiple browsers, the Browser object has been added another static getBrowser() method,
		Browser.getBrowser(Applet applet, String frame, int index)
which as implemented will allow getting pointers to multiple VRML plugin objects.

For Cosmo Player 1.0 beta 3a, use this "boilerplate" code to get instance of embedded browser plugin:

	JSObject win = JSObject.getWindow(this);
	JSObject doc = (JSObject) win.getMember("document");
	JSObject embeds = (JSObject) doc.getMember("embeds");
	browser = (Browser) embeds.getSlot(0);
Do not use this code in current environment, it is non-portable. This was the original method to get browser. Use static getBrowser() method shown above instead.

This offers more extensibility, ie eventual multiple browsers. If you are having problems with one or the other try the other one.

Here is some more information about LiveConnect JSObject: Netscape's Javascript Reference.
Kent Sandvik wrote:

Paul Ingalls wrote:
>
> Where can I find some up to date docs on the JSObject package?  The
> stuff on Netscape's site is out of date.  I want to have a java applet
> in one frame talk to a vrml file in another frame using the EAI.  Any
> help would be appreciated...

You could actually avoid using JSObjects now, at least in CP 1.0
forward, as the Browser.getBrowser(applet) API (see
http://vrml.sgi.com/moving-worlds/spec/ExternalInterface.html) is
supported.

As for getting access to an EMBED VRML tag in another frame,
Browser.getBrowser supports this at least in the API level, but as for
how well it works, I've never tried this myself (tend to have applet and
the vrml world in the same frame, if accessing the browser from another
frame does not work, one possible clumsy workaround is to have two
applets communicating, and the one tied to the frame/EMBED tag is an
invisible one).

Nodes

How do I access nodes from applet?

After you have an instance of the browser object, you can then use the browser methods to get references to Nodes in the VRML scene. The nodes have to be DEF'd in the scene.

When you get node instances it's like this:
	Node somenode;

	try{
		somenode=(Node) browser.getNode("NODE");
	} catch (InvalidNodeException e){
		System.out.println("Invalid Node Exception");
	}
Events

How do I handle events to and from nodes?

After you get the Node instance, you can get references to the EventIn and EventOut fields of the node. Then you can use the setValue and getValue methods of these eventIns and eventOuts to get info from the vrml world and send updates to the nodes back to the vrml world.

	// instance EventIn

	EventInSFVec3f setnewtranslation;

	// random values to set

	float[] valuetoset={0, 0, 0};

	// here get EventIn of Node 

	try{
		setnewtranslation=(EventInSFVec3f) somenode.getEventIn("set_translation");
	} catch (InvalidEventInException e){
		System.out.println("Invalid EventIn Exception");
	}

	// here set value of EventIn to Node

	setnewtranslation.setValue(valuetoset);

How do I receive events from VRML world in applet?

The EventOutObserver is an abstract public interface to get events from the vrml world. Implement EventOutObserver in the Java object that will handle events received from scene.
	public TheEventOutObserver extends Object implements EventOutObserver{
In your object definition for the EventOutObserver you need to override the callback method of the EventOutObserver interface:
	public void callback(EventOut event, double timestamp, Object someobject){

		//cast values and use them to do something

		int four=4;
		if (four ==((Integer)someobject).intValue()){function()}

	}
In the applet, instance the EventOutObserver before you use it:
	TheEventOutObserver theeventoutobserver;
After you get the node, get an instance of the eventout:
	EventOutSFVec3f theeventout;

	try{
		theeventout=(EventOutSFVec3f) somenode.getEventOut("translation_changed");
	} catch (InvalidEventOutException e) {
		System.out.println("Invalid EventOut Exception");
	}
After you get a reference to the EventOut, you need to advise the eventout of the data to the EventOutObserver so that it will receive the events from the vrml world.
	theeventout.advise(theeventoutobserver, null);
Null in this example represents an object that is passed to the callback of the registered EventOutObserver. You can replace null with other objects but you have to cast them back to usable values in the overridden callback method of your EventOutObserver.

Adam Fleming noted that observing events could crash the browser. Warning: on most versions of Cosmo Player, using an argument of anything other than null will lead to a memory leak and crash. Carlo Pescatelli states: "In this way if i have to observe a lot of nodes i must use one Observer for each of them."

The external applet can implement EventOutObserver. In this case use a method declaration like this:
	eventout.advise(this, new Integer(4));
You also have to override the callback method in the applet, to match the abstract method signature of the EventOutObserver interface.
	public void callback(EventOut event, double timestamp, Object someobject) {
		Integer x=(Integer)someobject;
	}
If callback locks or freezes, try not sending methods on nodes in the callback thread but from another thread.

Adding Nodes

How do I createVrmlFromString()?

The string argument to this method must be valid VRML. Here is some more explanation by Josh Levine:


Basically you have to get a handle on an initial transform or group in
the scene, and then add the Node[] you create with
"createVrmlFromString" to the scene.

Node root = browser.getNode("ROOT")

try {
  Node[] tmp = browser.createVrmlFromString("Transform { translation "+
                "0 10 0 children Shape { appearance Appearance { " +
                "material Material { diffuseColor 1 1 1 } } geometry "+
                "Box { size 2 2 2 } } }");
  EventInMFNode addChildren  = (EventInMFNode) root.getEventIn("addChildren");
  addChildren.setValue(tmp);
}
catch (InvalidVrmlException e) {
  System.out.println("Bad vrml...");
}


How do I get access to nodes that are added to scene after scene creation?

When you add nodes to the scene graph using createVrmlFromString() the method returns an array of nodes. You can keep these these nodes around in a vector or hashtable and later send events to them based on node value.

An alternate method is to add the created nodes to a predefined grouping node, then to traverse the grouping node and apply events as necessary.

If you use CreateVrmlFromURL(), this method does not return Nodes to Java applet but rather sends MFNode of created VRML to named eventIn and Node from createVrmlFromURL arguments. Then the nodes created wih this method can be manipulated as children of the node to which they were added. This can act as simple method to track loading status by adding an observer to the eventOut of the exposedField to which the MFNodes are added. When the observer is called it will signify that the VRML media is loaded. When the media is loaded you can access these nodes by traversing from the parent grouping node through Script node or EAI.

DEF names are not available, thus getNode is not available, on nodes that are created dynamically.

Why are DEF names in createVrmlFromString(), createVrmlFromURL(), and Inline nodes not accessible from the getNode() method?

Marrin:

A: The DEF name capability in VRML is a syntactic construct which allows nodes to be USE'd and routes to be defined between nodes in the same VRML file scope. It was never intended as a runtime name dictionary facility. The EAI presented a problem to VRML in that it has no implicit knowledge of any nodes in the world, and it exists outside any file scope, so it has no access to any nodes by name. It was decided to overload the semantics of DEF names to allow the EAI to get access to named nodes using the getNode() browser method. This was limited to nodes named in the base file (the file used to construct the original world or the file loaded with loadURL). Allowing DEF names created in any other scope (i.e., createVrmlFromString, createVrmlFromURL or Inline nodes) to add to the names accessible from the EAI would cause several problems:

- Since there is no name dictionary management facilities, there is no way to remove names once they are added. Over time, thousands of named nodes may be created, which would cause the dictionary to grow without possibility of ever shrinking.

- If two nodes are added with the same name (which is legal in VRML) undefined results will occur when the EAI attempts to access this name. Since VRML does not define the order of execution of scripts or the order of loading of Inlines, different browsers would present different nodes at different points in time. There would be no way to control this ambiguity.

- In the case of Inlines, the data hiding feature of VRML would be broken, because the EAI would be able to gain access to the internals of the Inline scene.

- Optimizations would be made very difficult because the EAI would have potential access to much more of the scene. Even though the EAI will probably NOT attempt to access most of the DEF'ed nodes (many nodes are simply DEF'ed so they can be routed or reused) that access MAY occur. Therefore, Inlines could not be unloaded for efficiency, and parts of the scene graph cannot be simplified.


How do I Create PROTO from String using EAI?

For some early versions of browsers, to use createVrmlFromString() to create PROTO, it is necessary to make string refer to EXTERNPROTO defined in the same operation.

Gavin Bell:
The VRML statements passed to createVrmlFromString() must be self-contained; the string is its own, separate scope. So, if you want to instantiate a prototype named Foo, you will have to use an EXTERNPROTO declaration in the string, like this:
    nodes = browser.createVrmlFromString(
    "EXTERNPROTO Foo [ ] \"#Foo\"
     Foo { }");
Notice that the quotes in the EXTERNPROTO definition are escaped with a backslash. Otherwise you can use regular node syntax.

Current browsers still require PROTO created from string to be defined in string's name scope.

Marrin:
You can't use a PROTO from the file in a createVrmlFromString call. You would have to either include the text for the entire PROTO in the string or put the PROTO into another file and include it in the string as an EXTERNPROTO (since this is a short PROTO the former solution is probably best).
See Tiny3D example for alternate nested node structure.

Troubleshooting

How do I shoot trouble?

This is a pretty complicated mechanism running on independently developed Beta components. So sometimes it's hard to get it to run. Realize that this is developer area.

Have all Java EAI functionality in start or run method of applet so it is reconnected when you reload the page.

> Q:What methods have to be called in the start
> method to reload the page of an EAI applet and world?  Do you have to get
> the browser instance again?  Do you have to get each of the nodes again?  In
> general, which elements have to be called on public void start() to allow
> for clean reload?
Murat Aktihanoglu says:
The init() method of your applet gets called only once, when the applet is first loaded into the JVM. When you reload or come back to the page, only start() method is called.

The reason most applets lose their "connection" to the browser is they call getBrowser() in init().

If you call getBrowser() and the EAI specific initialization methods (initializing some variables by getNode and etc.) in start(), then the applet works fine even if you change pages and come back or reload the page.


>i got this in my java console:
>
>AppAccelerator(tm) 1.0.2a for Java, x86 version.
>Copyright (c) 1996 Borland International. All Rights Reserved.
>java.lang.NoSuchFieldError: native method specified an invalid field
># Applet exception: exception: java.lang.NullPointerException
>java.lang.NullPointerException
In the case of applets that are known to work, this happens when the plugin is not loaded by the time the applet is loaded and trying to initialize the plugin connection. If you hit shift-reload it should work. If you get memory error, clear browser cache and increase virtual memory. These bugs are eliminated by improvements in browser architecture. Workaround is to sleep initialize of browser connect to give plugin time to load or loopingly test Node value against null to see if plugin is loaded and available.

It is a good idea to load a VRML file without EAI access prior to loading a VRML file with EAI to initialize VRML browser session.

There are known problems in browser reconnection.

Justin Couch wrote:
Brant Chamberlain wrote:
> I have found that the getBrowser function fails when
>
> embeds = (JSObject)doc.getMember("embeds");
>
> is called.
>
> What's even more infuriating is that this problem dissapears on
> other machines I've tested at my office. Is this a configuration issue?
> Has anybody had similar experiences. Any help REALLY appreciated...
>
> Using Netscape 4.04 and Cosmo 1.02

Your system classpath does contains references to either the cosmo
player zip file or to the netscape class implementation. Remove them.
Also, use the proscribed method of getting the browser reference with
the Browser.getBrowser() methods.

If rebooting doesn't work check for files in the temporay directory and delete them. To find the temporary directory, go to a DOS prompt and type set.
TMP=C:\WINDOWS\TEMP
TEMP=C:\WINDOWS\TEMP
When using Netscape 4.05 with JDK 1.1, going to a JDK 1.1 page with EAI from a JDK 1.02 page with EAI will crash the browser, but not vice versa.

How do I stop EAI from crashing browser?

Some browsers, notably Cosmo Player browser, have a problem with Java objects and memory. This means that it's memory error will crash your browser at some points. Eliminate these memory errors as possible.

Lars Travers has written documentation and an example of how to use techniques to free the Java objects and avoid many EAI browser crashes. See his demo at http://pw1.netcom.com/~ltrav/index.html.

After debugging Java code, compile with the -O javac option to optimize Java code.

Unfortunately, there are still some problems with the VRML browsers. Sometimes even with rigorous memory collection the HTML and VRML will crash when it probably otherwise would not.

Examples

Where can I see examples with source? If you have an EAI example with source email it to me to add to this list.

More Information

Where can I get more information or sites that use VRML EAI?

Document Information

Throughout this document the term VRML 2.0 instead of VRML97 is used for consistency.

Where can I get or add EAI FAQ information?

This document is under construction. We are currently working on making it nicer to read, with links and stuff. It currently resides at http://www.tomco.net/~raf/faqs/eaifaq.html. If you have info to add to this or have a question send email to current maintainer, Ross A. Finlayson, or EAI Working Group mailing list. Last modified March 1, 1999.


Java (TM) is a copyright of Sun Microsystems, Inc., Netscape Navigator(TM) is a copyright of Netscape Communications Corporation, Cosmo(TM) Player is a copyright of PLATINUM technology IP, inc., WorldView 2.0(TM) is a copyright of PLATINUM technology IP, inc. MSIE ActiveX and MS Internet Explorer are trademarks or registered trademarks of Microsoft Corporation. Disclaimer. All rights reserved. © Finlayson Consulting VRML Group