Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.renderer.norender.browser
Class NRUniverse

java.lang.Object
  extended by org.web3d.vrml.renderer.norender.browser.NRUniverse
All Implemented Interfaces:
BrowserCore, EventModelInitListener

public class NRUniverse
extends java.lang.Object
implements BrowserCore, EventModelInitListener

Representation of a Null renderer universe object suitable for use in single screen, stereo and walled environments.

Apart from the VirtualUniverse, this also holds all of the view information model. In particular, this is shared between multiple org.web3d.vrml.renderer.j3d.browser.VRMLBrowserCanvas instances to enable multiple views of the same scenegraph or for stereo viewing.

The universe is responsible for handling the management of the viewpoints within a scene. VRML defines a single viewpoint model for multiple canvases. If we want to set this environment up for stereo rendering or CAVE type environments, the renderer will need to use a single view for all of them. If you are trying to perform multiple views of the scenegraph, such as an editor environment, this universe is not suitable as it uses a single View object and attaches all canvases to that view and hence the underlying currently bound viewpoint.

The universe is not responsible for loading more VRML content. To handle anchors, it delegates to the supplied listener.

Version:
$Revision: 1.27 $
Author:
Justin Couch

Constructor Summary
NRUniverse(EventModelEvaluator eme)
          Construct a default, empty universe that contains no scenegraph.
 
Method Summary
 void addCoreListener(BrowserCoreListener l)
          Add a listener for browser core events.
 void addNavigationStateListener(NavigationStateListener l)
          Add a listener for navigation state changes.
 void addNodeObserver(int nodeType, NodeObserver obs)
          Add an observer for a specific node type.
 void addProfilingListener(ProfilingListener l)
          Request notification of profiling information.
 void addSensorStatusListener(SensorStatusListener l)
          Add a listener for sensor state changes.
 void addViewpointStatusListener(ViewpointStatusListener l)
          Add a listener for viewpoint status changes.
 void changeViewpoint(VRMLViewpointNodeType vp)
          Request that this viewpoint object is bound at the start of the next frame.
 void changeWorld()
          Notification that its safe to clear the world.
 void dispose()
          Notify the core that it can dispose all resources.
 void fitToWorld(boolean animated)
          Move the user's location to see the entire world.
 float getCurrentFrameRate()
          Get the current frame rate of the browser in frames per second.
 float getCurrentSpeed()
          Get the current velocity of the bound viewpoint in meters per second.
 java.util.Map getDEFMappings()
          Get the mapping of DEF names to the node instances that they represent.
 java.lang.String getDescription()
          Get the description string currently used by the world.
 java.lang.String getIDString()
          Get the ID string for this renderer.
 int getMinimumFrameInterval()
          Get the currently set minimum frame cycle interval.
 int getRendererType()
          Get the type of renderer that implements the browser core.
 int getRenderingStyle()
          Get the currently set rendering style.
 VRMLScene getScene()
          Get the scene that this universe is currently holding.
 void getUserPosition(javax.vecmath.Vector3f pos, javax.vecmath.AxisAngle4f ori)
          Get the user's location and orientation.
 VRMLClock getVRMLClock()
          Get the clock instance in use by the core.
 VRMLExecutionSpace getWorldExecutionSpace()
          Convenience method to ask for the execution space that the world is currently operating in.
 java.lang.String getWorldURL()
          Get the fully qualified URL of the currently loaded world.
 void removeCoreListener(BrowserCoreListener l)
          Remove a browser core listener.
 void removeNavigationStateListener(NavigationStateListener l)
          Remove a navigation state listener.
 void removeNodeObserver(int nodeType, NodeObserver obs)
          Remove the given node observer instance for the specific node type.
 void removeProfilingListener(ProfilingListener l)
          Remove notification of profiling information.
 void removeSensorStatusListener(SensorStatusListener l)
          Remove a sensor state listener.
 void removeViewpointStatusListener(ViewpointStatusListener l)
          Remove a viewpoint state listener.
 void sendURLFailEvent(java.lang.String msg)
          Send to the core listeners the error message that a URL failed to load for some reason.
 void setDescription(java.lang.String desc)
          Set the description of the current world.
 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 setEventModelStatusListener(EventModelStatusListener l)
          Set the eventModelStatus listener.
 void setLastRenderTime(long lastTime)
          Set the last frame render time used for FPS calculations.
 void setMinimumFrameInterval(int millis, boolean userSet)
          Set the minimum frame interval time to limit the CPU resources taken up by the 3D renderer.
 void setNavigationMode(java.lang.String mode)
          Set the navigation mode selected from the user interface.
 void setNavigationStateListener(NavigationStateListener l)
          Set the listener for navigation state change notifications.
 void setRenderingStyle(int style)
          Change the rendering style that the browser should currently be using for all layers.
 void setScene(VRMLScene scene, java.lang.String viewpoint)
          Set the scene to use within this universe.
 void syncUIUpdates()
          Sync UI updates with the Application thread.
 void worldInitComplete()
          Notification from the event model evaluator that the initialization phase is now complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NRUniverse

public NRUniverse(EventModelEvaluator eme)
Construct a default, empty universe that contains no scenegraph.

Parameters:
eme - The event model evaluation processor
Method Detail

worldInitComplete

public void worldInitComplete()
Notification from the event model evaluator that the initialization phase is now complete. Use this to send off the external Browser init event.

Specified by:
worldInitComplete in interface EventModelInitListener

changeWorld

public void changeWorld()
Notification that its safe to clear the world. The underlying rendering layer should now be cleared and loaded with the world.

Specified by:
changeWorld in interface EventModelInitListener

getRendererType

public int getRendererType()
Get the type of renderer that implements the browser core. The only valid values returned are the constants in this interface.

Specified by:
getRendererType in interface BrowserCore
Returns:
The renderer type

getIDString

public java.lang.String getIDString()
Get the ID string for this renderer.

Specified by:
getIDString in interface BrowserCore
Returns:
The String token for this renderer.

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.

Specified by:
setErrorReporter in interface BrowserCore
Parameters:
reporter - The instance to use or null

setRenderingStyle

public void setRenderingStyle(int style)
                       throws java.lang.IllegalArgumentException
Change the rendering style that the browser should currently be using for all layers. Various options are available based on the constants defined in this interface.

Specified by:
setRenderingStyle in interface BrowserCore
Parameters:
style - One of the RENDER_* constants
Throws:
java.lang.IllegalArgumentException - A style constant that is not recognized by the implementation was provided

getRenderingStyle

public int getRenderingStyle()
Get the currently set rendering style. The default style is RENDER_SHADED.

Specified by:
getRenderingStyle in interface BrowserCore
Returns:
one of the RENDER_ constants

setMinimumFrameInterval

public void setMinimumFrameInterval(int millis,
                                    boolean userSet)
Set the minimum frame interval time to limit the CPU resources taken up by the 3D renderer. By default it will use all of them. The second parameter is used to control whether this is a user-set hard minimum or something set by the browser internals. User set values are always treated as the minimum unless the browser internals set a value that is a slower framerate than the user set. If the browser then sets a faster framerate than the user set value, the user value is used instead.

Specified by:
setMinimumFrameInterval in interface BrowserCore
Parameters:
millis - The minimum time in milleseconds.
userSet - true if this is an end-user set minimum

getMinimumFrameInterval

public int getMinimumFrameInterval()
Get the currently set minimum frame cycle interval. Note that this is the minimum interval, not the actual frame rate. Heavy content loads can easily drag this down below the max frame rate that this will generate.

Specified by:
getMinimumFrameInterval in interface BrowserCore
Returns:
The cycle interval time in milliseconds

getVRMLClock

public VRMLClock getVRMLClock()
Get the clock instance in use by the core. We need this for when new nodes are added to the scene to make sure they are all appropriately configured.

Specified by:
getVRMLClock in interface BrowserCore
Returns:
The clock used by the browser core

getDEFMappings

public java.util.Map getDEFMappings()
Get the mapping of DEF names to the node instances that they represent. Primarily used for the EAI functionality. The map instance changes each time a new world is loaded so will need to be re-fetched. If no mappings are available (eg scripting replaceWorld() type call) then the map will be empty.

Specified by:
getDEFMappings in interface BrowserCore
Returns:
The current mapping of DEF names to node instances

getWorldExecutionSpace

public VRMLExecutionSpace getWorldExecutionSpace()
Convenience method to ask for the execution space that the world is currently operating in. Sometimes this is not known, particularly if the end user has called a loadURL type function that is asynchronous. This will change each time a new scene is loaded.

Specified by:
getWorldExecutionSpace in interface BrowserCore
Returns:
The current world execution space.

getDescription

public java.lang.String getDescription()
Get the description string currently used by the world. Returns null if not set or supported.

Specified by:
getDescription in interface BrowserCore
Returns:
The current description string or null

setDescription

public void setDescription(java.lang.String desc)
Set the description of the current world. If the world is operating as part of a web browser then it shall attempt to set the title of the window. If the browser is from a component then the result is dependent on the implementation

Specified by:
setDescription in interface BrowserCore
Parameters:
desc - The description string to set.

getCurrentSpeed

public float getCurrentSpeed()
Get the current velocity of the bound viewpoint in meters per second. The velocity is defined in terms of the world values, not the local coordinate system of the viewpoint.

Specified by:
getCurrentSpeed in interface BrowserCore
Returns:
The velocity in m/s or 0.0 if not supported

getCurrentFrameRate

public float getCurrentFrameRate()
Get the current frame rate of the browser in frames per second.

Specified by:
getCurrentFrameRate in interface BrowserCore
Returns:
The current frame rate or 0.0 if not supported

setLastRenderTime

public void setLastRenderTime(long lastTime)
Set the last frame render time used for FPS calculations. Only the per frame mamanger should call this.

Specified by:
setLastRenderTime in interface BrowserCore
Parameters:
lastTime - The time it took to render the last frame in milliseconds.

setEventModelStatusListener

public void setEventModelStatusListener(EventModelStatusListener l)
Set the eventModelStatus listener.

Specified by:
setEventModelStatusListener in interface BrowserCore
Parameters:
l - The listener. Null will clear it.

addNavigationStateListener

public void addNavigationStateListener(NavigationStateListener l)
Add a listener for navigation state changes. A listener can only be added once. Duplicate requests are ignored.

Specified by:
addNavigationStateListener in interface BrowserCore
Parameters:
l - The listener to add

removeNavigationStateListener

public void removeNavigationStateListener(NavigationStateListener l)
Remove a navigation state listener. If the reference is null or not known, the request is silently ignored.

Specified by:
removeNavigationStateListener in interface BrowserCore
Parameters:
l - The listener to remove

addSensorStatusListener

public void addSensorStatusListener(SensorStatusListener l)
Add a listener for sensor state changes. A listener can only be added once. Duplicate requests are ignored.

Specified by:
addSensorStatusListener in interface BrowserCore
Parameters:
l - The listener to add

removeSensorStatusListener

public void removeSensorStatusListener(SensorStatusListener l)
Remove a sensor state listener. If the reference is null or not known, the request is silently ignored.

Specified by:
removeSensorStatusListener in interface BrowserCore
Parameters:
l - The listener to remove

addViewpointStatusListener

public void addViewpointStatusListener(ViewpointStatusListener l)
Add a listener for viewpoint status changes. A listener can only be added once. Duplicate requests are ignored.

Specified by:
addViewpointStatusListener in interface BrowserCore
Parameters:
l - The listener to add

removeViewpointStatusListener

public void removeViewpointStatusListener(ViewpointStatusListener l)
Remove a viewpoint state listener. If the reference is null or not known, the request is silently ignored.

Specified by:
removeViewpointStatusListener in interface BrowserCore
Parameters:
l - The listener to remove

addNodeObserver

public void addNodeObserver(int nodeType,
                            NodeObserver obs)
Add an observer for a specific node type. A single instance may be registered for more than one type. Each type registered will result in a separate call per frame - one per type. If the observer is currently added for this type ID, the request is ignored.

Specified by:
addNodeObserver in interface BrowserCore
Parameters:
nodeType - The type identifier of the node being observed
obs - The observer instance to add

removeNodeObserver

public void removeNodeObserver(int nodeType,
                               NodeObserver obs)
Remove the given node observer instance for the specific node type. It will not be removed for any other requested node types. If the instance is not registered for the given node type ID, the request will be silently ignored.

Specified by:
removeNodeObserver in interface BrowserCore
Parameters:
nodeType - The type identifier of the node being observed
obs - The observer instance to remove

dispose

public void dispose()
Notify the core that it can dispose all resources. The core cannot be used for rendering after that.

Specified by:
dispose in interface BrowserCore

getWorldURL

public java.lang.String getWorldURL()
Get the fully qualified URL of the currently loaded world. This returns the entire URL including any possible arguments that might be associated with a CGI call or similar mechanism. If the initial world is replaced with loadURL then the string will reflect the new URL. If replaceWorld is called then the URL still represents the original world.

Specified by:
getWorldURL in interface BrowserCore
Returns:
A string of the URL or null if not supported.

setScene

public void setScene(VRMLScene scene,
                     java.lang.String viewpoint)
Set the scene to use within this universe. If null, this will clear this scene and de-register all listeners. The View will be detached from the ViewPlatform and therefore the canvas will go blank.

Specified by:
setScene in interface BrowserCore
Parameters:
scene - The new scene to load, or null
viewpoint - The viewpoint.description to bind to or null for default

changeViewpoint

public void changeViewpoint(VRMLViewpointNodeType vp)
Request that this viewpoint object is bound at the start of the next frame. This method should only be called by external users such as UI toolkits etc that need to synchronize the viewpoint change with rendering loop, but are not able to synchronize themselves because they exist on a different thread that cannot block.

Specified by:
changeViewpoint in interface BrowserCore
Parameters:
vp - The new viewpoint instance to bind to

addCoreListener

public void addCoreListener(BrowserCoreListener l)
Add a listener for browser core events. These events are used to notify all listeners of internal structure changes, such as the browser starting and stopping. A listener can only be added once. Duplicate requests are ignored.

Specified by:
addCoreListener in interface BrowserCore
Parameters:
l - The listener to add

removeCoreListener

public void removeCoreListener(BrowserCoreListener l)
Remove a browser core listener. If the reference is null or not known, the request is silently ignored.

Specified by:
removeCoreListener in interface BrowserCore
Parameters:
l - The listener to remove

addProfilingListener

public void addProfilingListener(ProfilingListener l)
Request notification of profiling information.

Specified by:
addProfilingListener in interface BrowserCore
Parameters:
l - The listener

removeProfilingListener

public void removeProfilingListener(ProfilingListener l)
Remove notification of profiling information.

Specified by:
removeProfilingListener in interface BrowserCore
Parameters:
l - The listener

setNavigationMode

public void setNavigationMode(java.lang.String mode)
Set the navigation mode selected from the user interface.

Specified by:
setNavigationMode in interface BrowserCore
Parameters:
mode - The new mode

getUserPosition

public void getUserPosition(javax.vecmath.Vector3f pos,
                            javax.vecmath.AxisAngle4f ori)
Get the user's location and orientation. This will use the viewpoint bound in the active layer.

Parameters:
pos - The current user position
ori - The current user orientation

fitToWorld

public void fitToWorld(boolean animated)
Move the user's location to see the entire world. Change the users orientation to look at the center of the world.

Specified by:
fitToWorld in interface BrowserCore
Parameters:
animated - Should the transistion be animated. Defaults to FALSE.

syncUIUpdates

public void syncUIUpdates()
Sync UI updates with the Application thread. This method alls the core to push work off to the app thread.

Specified by:
syncUIUpdates in interface BrowserCore

setNavigationStateListener

public void setNavigationStateListener(NavigationStateListener l)
Set the listener for navigation state change notifications. By setting a value of null it will clear the currently set instance

Parameters:
l - The listener to use for change updates

sendURLFailEvent

public void sendURLFailEvent(java.lang.String msg)
Send to the core listeners the error message that a URL failed to load for some reason. This is for the EAI/ESAI spec conformance.

Specified by:
sendURLFailEvent in interface BrowserCore
Parameters:
msg - The message to send

getScene

public VRMLScene getScene()
Get the scene that this universe is currently holding. If none is set then null is returned.

Returns:
The currently set scene instance

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium