Areas


Topics

j3d.org

VRML/X3D

  1. What's the difference between Java 3D and VRML?
  2. What is X3D?
  3. Is there a Java3D-based VRML Browser
  4. How do I access nodes marked with DEF
  5. How do I mix Java3D nodes and VRML worlds?
  6. Why doesn't the NCSA loader load textures?
  7. How can I save my Java3D scene as a VRML file?
  8. I keep hearing about this Xj3D thing, where can I find more info?

Return to the main FAQ page for more questions and answers.

 

1. What's the difference between Java 3D and VRML?

Java3D is a low-level programming API for 3D graphics rendering. The code must be compiled to move it to executable form. VRML is a text based modelling language that is interpreted dynamically from the source files. A VRML browser can be implemented using Java3D, but you can't create Java3D applications with VRML.

 

2. What is X3D?

X3D is the next generation of the VRML specification. Like VRML it is a scene description language in a text file format. The major difference is that it can use either XML to describe the scene rather or to the older OpenInventor style syntax of VRML 1.0/2.0/97.

There is a loader available for the X3D format. See the Loaders section of the j3d.org site. This loader also is capable of loading the majority of the VRML 97 specification too.

 

3. Is there a Java3D-based VRML Browser

The Web3D Consortium is working together with a number of Open Source developers to them. The main codebase is called Xj3D, which has many different functions, from being a pure browser, to a toolkit to add X3D/VRML capabilities to any application.

This project has a very long history, starting with the donation of source code by Sun in Sept 1998. The source code working group, along with a number of commercial companies are now developing the code. The official releases and the working group can be found at
http://www.web3d.org/x3d/workgroups/source.html

 

4. How do I access nodes marked with DEF

If you are using the full Java3D based VRML browser, there is not much you can do about this as you must treat the browser as a black-box standard VRML browser. There is work that allows the integration of the External Authoring Interface into the standard browser in the later releases. You may access DEF names using the getNode() method as per the standard EAI definition.

Further information on the EAI can be found in Part 2 of the VRML97 specification at http://www.web3d.org/x3d/vrml/index.html

If you only wish to load VRML geometry without the browser, a loader is also available. The getNamedObjects() method of the Scene class can be used to extract DEF names from the file in accordance with the VRML scoping rules (no access to Inlined DEFs for example). In return you will be given the Java3D object that was built from the file, but not the runtime environment sufficient to work with VRML content directly.

 

5. How do I mix Java3D nodes and VRML worlds?

If you are using a loader to load the VRML then mixing Java3D and VRML generated nodes is certainly possible. There are many options about how you combine the objects together as the VRML nodes consist of standard javax.media.j3d.SceneGraphObjects allowing them to be placed anywhere within the scenegraph.

Doug Gehringer (Doug.Gehringer@west.sun.com) from Sun recommends the following approach:

The simplest way to do this is to have the VRML content and the new nodes be separate scene graphs. The VRML scene would be one BranchGraph attached to the locale and the new nodes would be other BranchGroups that get added to the locale. This works fine unless you want to make the new nodes be attached to the VRML scene graph.

For example, if you have VRML scene with a chair in and you want the new node to be a model of a person sitting in the chair. You can make this case work by making the VRML file have an "attachment point" for the new node. The chair could have a Transform node in the right location with DEF name:

Group { # this holds the chair and the person
    children [
        Shape {...} # this is the chair
        DEF Chair_seat Transform {
            # the new nodes will be children of this node
        }
    }
}

The VRML loader will make a TransformGroup for the "Chair_seat" Transform node and will store it in the DEF table. After loading the scene, you can get the mount point using the named object table:

  VrmlScene scene =  vrmlLoader.load(url);
  Hashtable defTable = scene.getNamedObjects();
  TransformGroup seat = (TransformGroup) defTable.get("Chair_seat");

Set the capability bits on the chair's TransformGroup to allow children to be added after the scene is made live. Then attach the VRML scene to the locale. When the user hits the button, add the a BranchGroup containing the new nodes to the TransformGroup (remember that only BranchGroups can be added to a live scene graph).

 

6. Why doesn't the NCSA loader load textures?

We don't know. It was part of what the developer did and we don't know much further than that. Unfortunately, the developer who wrote the code is no longer maintaining the project, so it probably won't ever load them.

 

7. How can I save my Java3D scene as a VRML file?

The only VRML loader/toolkit that is capable of saving out a Java3D scene graph as VRML is Satoshi Konno's CyberX3D Toolkit. Please note that VRML and Java3D don't exactly match in capabilities so some information will be lost in the process. In addition, it will require you to make some changes to the normal scene graph that will adversely effect performance, so the first question you really should ask - why is your application not keeping its own internal data structures that can be used to create the VRML file from, rather than use the low-level rendering structures for your data storage.

 

8. I keep hearing about this Xj3D thing, where can I find more info?

Xj3D is a long running open source toolkit that is used for loading VRML97 and X3D files. The homepage for the toolkit is

    http://www.xj3d.org/

The main work is done through the Web3D Consortium so more information about mailing lists and such can be found at:

    http://www.web3d.org/x3d/workgroups/source.html