Xj3D VRML/X3D Code API

org.web3d.j3d.loaders
Class BaseLoader

java.lang.Object
  extended bycom.sun.j3d.loaders.LoaderBase
      extended byorg.web3d.j3d.loaders.BaseLoader
All Implemented Interfaces:
com.sun.j3d.loaders.Loader, org.j3d.renderer.java3d.loaders.ManagedLoader
Direct Known Subclasses:
VRML97Loader, Web3DLoader, X3DLoader

public abstract class BaseLoader
extends com.sun.j3d.loaders.LoaderBase
implements org.j3d.renderer.java3d.loaders.ManagedLoader

A Java3D file loader implementation for reading X3D utf8 files only and building a Java3D scenegraph with them.

The loader considers sensor handling and routing to be behaviours. Some asynchronous loading of files for textures is performed. Sound file loading is performed if audio clips are asked for. For example, if behaviours are not requested then Inlines will not have their content loaded.

If the loader asks for no behaviors, then we will still load nodes that use behaviors, but will disable their use. For example, a LOD will still need to have all of the geometry loaded, just not shown or activated because the LOD's internal behavior is disabled. Scripts are considered to be behaviours, and they will not be loaded at all if behaviour loading is disabled.

The implementation only makes use of two behaviours. One is a per-frame behaviour for the event model evaluation. The other is a handler for trapping user input events. If you disable behaviours, you loose both of these. For content other than static geometry, such as animations, turning off behaviours will result in no animations. However, every loaded scene will be attempting to do work like navigation. This will become quite CPU intensive because every model will be performing picking operations. To cut down on this CPU usage, the navigation processing is turned off by default. If you want the loaded code to also do the navigation of the viewpoints, then you can call the setNavigationEnable() method. The default setup for runtime activities is ListsRouterFactory and MemCacheLoadManager

Version:
$Revision: 2.25 $
Author:
Justin Couch

Field Summary
protected  ErrorReporter errorReporter
          Class that represents the external reporter
protected  java.util.Map overrideCapBitsMap
          The map of the override capability bit settings
protected  java.util.Map overrideFreqBitsMap
          The map of the override capability bit settings
protected  VRMLScene parsedScene
          The high-level VRML scene that was parsed to create the J3D scene
protected  VRMLParserFactory parserFactory
          The parser factory that we are going to use.
protected  java.util.Map requiredCapBitsMap
          The map of the required capability bit settings
protected  java.util.Map requiredFreqBitsMap
          The map of the required capability bit settings
protected  boolean vrml97Only
          Flag to say if the scene builder factory should only use VRML97
 
Fields inherited from class com.sun.j3d.loaders.LoaderBase
basePath, baseUrl, loadFlags
 
Fields inherited from interface com.sun.j3d.loaders.Loader
LOAD_ALL, LOAD_BACKGROUND_NODES, LOAD_BEHAVIOR_NODES, LOAD_FOG_NODES, LOAD_LIGHT_NODES, LOAD_SOUND_NODES, LOAD_VIEW_GROUPS
 
Constructor Summary
protected BaseLoader()
          Construct a default loader implementation with no flags set.
  BaseLoader(int flags)
          Construct a loader with the given flags set.
 
Method Summary
 boolean getNavigationEnabled()
          Get the currently set navigation state.
 VRMLScene getVRMLScene()
          Fetch the high-level Scene from the last parsed file that Xj3D uses to represent the VRML scene graph.
 com.sun.j3d.loaders.Scene load(java.io.Reader reader)
          Load the scene from the given reader.
 com.sun.j3d.loaders.Scene load(java.lang.String filename)
          Load a scene from the given filename.
 com.sun.j3d.loaders.Scene load(java.net.URL url)
          Load a scene from the named URL.
 void registerURNLocation(java.lang.String prefix, java.lang.String directory)
          Add a prefix and directory to the URN resolution system.
 void setCapabilityOverrideMap(java.util.Map capBits, java.util.Map freqBits)
          Provide the set of mappings that override anything that the loader might set.
 void setCapabilityRequiredMap(java.util.Map capBits, java.util.Map freqBits)
          Set the mapping of capability bits that the user would like to make sure is set.
 void setErrorReporter(ErrorReporter reporter)
          Register an error reporter with the engine so that any errors generated by the loading of script code can be reported in a nice, pretty fashion.
 void setNavigationEnabled(boolean state)
          Enable or disable navigation processing sub-section of the user input processing.
 
Methods inherited from class com.sun.j3d.loaders.LoaderBase
getBasePath, getBaseUrl, getFlags, setBasePath, setBaseUrl, setFlags
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.j3d.loaders.Loader
getBasePath, getBaseUrl, getFlags, setBasePath, setBaseUrl, setFlags
 

Field Detail

parserFactory

protected VRMLParserFactory parserFactory
The parser factory that we are going to use.


vrml97Only

protected boolean vrml97Only
Flag to say if the scene builder factory should only use VRML97


overrideCapBitsMap

protected java.util.Map overrideCapBitsMap
The map of the override capability bit settings


requiredCapBitsMap

protected java.util.Map requiredCapBitsMap
The map of the required capability bit settings


overrideFreqBitsMap

protected java.util.Map overrideFreqBitsMap
The map of the override capability bit settings


requiredFreqBitsMap

protected java.util.Map requiredFreqBitsMap
The map of the required capability bit settings


errorReporter

protected ErrorReporter errorReporter
Class that represents the external reporter


parsedScene

protected VRMLScene parsedScene
The high-level VRML scene that was parsed to create the J3D scene

Constructor Detail

BaseLoader

protected BaseLoader()
Construct a default loader implementation with no flags set. When asked to load a file it will not produce anything unless flags have been set through the setFlags() method.


BaseLoader

public BaseLoader(int flags)
Construct a loader with the given flags set.

Parameters:
flags - The flag values to be used
Throws:
java.lang.RuntimeException - The factory for loading VRML content could not be found
Method Detail

load

public com.sun.j3d.loaders.Scene load(java.io.Reader reader)
                               throws com.sun.j3d.loaders.IncorrectFormatException,
                                      com.sun.j3d.loaders.ParsingErrorException
Load the scene from the given reader. The scene instance returned by this builder will not have had any external references resolved. Externprotos, scripts, Inlines and all other nodes that reference part of their data as a URL will need to be loaded separately.

Specified by:
load in interface com.sun.j3d.loaders.Loader
Parameters:
reader - The source of input characters
Returns:
A description of the scene
Throws:
com.sun.j3d.loaders.IncorrectFormatException - The file is not one our loader understands (VRML 1.0 or X3D content)
com.sun.j3d.loaders.ParsingErrorException - An error parsing the file

load

public com.sun.j3d.loaders.Scene load(java.lang.String filename)
                               throws java.io.FileNotFoundException,
                                      com.sun.j3d.loaders.IncorrectFormatException,
                                      com.sun.j3d.loaders.ParsingErrorException
Load a scene from the given filename. The scene instance returned by this builder will not have had any external references resolved. Externprotos, scripts, Inlines and all other nodes that reference part of their data as a URL will need to be loaded separately.

Specified by:
load in interface com.sun.j3d.loaders.Loader
Parameters:
filename - The name of the file to load
Returns:
A description of the scene
Throws:
java.io.FileNotFoundException - The reader can't find the file
com.sun.j3d.loaders.IncorrectFormatException - The file is not one our loader understands (VRML 1.0 or X3D content)
com.sun.j3d.loaders.ParsingErrorException - An error parsing the file

load

public com.sun.j3d.loaders.Scene load(java.net.URL url)
                               throws java.io.FileNotFoundException,
                                      com.sun.j3d.loaders.IncorrectFormatException,
                                      com.sun.j3d.loaders.ParsingErrorException
Load a scene from the named URL. The scene instance returned by this builder will not have had any external references resolved. Externprotos, scripts, Inlines and all other nodes that reference part of their data as a URL will need to be loaded separately.

Specified by:
load in interface com.sun.j3d.loaders.Loader
Parameters:
url - The URL instance to load data from
Returns:
A description of the scene
Throws:
java.io.FileNotFoundException - The reader can't find the file
com.sun.j3d.loaders.IncorrectFormatException - The file is not one our loader understands (VRML 1.0 or X3D content)
com.sun.j3d.loaders.ParsingErrorException - An error parsing the file

setCapabilityOverrideMap

public void setCapabilityOverrideMap(java.util.Map capBits,
                                     java.util.Map freqBits)
Provide the set of mappings that override anything that the loader might set.

If the key is set, but the value is null or zero length, then all capabilities on that node will be disabled. If the key is set the values override all settings that the loader may wish to normally make. This can be very dangerous if the loader is used for a file format that includes its own internal animation engine, so be very careful with this request.

Specified by:
setCapabilityOverrideMap in interface org.j3d.renderer.java3d.loaders.ManagedLoader
Parameters:
capBits - The capability bits to be set
freqBits - The frequency bits to be set

setCapabilityRequiredMap

public void setCapabilityRequiredMap(java.util.Map capBits,
                                     java.util.Map freqBits)
Set the mapping of capability bits that the user would like to make sure is set. The end output is that the capabilities are the union of what the loader wants and what the user wants.

If the map contains a key, but the value is null or zero length, the request is ignored.

Specified by:
setCapabilityRequiredMap in interface org.j3d.renderer.java3d.loaders.ManagedLoader
Parameters:
capBits - The capability bits to be set
freqBits - The frequency bits to be set

getNavigationEnabled

public boolean getNavigationEnabled()
Get the currently set navigation state.

Returns:
true for the current state

setNavigationEnabled

public void setNavigationEnabled(boolean state)
Enable or disable navigation processing sub-section of the user input processing. By default the navigation processing is enabled.

Parameters:
state - true to enable navigation

getVRMLScene

public VRMLScene getVRMLScene()
Fetch the high-level Scene from the last parsed file that Xj3D uses to represent the VRML scene graph. This will give you access to all the real node representations, particularly those that do not have a Java3D SceneGraphObject equivalent representation and cannot be fetched through the usual Loader/Scene interfaces. If no file has been parsed yet, this will return null.

Returns:
A representation of the high-level scene or null

setErrorReporter

public void setErrorReporter(ErrorReporter reporter)
Register an error reporter with the engine so that any errors generated by the loading of script code can be reported in a nice, pretty fashion. Setting a value of null will clear the currently set reporter. If one is already set, the new value replaces the old.

Parameters:
reporter - The instance to use or null

registerURNLocation

public void registerURNLocation(java.lang.String prefix,
                                java.lang.String directory)
                         throws java.lang.IllegalArgumentException
Add a prefix and directory to the URN resolution system. Whenever the prefix is found under the web3d area, this directory will be searched.

Parameters:
prefix - The subspace prefix to use
directory - The directory that GeoVRML is installed in
Throws:
java.lang.IllegalArgumentException - The directory is not valid

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium