Package org.web3d.vrml.renderer.ogl
Class OGLVRMLSceneBuilder
java.lang.Object
org.web3d.vrml.renderer.ogl.OGLVRMLSceneBuilder
- All Implemented Interfaces:
BinaryContentHandler
,ContentHandler
,ProtoHandler
,RouteHandler
,ScriptHandler
,StringContentHandler
,SceneBuilder
A OpenGL file loader implementation for reading VRML and X3D files and
building a OpenGL scene graph with them.
If the user 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.
- Version:
- $Revision: 1.28 $
- Author:
- Justin Couch
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new default instance of the scene builder.Create a scene builder with the given node factory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
allowVRML97Only
(boolean enabled) Change the builder to recognise only VRML97 content or allow any version to be loaded.void
componentDecl
(String componentInfo) A component declaration has been found in the code.void
Declaration of the end of the document.void
Notification of the end of an EXTERNPROTO declaration.void
endField()
Notification of the end of a field declaration.void
endNode()
Notification of the end of a node declaration.void
Notification of the end of an ordinary proto body.void
Notification of the end of an ordinary proto declaration statement.void
Notification of the end of a script declaration.void
exportDecl
(String defName, String exported) An EXPORT declaration has been found in the document.void
externProtoURI
(String[] values) Notification of the URI list for an EXTERNPROTO.void
fieldValue
(boolean value) Set the value of the field at the given index as an boolean.void
fieldValue
(boolean[] value, int len) Set the value of the field at the given index as an array of boolean.void
fieldValue
(double value) Set the value of the field at the given index as an double.void
fieldValue
(double[] value, int len) Set the value of the field at the given index as an array of doubles.void
fieldValue
(float value) Set the value of the field at the given index as a float.void
fieldValue
(float[] value, int len) Set the value of the field at the given index as an array of floats.void
fieldValue
(int value) Set the value of the field at the given index as an integer.void
fieldValue
(int[] value, int len) Set the value of the field at the given index as an array of integers.void
fieldValue
(long value) Set the value of the field at the given index as an long.void
fieldValue
(long[] value, int len) Set the value of the field at the given index as an array of longs.void
fieldValue
(String value) The value of a normal field.void
fieldValue
(String[] values) The value of an MFField where the underlying parser knows about how the values are broken up.void
fieldValue
(String[] value, int len) Set the value of the field at the given index as an array of strings.getScene()
Get the scene that was last built by this scene handler.void
importDecl
(String inline, String exported, String imported) An IMPORT declaration has been found in the document.void
A META declaration has been found in the code.void
profileDecl
(String profileName) A profile declaration has been found in the code.void
protoFieldDecl
(int access, String type, String name, Object value) Notification of a proto's field declaration.void
protoIsDecl
(String fieldName) Notification of a field value uses an IS statement.void
Release any references to the scene that was last built by this scene handler.void
reset()
Reset the builder.void
Notification of a ROUTE declaration in the file.void
scriptFieldDecl
(int access, String type, String name, Object value) Notification of a script's field declaration.void
Set the document locator that can be used by the implementing code to find out information about the current line information.void
setErrorReporter
(org.j3d.util.ErrorReporter reporter) Set the error handler instance used by this instance of the builder.void
Set the frame state manager to use for the builder after this point.void
setLoadRequirements
(boolean useBackgrounds, boolean useFogs, boolean useLights, boolean useAudio, boolean useViewpoints, boolean useExternals) Set the flags about what to load.void
Begin parsingvoid
startExternProtoDecl
(String name) Notification of the start of an EXTERNPROTO declaration of the given name.void
startField
(String name) Notification of a field declaration.void
Notification of the start of a node.void
Notification of the start of an ordinary proto body.void
startProtoDecl
(String name) Notification of the start of an ordinary (inline) proto declaration.void
Notification of the start of a script declaration.void
The field value is a USE for the given node name.
-
Constructor Details
-
OGLVRMLSceneBuilder
public OGLVRMLSceneBuilder()Create a new default instance of the scene builder. This uses the default factory for nodes. -
OGLVRMLSceneBuilder
Create a scene builder with the given node factory. The factory should be producing nodes that conform to theOGLVRMLNode
interface as we expect some of the capabilities to be there. Using any other form of factory is asking for errors. If the factory reference is null then the default factory will be used.- Parameters:
fac
- The factory instance to use.
-
-
Method Details
-
setErrorReporter
public void setErrorReporter(org.j3d.util.ErrorReporter reporter) Set the error handler instance used by this instance of the builder. The handler is used to report errors at the higher level. A value of null will clear the current instance and return to the default handling.- Specified by:
setErrorReporter
in interfaceSceneBuilder
- Parameters:
reporter
- The instance to use or null to clear
-
getScene
Get the scene that was last built by this scene handler. If none of the methods have been called yet, this will return a null reference. 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:
getScene
in interfaceSceneBuilder
- Returns:
- The last built scene
-
releaseScene
public void releaseScene()Release any references to the scene that was last built by this scene handler. This should be called by the loader after a reference to the scene has been retrieved using the getScene() method.- Specified by:
releaseScene
in interfaceSceneBuilder
-
reset
public void reset()Reset the builder. This is used to make sure that the builder has been reset after a parsing run just in case the last parsing run exited abnormally and left us in an odd state. Sometimes this can prevent us from parsing again. This method should be called just before theVRMLReader.parse()
method is called.The flags set about what to load are not reset by this method.
- Specified by:
reset
in interfaceSceneBuilder
-
allowVRML97Only
public void allowVRML97Only(boolean enabled) Change the builder to recognise only VRML97 content or allow any version to be loaded.- Specified by:
allowVRML97Only
in interfaceSceneBuilder
- Parameters:
enabled
- true to restrict content to VRML97 only
-
setFrameStateManager
Set the frame state manager to use for the builder after this point. Set a value of null it will clear the currently set items.- Specified by:
setFrameStateManager
in interfaceSceneBuilder
- Parameters:
fsm
- The state manager to use
-
setDocumentLocator
Set the document locator that can be used by the implementing code to find out information about the current line information. This method is called by the parser to your code to give you a locator to work with. If this has not been set by the timestartDocument()
has been called, you can assume that you will not have one available.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Parameters:
loc
- The locator instance to use
-
startDocument
public void startDocument(String uri, String url, String encoding, String type, String version, String comment) throws SAVException, VRMLException Begin parsing- Specified by:
startDocument
in interfaceContentHandler
- Parameters:
uri
- full path of directory and filenameurl
- directory pathencoding
- utf8 for VRML, xml for XMLtype
- example #X3D for ClassicVRML, ___ for XMLversion
- example V3.0 (VRML) or 3.3 (X3D)comment
- optional- Throws:
SAVException
VRMLException
-
profileDecl
A profile declaration has been found in the code. A proto builder should never encounter this situation.- Specified by:
profileDecl
in interfaceContentHandler
- Parameters:
profileName
- The name of the profile to use- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
componentDecl
A component declaration has been found in the code. A proto builder should never encounter this situation.- Specified by:
componentDecl
in interfaceContentHandler
- Parameters:
componentInfo
- The name of the component to use- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
metaDecl
A META declaration has been found in the code. There may be zero or more meta declarations in the file, appearing just after the component declaration. Each meta declaration has a key and value strings. No information is to be implied from this. It is for extra data only.- Specified by:
metaDecl
in interfaceContentHandler
- Parameters:
key
- The value of the key stringvalue
- The value of the value string- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
importDecl
public void importDecl(String inline, String exported, String imported) throws SAVException, VRMLException An IMPORT declaration has been found in the document. All three parameters will always be provided, regardless of whether the AS keyword has been used or not. The parser implementation will automatically set the local import name as needed.- Specified by:
importDecl
in interfaceContentHandler
- Parameters:
inline
- The name of the inline DEF nodesexported
- The exported name from the inlined fileimported
- The local name to use for the exported name- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
exportDecl
An EXPORT declaration has been found in the document. Both parameters will always be provided regardless of whether the AS keyword has been used. The parser implementation will automatically set the exported name as needed.- Specified by:
exportDecl
in interfaceContentHandler
- Parameters:
defName
- The DEF name of the nodes to be exportedexported
- The name to be exported as- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
endDocument
Declaration of the end of the document. There will be no further parsing and hence events after this.- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
startNode
Notification of the start of a node. This is the opening statement of a node and it's DEF name. USE declarations are handled in a separate method.- Specified by:
startNode
in interfaceContentHandler
- Parameters:
name
- The name of the node that we are about to parsedefName
- The string associated with the DEF name. Null if not given for this node.- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
endNode
Notification of the end of a node declaration.- Specified by:
endNode
in interfaceContentHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
startField
Notification of a field declaration. This notification is only called if it is a standard node. If the node is a script or PROTO declaration then theScriptHandler
orProtoHandler
methods are used.- Specified by:
startField
in interfaceContentHandler
- Parameters:
name
- The name of the field declared- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
fieldValue
The value of a normal field. This is a string that represents the entire value of the field. MFStrings will have to be parsed. This is a terminating call for startField as well. The next call will either be anotherstartField()
orendNode()
.If this field is an SFNode with a USE declaration you will have the
useDecl(String)
method called rather than this method.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Specified by:
fieldValue
in interfaceStringContentHandler
- Parameters:
value
- The value of this field- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
fieldValue
The value of an MFField where the underlying parser knows about how the values are broken up. The parser is not required to support this callback, but implementors of this interface should understand it. The most likely time we will have this method called is for MFString or URL lists. If called, it is guaranteed to split the strings along the SF node type boundaries.- Specified by:
fieldValue
in interfaceStringContentHandler
- Parameters:
values
- The list of string representing the values- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
useDecl
The field value is a USE for the given node name. This is a terminating call for startField as well. The next call will either be anotherstartField()
orendNode()
.- Specified by:
useDecl
in interfaceContentHandler
- Parameters:
defName
- The name of the DEF string to use- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
endField
Notification of the end of a field declaration. This is called only at the end of an MFNode declaration. All other fields are terminated by eitheruseDecl(String)
orfieldValue(String)
.- Specified by:
endField
in interfaceContentHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
fieldValue
Set the value of the field at the given index as an integer. This would be used to set SFInt32 field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the node- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an array of integers. This would be used to set MFInt32 field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the nodelen
- The number of valid entries in the value array- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an boolean. This would be used to set SFBool field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the node- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an array of boolean. This would be used to set MFBool field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the nodelen
- The number of valid entries in the value array- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as a float. This would be used to set SFFloat field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the node- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an array of floats. This would be used to set MFFloat, SFVec2f, SFVec3f and SFRotation field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the nodelen
- The number of valid entries in the value array- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an long. This would be used to set SFTime field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the node- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an array of longs. This would be used to set MFTime field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the nodelen
- The number of valid entries in the value array- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an double. This would be used to set SFDouble field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the node- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an array of doubles. This would be used to set MFDouble, SFVec2d and SFVec3d field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the nodelen
- The number of valid entries in the value array- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
fieldValue
Set the value of the field at the given index as an array of strings. This would be used to set MFString field types.- Specified by:
fieldValue
in interfaceBinaryContentHandler
- Parameters:
value
- The new value to use for the nodelen
- The number of valid entries in the value array- Throws:
SAVException
- This call is taken at the wrong time in the structure of the document.VRMLException
- This call is taken at the wrong time in the structure of the document.
-
startProtoDecl
Notification of the start of an ordinary (inline) proto declaration. The proto has the given node name.- Specified by:
startProtoDecl
in interfaceProtoHandler
- Parameters:
name
- The name of the proto- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
endProtoDecl
Notification of the end of an ordinary proto declaration statement.- Specified by:
endProtoDecl
in interfaceProtoHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
protoFieldDecl
public void protoFieldDecl(int access, String type, String name, Object value) throws SAVException, VRMLException Notification of a proto's field declaration. This is used for both external and ordinary protos. Externprotos don't allow the declaration of a value for the field. In this case, the parameter value will be null.- Specified by:
protoFieldDecl
in interfaceProtoHandler
- Parameters:
access
- The access type (eg exposedField, field etc)type
- The field type (eg SFInt32, MFVec3d etc)name
- The name of the fieldvalue
- The default value of the field. Null if not allowed.- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
protoIsDecl
Notification of a field value uses an IS statement. If we are running in VRML97 mode, this will throw an exception if the field access types do not match.- Specified by:
protoIsDecl
in interfaceProtoHandler
- Parameters:
fieldName
- The name of the field that is being IS'd- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
startProtoBody
Notification of the start of an ordinary proto body. All nodes contained between here and the correspondingendProtoBody()
statement form the body and not the normal scene graph information.- Specified by:
startProtoBody
in interfaceProtoHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
endProtoBody
Notification of the end of an ordinary proto body. Parsing now returns to ordinary node declarations.- Specified by:
endProtoBody
in interfaceProtoHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
startExternProtoDecl
Notification of the start of an EXTERNPROTO declaration of the given name. Between here and the matchingendExternProtoDecl()
call you should only receiveprotoFieldDecl(int, java.lang.String, java.lang.String, java.lang.Object)
calls.- Specified by:
startExternProtoDecl
in interfaceProtoHandler
- Parameters:
name
- The node name of the extern proto- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
endExternProtoDecl
Notification of the end of an EXTERNPROTO declaration.- Specified by:
endExternProtoDecl
in interfaceProtoHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
externProtoURI
Notification of the URI list for an EXTERNPROTO. This is a complete list of URIs. The calling application is required to interpet the incoming strings. Even if the externproto has no URIs registered, this method shall be called. If there are none available, this will be called with a zero length list of values.- Specified by:
externProtoURI
in interfaceProtoHandler
- Parameters:
values
- A list of strings representing all of the URI values- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
startScriptDecl
Notification of the start of a script declaration. All calls between now and the correspondingendScriptDecl()
call belong to this script node. This method will be called after the ContentHandlerstartNode()
method call. All DEF information is contained in that method call and this just signifies the start of script processing so that we know to treat the field parsing callbacks a little differently.- Specified by:
startScriptDecl
in interfaceScriptHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
endScriptDecl
Notification of the end of a script declaration. This is guaranteed to be called before the ContentHandlerendNode()
callback.- Specified by:
endScriptDecl
in interfaceScriptHandler
- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
scriptFieldDecl
public void scriptFieldDecl(int access, String type, String name, Object value) throws SAVException, VRMLException Notification of a script's field declaration. This is used for all fields excepturl
,mustEvaluate
anddirectOutput
fields. These fields use the normal field callbacks ofContentHandler
.- Specified by:
scriptFieldDecl
in interfaceScriptHandler
- Parameters:
access
- The access type (eg exposedField, field etc)type
- The field type (eg SFInt32, MFVec3d etc)name
- The name of the fieldvalue
- The default value of the field- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
routeDecl
public void routeDecl(String srcNodeName, String srcFieldName, String destNodeName, String destFieldName) throws SAVException, VRMLException Notification of a ROUTE declaration in the file. The context of this route should be assumed from the surrounding calls to start and end of proto and node bodies.- Specified by:
routeDecl
in interfaceRouteHandler
- Parameters:
srcNodeName
- The name of the DEF of the source nodesrcFieldName
- The name of the field to route values fromdestNodeName
- The name of the DEF of the destination nodedestFieldName
- The name of the field to route values to- Throws:
SAVException
- This call is taken at the wrong time in the structure of the documentVRMLException
- The content provided is invalid for this part of the document or can't be parsed
-
setLoadRequirements
public void setLoadRequirements(boolean useBackgrounds, boolean useFogs, boolean useLights, boolean useAudio, boolean useViewpoints, boolean useExternals) Set the flags about what to load. The flags defined here are matched by the Java 3D Loader Nodes defined as externals are inlines and extern protos. This method should be called after theallowVRML97Only(boolean)
method as it uses that flag.- Parameters:
useBackgrounds
- true if BackgroundNodeTypes should be loadeduseFogs
- true if FogNodeTypes should be loadeduseLights
- true if LightNodeTypes should be loadeduseAudio
- true if AudioClipNodeTypes should be loadeduseViewpoints
- true if ViewpointNodeTypes should loadeduseExternals
- true if ExternalNodeTypes should be loaded
-