Areas


Topics

j3d.org

File Formats

  1. What File Formats does Java 3D support?
  2. How do I write out my scenegraph to XYZ format?
  3. How do I serialise the scene graph?
  4. AccessControlException when using a file loader in an applet

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

 

1. What File Formats does Java 3D support?

Java 3D is a rendering API. As such it does not support any file formats. Third party software then is used to read in a file and covert it into the Java 3D rendering code to run. Sun provides an OBJ and Lightwave3D loader as part of the standard distribution, but there are many more. All known file loader implementations can be found on the j3d.org Loader Archive page

Most file loaders implement the Sun utility interface com.sun.j3d.loaders.Loader.

 

2. How do I write out my scenegraph to XYZ format?

The simplest answer is that there is no direct capability to write a pure Java 3D scene graph out to a file. Java 3D looses much of the scene graph information deliberately for optimisation purposes. If you need to save your scene graph out to disk then you will need to keep your own internal data structures and representations of the information and use that.

Sun has released a new utility/example application called J3DFly that includes a new scene graph serialisation format to allow the save and restore of a scene graph to disk. This is still early beta development so you will need to download it from the J3D Homepage

 

3. How do I serialise the scene graph?

You cannot serialise the scene graph. This is because the scene graph uses many native resources and other items that make saving scene graphs directly as a serialised stream a really bad thing to do.

 

4. AccessControlException when using a file loader in an applet

Loaders cannot load filenames directly when in an applet. This is a standard security restriction. In particular, this happens when you pass just the file name string to the load() method expecting the loader to work out that you are in an applet. This is wrong and will cause the exception.

If you want to load a file from a remote webserver, use the URL class and access the base URL from the applet using the following code:

  try {
      URL file_url = new URL(getCodeBase(), file_name);

      Loader loader = new XYZLoader();

      Scene scene = loader.load(file_url);
  } catch(MalformedURLException mue) {
  } catch(IOException ioe) {
  } catch(IncorrectFormatException ife) {
  } catch(ParsingErrorException pee) {
  }