Class CRProtoCreator
- All Implemented Interfaces:
NodeTemplateToInstanceCreator
,SceneGraphTraversalSimpleObserver
- Direct Known Subclasses:
NRProtoCreator
,OGLProtoCreator
The creator strips the definition apart and builds a runtime node based on the details and the node factory provided. The creator can handle one instance at a time, although it will correctly parse and build nested proto declarations without extra effort.
We have a small conundrum to deal with - if the proto definition contains SF/MFNode fields, we don't know whether the values should be also generated as real runtime nodes too. Maybe the usage of this node will provide values that are dealt with after this class has finished. Other times, these default values must be used. For this implementation, we have gone with the safety-first approach: Always parse the definition of any SF or MFNode field and turn those into runtime instances. Although this may create extra garbage, there seems to be no nice way of dealing with this issue without a completely different architecture for the library.
Note: Under the current implementation, EXTERNPROTOs are not yet catered for.
- Version:
- $Revision: 1.33 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SceneGraphTraversalSimpleObserver
The current observer.protected org.j3d.util.ErrorReporter
Reporter instance for handing out errorsprotected VRMLNodeFactory
The factory that is used to generate the runtime versionMapping of import names to the copy proxy instanceprotected boolean
Flag to say if the current proto instance is VRML97 capableprotected int
The major version of the spec this instance belongs to.protected int
The minor version of the spec this instance belongs to.protected NodeCopier
Class used to copy SF/MFNode field instancesMapping of declaration node to the J3D versionprotected ProtoCopier
Class used to create the proto body nodesprotected CRProtoInstance
The proto instance we're building upprotected VRMLExecutionSpace
The parent executionSpace used when working with instances of nodes inside the field declarations.protected ProtoScene
The scene as we are building it up during traversalprotected FrameStateManager
The state manager to currently useprotected SceneGraphTraverser
Traverser used to examine SF/MFNode fields and the proto bodyprotected String
The current world's root URL -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CRProtoCreator
(VRMLNodeFactory fac, String worldURL, int major, int minor) Create a new instance of a generic proto creator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fillinInstance
(VRMLNodeTemplate template, VRMLNode nodeInstance, VRMLExecutionSpace space) Given a stubbed instance, fill in the rest of the details.protected void
finishCreate
(PrototypeDecl proto) Internal method to group code together for finishing proto creationvoid
observedNode
(VRMLNodeType parent, VRMLNodeType child, int field, boolean used) Notification of a child node.protected abstract void
protoNode
(VRMLNodeType parent, VRMLProtoInstance proto, int field, boolean used) Separate handler for the proto node, which needs to be renderer-specificvoid
setErrorReporter
(org.j3d.util.ErrorReporter reporter) Register an error reporter with the engine so that any errors generated by the script code can be reported in a nice, pretty fashion.void
Set the frame state manager to use for the builder after this point.protected void
setProtoField
(VRMLNodeType node, int field, int fieldSize, VRMLFieldData data) Process a single field of a contained, nested proto.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.web3d.vrml.lang.NodeTemplateToInstanceCreator
newInstance
-
Field Details
-
factory
The factory that is used to generate the runtime version -
traverser
Traverser used to examine SF/MFNode fields and the proto body -
scene
The scene as we are building it up during traversal -
stateManager
The state manager to currently use -
nodeMap
-
importMap
-
protoInstance
The proto instance we're building up -
rootSpace
The parent executionSpace used when working with instances of nodes inside the field declarations. -
nodeCopier
Class used to copy SF/MFNode field instances -
protoCopier
Class used to create the proto body nodes -
currentObserver
The current observer. May be node or proto copier instance -
errorReporter
protected org.j3d.util.ErrorReporter errorReporterReporter instance for handing out errors -
isVRML97
protected boolean isVRML97Flag to say if the current proto instance is VRML97 capable -
majorVersion
protected int majorVersionThe major version of the spec this instance belongs to. -
minorVersion
protected int minorVersionThe minor version of the spec this instance belongs to. -
worldURL
The current world's root URL
-
-
Constructor Details
-
CRProtoCreator
Create a new instance of a generic proto creator.- Parameters:
fac
- The factory to use (Must generate VRMLNodeType instances)worldURL
- the current world's root URLmajor
- The major version number of this sceneminor
- The minor version number of this scene
-
-
Method Details
-
setErrorReporter
public void setErrorReporter(org.j3d.util.ErrorReporter reporter) Register an error reporter with the engine so that any errors generated by the 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 interfaceNodeTemplateToInstanceCreator
- Parameters:
reporter
- The instance to use or null
-
fillinInstance
public void fillinInstance(VRMLNodeTemplate template, VRMLNode nodeInstance, VRMLExecutionSpace space) Given a stubbed instance, fill in the rest of the details. This is used for extern protos who create a light instance for the scene graph and then after the EP is loaded they fill in the details.- Specified by:
fillinInstance
in interfaceNodeTemplateToInstanceCreator
- Parameters:
template
- The proto definition loaded from the EPnodeInstance
- The instance to fill outspace
- The execution space this node belongs in
-
observedNode
Notification of a child node.- Specified by:
observedNode
in interfaceSceneGraphTraversalSimpleObserver
- Parameters:
parent
- The parent node of this nodechild
- The child node that is being observedfield
- The index of the child field in its parent nodeused
- true if the node reference is actually a USE
-
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.- Parameters:
fsm
- The state manager to use
-
protoNode
protected abstract void protoNode(VRMLNodeType parent, VRMLProtoInstance proto, int field, boolean used) Separate handler for the proto node, which needs to be renderer-specific- Parameters:
parent
- The parent node of this nodeproto
- The proto node that has been foundfield
- The index of the child field in its parent nodeused
- true if the node reference is actually a USE
-
finishCreate
Internal method to group code together for finishing proto creation- Parameters:
proto
- The decl of the proto
-
setProtoField
protected void setProtoField(VRMLNodeType node, int field, int fieldSize, VRMLFieldData data) throws FieldException Process a single field of a contained, nested proto.- Parameters:
node
- The node reference we are sending the value tofield
- The index of the field to set the data forfieldSize
- The size of field to set the data fordata
- The source data used to set the field- Throws:
FieldException
- Any one of the normal field exceptions
-