Class ColladaRoot
- java.lang.Object
-
- gov.nasa.worldwind.util.xml.AbstractXMLEventParser
-
- gov.nasa.worldwind.ogc.collada.ColladaAbstractObject
-
- gov.nasa.worldwind.ogc.collada.ColladaRoot
-
- All Implemented Interfaces:
ColladaRenderable,Highlightable,XMLEventParser
public class ColladaRoot extends ColladaAbstractObject implements ColladaRenderable, Highlightable
Parses a COLLADA document and provides access to its contents. Instructions for parsing COLLADA files and streams are given in the Description section ofgov.nasa.worldwind.ogc.collada.
-
-
Field Summary
Fields Modifier and Type Field Description protected intaltitudeModeThis shape's altitude mode.protected ColladaDoccolladaDocReference to the ColladaDoc representing the COLLADA file.protected javax.xml.stream.XMLEventReadereventReaderThe event reader used to parse the document's XML.protected java.io.InputStreameventStreamThe input stream underlying the event reader.protected AngleheadingThis shape's heading, positive values are clockwise from north.protected booleanhighlightedIndicates whether or not the COLLADA model is highlighted.protected MatrixmatrixTransform matrix computed from the document's scale and orientation.protected Vec4modelScaleA scale to apply to the model.protected ColladaParserContextparserContextThe parser context for the document.protected AnglepitchThis shape's pitch (often called tilt), its rotation about the model's X axis.protected PositionpositionThis shape's geographic location.protected ColladaResourceResolverresourceResolverResource resolver to resolve relative file paths.protected AnglerollThis shape's roll, its rotation about the model's Y axis.protected doublescaleScale applied to the model.protected booleanscaleFetchedFlag to indicate that the scale has been computed.protected ColladaScenesceneCached COLLADA scene.protected booleansceneFetchedFlag to indicate that the scene has been retrieved from the hash map.-
Fields inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
CHARACTERS_CONTENT, fields, namespaceURI, parent
-
-
Constructor Summary
Constructors Constructor Description ColladaRoot(ColladaDoc docSource)Create a newColladaRootfor aColladaDocinstance.ColladaRoot(java.io.File docSource)Create a newColladaRootfor aFile.ColladaRoot(java.io.InputStream docSource)Create a newColladaRootfor aInputStream.ColladaRoot(java.net.URL docSource)Create a newColladaRootfor aURL.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanParseContentType(java.lang.String mimeType)Determines if a MIME type can be parsed as COLLADA.protected voidcloseEventStream()Closes the event stream associated with this context's XML event reader.protected doublecomputeScale()Indicates the scale defined by the asset/unit element.static ColladaRootcreate(java.lang.Object docSource)Creates a Collada root for an untyped source.static ColladaRootcreateAndParse(java.lang.Object docSource)Creates and parses a Collada root for an untyped source.The source must be either aFileor aStringidentifying either a file path or aURL.protected ColladaParserContextcreateParserContext(javax.xml.stream.XMLEventReader reader)Invoked duringinitialize()to create the parser context.protected javax.xml.stream.XMLEventReadercreateReader(java.lang.Object docSource)Creates the event reader.intgetAltitudeMode()Returns this shape's altitude mode.ColladaAssetgetAsset()Indicates the asset field of this document.protected ColladaDocgetColladaDoc()Indicates the document that is the source of this root.AnglegetHeading()Indicates this shape's heading, its rotation clockwise from north.java.lang.ObjectgetItemByID(java.lang.String id)Finds a named element in the document.BoxgetLocalExtent(ColladaTraversalContext tc)Returns this renderable's model coordinate extent.protected MatrixgetMatrix()Indicates the transform matrix applied to this document.Vec4getModelScale()Indicates this shape's scale, if any.protected XMLEventParserContextgetParserContext()Indicates the parser context used by this document.AnglegetPitch()Indicates this shape's pitch -- often referred to as tilt -- the angle to rotate this shape's model about its X axis.PositiongetPosition()Indicates this shape's geographic position.ColladaResourceResolvergetResourceResolver()Indicates the resource resolver used to resolve relative file paths.AnglegetRoll()Indicates this shape's roll, the angle to rotate this shape's model about its Y axis.protected doublegetScale()Indicates the scale factored applied to this document.ColladaScenegetScene()Indicates the scene contained in this document.java.lang.StringgetSupportFilePath(java.lang.String link)Determines the path of a supporting file (such an image).protected voidinitialize()Called just before the constructor returns.booleanisHighlighted()Indicates whether to highlight the shape.ColladaRootparse(java.lang.Object... args)Starts document parsing.protected ColladaRootparseCachedColladaFile(java.net.URL url, java.lang.String linkBase)Open and parse the specified file expressed as a file: URL..voidpreRender(ColladaTraversalContext tc, DrawContext dc)Pre-Render this element.voidrender(ColladaTraversalContext tc, DrawContext dc)Render this element.protected voidreset()Clear cached values.protected java.lang.ObjectresolveLocalReference(java.lang.String linkBase, java.lang.String linkRef)Resolves a reference to a local element identified by address and identifier, wherelinkBaseidentifies a document, including the current document, andlinkRefis the id of the desired element.java.lang.ObjectresolveReference(java.lang.String link)Resolves a reference to a local or remote file or element.java.lang.ObjectresolveRemoteReference(java.lang.String linkBase, java.lang.String linkRef)Resolves a reference to a remote element identified by address and identifier, wherelinkBaseidentifies a remote document, andlinkRefis the id of the desired element.voidsetAltitudeMode(int altitudeMode)Specifies this shape's altitude mode, one ofWorldWind.ABSOLUTE,WorldWind.RELATIVE_TO_GROUNDorWorldWind.CLAMP_TO_GROUND.voidsetHeading(Angle heading)Specifies this shape's heading, its rotation clockwise from north.voidsetHighlighted(boolean highlighted)Specifies whether to highlight the shape.voidsetModelScale(Vec4 modelScale)Specifies this shape's scale.voidsetPitch(Angle pitch)Specifies this shape's pitch -- often referred to as tilt -- the angle to rotate this shape's model about its X axis.voidsetPosition(Position position)Specifies this shape's geographic position.voidsetResourceResolver(ColladaResourceResolver resourceResolver)Specifies a resource resolver to resolve relative file paths.voidsetRoll(Angle roll)Specifies this shape's roll, the angle to rotate this shape's model about its Y axis.-
Methods inherited from class gov.nasa.worldwind.ogc.collada.ColladaAbstractObject
getRoot
-
Methods inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
allocate, doAddCharacters, doAddEventAttribute, doAddEventContent, doParseEventAttributes, doParseEventContent, freeResources, getAConstructor, getCharacters, getField, getField, getFields, getNamespaceURI, getParent, hasField, hasField, hasFields, mergeFields, newInstance, overrideFields, parse, parseCharacterContent, removeField, setField, setField, setFields, setNamespaceURI, setParent
-
-
-
-
Field Detail
-
colladaDoc
protected ColladaDoc colladaDoc
Reference to the ColladaDoc representing the COLLADA file.
-
eventReader
protected javax.xml.stream.XMLEventReader eventReader
The event reader used to parse the document's XML.
-
eventStream
protected java.io.InputStream eventStream
The input stream underlying the event reader.
-
parserContext
protected ColladaParserContext parserContext
The parser context for the document.
-
position
protected Position position
This shape's geographic location. The altitude is relative to this shapes altitude mode.
-
altitudeMode
protected int altitudeMode
This shape's altitude mode. May be one ofWorldWind.CLAMP_TO_GROUND,WorldWind.RELATIVE_TO_GROUND, orWorldWind.ABSOLUTE.
-
heading
protected Angle heading
This shape's heading, positive values are clockwise from north. Null is an allowed value.
-
pitch
protected Angle pitch
This shape's pitch (often called tilt), its rotation about the model's X axis. Positive values are clockwise. Null is an allowed value.
-
roll
protected Angle roll
This shape's roll, its rotation about the model's Y axis. Positive values are clockwise. Null is an allowed Value.
-
modelScale
protected Vec4 modelScale
A scale to apply to the model. Null is an allowed value.
-
sceneFetched
protected boolean sceneFetched
Flag to indicate that the scene has been retrieved from the hash map.
-
scene
protected ColladaScene scene
Cached COLLADA scene.
-
scaleFetched
protected boolean scaleFetched
Flag to indicate that the scale has been computed.
-
scale
protected double scale
Scale applied to the model. Determined by the COLLADA/asset/unit element.
-
highlighted
protected boolean highlighted
Indicates whether or not the COLLADA model is highlighted.
-
matrix
protected Matrix matrix
Transform matrix computed from the document's scale and orientation. This matrix is computed and cached during when the document is rendered.
-
resourceResolver
protected ColladaResourceResolver resourceResolver
Resource resolver to resolve relative file paths.
-
-
Constructor Detail
-
ColladaRoot
public ColladaRoot(ColladaDoc docSource) throws java.io.IOException
Create a newColladaRootfor aColladaDocinstance. A ColladaDoc represents COLLADA files from either files or input streams.- Parameters:
docSource- the ColladaDoc instance representing the COLLADA document.- Throws:
java.lang.IllegalArgumentException- if the document source is null.java.io.IOException- if an error occurs while reading the COLLADA document.
-
ColladaRoot
public ColladaRoot(java.io.File docSource) throws java.io.IOExceptionCreate a newColladaRootfor aFile.- Parameters:
docSource- the File containing the document.- Throws:
java.lang.IllegalArgumentException- if the document source is null.java.io.IOException- if an error occurs while reading the Collada document.
-
ColladaRoot
public ColladaRoot(java.net.URL docSource) throws java.io.IOExceptionCreate a newColladaRootfor aURL.- Parameters:
docSource- the URL of the document.- Throws:
java.lang.IllegalArgumentException- if the document source is null.java.io.IOException- if an error occurs while reading the Collada document.
-
ColladaRoot
public ColladaRoot(java.io.InputStream docSource) throws java.io.IOExceptionCreate a newColladaRootfor aInputStream.- Parameters:
docSource- the URL of the document.- Throws:
java.lang.IllegalArgumentException- if the document source is null.java.io.IOException- if an error occurs while reading the Collada document.
-
-
Method Detail
-
create
public static ColladaRoot create(java.lang.Object docSource) throws java.io.IOException
Creates a Collada root for an untyped source. The source must be either aFileor aStringidentifying either a file path or aURL. Null is returned if the source type is not recognized.- Parameters:
docSource- either aFileor aStringidentifying a file path orURL.- Returns:
- a new
ColladaRootfor the specified source, or null if the source type is not supported. - Throws:
java.lang.IllegalArgumentException- if the source is null.java.io.IOException- if an error occurs while reading the source.
-
createAndParse
public static ColladaRoot createAndParse(java.lang.Object docSource) throws java.io.IOException, javax.xml.stream.XMLStreamException
Creates and parses a Collada root for an untyped source.The source must be either aFileor aStringidentifying either a file path or aURL. Null is returned if the source type is not recognized.- Parameters:
docSource- either aFileor aStringidentifying a file path orURL.- Returns:
- a new
ColladaRootfor the specified source, or null if the source type is not supported. - Throws:
java.lang.IllegalArgumentException- if the source is null.javax.xml.stream.XMLStreamException- if the XML stream is not readable.java.io.IOException- if an error occurs while reading the source.
-
initialize
protected void initialize() throws java.io.IOExceptionCalled just before the constructor returns. If overriding this method be sure to invokesuper.initialize().- Throws:
java.io.IOException- if an I/O error occurs attempting to open the document source.
-
getColladaDoc
protected ColladaDoc getColladaDoc()
Indicates the document that is the source of this root.- Returns:
- The source of the COLLADA content.
-
getPosition
public Position getPosition()
Indicates this shape's geographic position.- Returns:
- this shape's geographic position. The position's altitude is relative to this shape's altitude mode.
-
setPosition
public void setPosition(Position position)
Specifies this shape's geographic position. The position's altitude is relative to this shape's altitude mode.- Parameters:
position- this shape's geographic position.- Throws:
java.lang.IllegalArgumentException- if the position is null.
-
getAltitudeMode
public int getAltitudeMode()
Returns this shape's altitude mode.- Returns:
- this shape's altitude mode.
- See Also:
setAltitudeMode(int)
-
setAltitudeMode
public void setAltitudeMode(int altitudeMode)
Specifies this shape's altitude mode, one ofWorldWind.ABSOLUTE,WorldWind.RELATIVE_TO_GROUNDorWorldWind.CLAMP_TO_GROUND.Note: If the altitude mode is unrecognized,
WorldWind.ABSOLUTEis used.Note: Subclasses may recognize additional altitude modes or may not recognize the ones described above.
- Parameters:
altitudeMode- the altitude mode. The default value isWorldWind.ABSOLUTE.
-
getHeading
public Angle getHeading()
Indicates this shape's heading, its rotation clockwise from north.- Returns:
- this shape's heading, or null if no heading has been specified.
-
setHeading
public void setHeading(Angle heading)
Specifies this shape's heading, its rotation clockwise from north.- Parameters:
heading- this shape's heading. May be null.
-
getPitch
public Angle getPitch()
Indicates this shape's pitch -- often referred to as tilt -- the angle to rotate this shape's model about its X axis.- Returns:
- this shape's pitch, or null if no pitch has been specified. Positive values are clockwise as observed looking along the model's X axis toward the model's origin.
-
setPitch
public void setPitch(Angle pitch)
Specifies this shape's pitch -- often referred to as tilt -- the angle to rotate this shape's model about its X axis.- Parameters:
pitch- this shape's pitch. Positive values are clockwise as observed looking along the model's X axis toward the model's origin. May be null.
-
getRoll
public Angle getRoll()
Indicates this shape's roll, the angle to rotate this shape's model about its Y axis.- Returns:
- this shape's roll, or null if no roll has been specified. Positive values are clockwise as observed looking along the model's Y axis toward the origin.
-
setRoll
public void setRoll(Angle roll)
Specifies this shape's roll, the angle to rotate this shape's model about its Y axis.- Parameters:
roll- this shape's roll. May be null. Positive values are clockwise as observed looking along the model's Y axis toward the origin.
-
getModelScale
public Vec4 getModelScale()
Indicates this shape's scale, if any.- Returns:
- this shape's scale, or null if no scale has been specified.
-
setModelScale
public void setModelScale(Vec4 modelScale)
Specifies this shape's scale. The scale is applied to the shape's model definition in the model's coordinate system prior to oriented and positioning the model.- Parameters:
modelScale- this shape's scale. May be null, in which case no scaling is applied.
-
getResourceResolver
public ColladaResourceResolver getResourceResolver()
Indicates the resource resolver used to resolve relative file paths.- Returns:
- The resource resolver, or null if none is set.
-
setResourceResolver
public void setResourceResolver(ColladaResourceResolver resourceResolver)
Specifies a resource resolver to resolve relative file paths.- Parameters:
resourceResolver- New resource resolver. May be null.
-
isHighlighted
public boolean isHighlighted()
Indicates whether to highlight the shape.- Specified by:
isHighlightedin interfaceHighlightable- Returns:
- true to highlight the shape, otherwise false.
-
setHighlighted
public void setHighlighted(boolean highlighted)
Specifies whether to highlight the shape. Setting root COLLADA root highlighted causes all parts of the COLLADA model to highlight.- Specified by:
setHighlightedin interfaceHighlightable- Parameters:
highlighted- true to highlight the shape, otherwise false.
-
resolveReference
public java.lang.Object resolveReference(java.lang.String link)
Resolves a reference to a local or remote file or element. If the link refers to an element in the current document, this method returns that element. If the link refers to a remote document, this method will initiate asynchronous retrieval of the document, and return a URL of the downloaded document in the file cache, if it is available locally. If the link identifies a COLLADA document, the document will be returned as a parsed ColladaRoot.- Parameters:
link- the address of the document or element to resolve. This may be a full URL, a URL fragment that identifies an element in the current document ("#myElement"), or a URL and a fragment identifier ("http://server.com/model.dae#myElement").- Returns:
- the requested element, or null if the element is not found.
- Throws:
java.lang.IllegalArgumentException- if the address is null.
-
resolveLocalReference
protected java.lang.Object resolveLocalReference(java.lang.String linkBase, java.lang.String linkRef)Resolves a reference to a local element identified by address and identifier, wherelinkBaseidentifies a document, including the current document, andlinkRefis the id of the desired element.If
linkBaserefers to a local COLLADA file andlinkRefis non-null, the return value is the element identified bylinkRef. IflinkRefis null, the return value is a parsedColladaRootfor the COLLADA file identified bylinkBase. Otherwise,linkBaseis returned.- Parameters:
linkBase- the address of the document containing the requested element.linkRef- the element's identifier.- Returns:
- the requested element, or null if the element is not found.
- Throws:
java.lang.IllegalArgumentException- if the address is null.
-
resolveRemoteReference
public java.lang.Object resolveRemoteReference(java.lang.String linkBase, java.lang.String linkRef)Resolves a reference to a remote element identified by address and identifier, wherelinkBaseidentifies a remote document, andlinkRefis the id of the desired element. This method retrieves resources asynchronously using theFileStore.The return value is null if the file is not yet available in the FileStore. If
linkBaserefers to a COLLADA file andlinkRefis non-null, the return value is the element identified bylinkRef. IflinkBaserefers to a COLLADA file andlinkRefis null, the return value is a parsedColladaRootfor the COLLADA file identified bylinkBase. Otherwise the return value is aURLto the file in the file cache.- Parameters:
linkBase- the address of the document containing the requested element.linkRef- the element's identifier.- Returns:
- URL to the requested file, parsed ColladaRoot, or COLLADA element. Returns null if the document is not yet available in the FileStore.
- Throws:
java.lang.IllegalArgumentException- if thelinkBaseis null.
-
canParseContentType
protected boolean canParseContentType(java.lang.String mimeType)
Determines if a MIME type can be parsed as COLLADA. Parsable types are the COLLADA MIME type, as well as "text/plain" and "text/xml".- Parameters:
mimeType- Type to test. May be null.- Returns:
trueifmimeTypecan be parsed as COLLADA.
-
parseCachedColladaFile
protected ColladaRoot parseCachedColladaFile(java.net.URL url, java.lang.String linkBase) throws java.io.IOException, javax.xml.stream.XMLStreamException
Open and parse the specified file expressed as a file: URL..- Parameters:
url- the URL of the file to open, expressed as a URL with a scheme of "file".linkBase- the original address of the document if the file is a retrieved and cached file.- Returns:
- A
ColladaRootrepresenting the file's COLLADA contents. - Throws:
java.io.IOException- if an I/O error occurs during opening and parsing.javax.xml.stream.XMLStreamException- if a server parsing error is encountered.
-
createReader
protected javax.xml.stream.XMLEventReader createReader(java.lang.Object docSource)
Creates the event reader. Called from the constructor.- Parameters:
docSource- the document source to create a reader for. The type can be any of those supported byWWXML.openEventReader(Object).- Returns:
- a new event reader, or null if the source type cannot be determined.
-
createParserContext
protected ColladaParserContext createParserContext(javax.xml.stream.XMLEventReader reader)
Invoked duringinitialize()to create the parser context. The parser context is created by the globalXMLEventParserContextFactory.- Parameters:
reader- the reader to associate with the parser context.- Returns:
- a new parser context.
-
parse
public ColladaRoot parse(java.lang.Object... args) throws javax.xml.stream.XMLStreamException
Starts document parsing. This method initiates parsing of the COLLADA document and returns when the full document has been parsed.- Parameters:
args- optional arguments to pass to parsers of sub-elements.- Returns:
thisif parsing is successful, otherwise null.- Throws:
javax.xml.stream.XMLStreamException- if an exception occurs while attempting to read the event stream.
-
closeEventStream
protected void closeEventStream()
Closes the event stream associated with this context's XML event reader.
-
getScene
public ColladaScene getScene()
Indicates the scene contained in this document.- Returns:
- The COLLADA scene, or null if there is no scene.
-
getAsset
public ColladaAsset getAsset()
Indicates the asset field of this document.- Returns:
- The asset field, or null if the field has not been set.
-
getLocalExtent
public Box getLocalExtent(ColladaTraversalContext tc)
Description copied from class:ColladaAbstractObjectReturns this renderable's model coordinate extent.- Specified by:
getLocalExtentin interfaceColladaRenderable- Overrides:
getLocalExtentin classColladaAbstractObject- Parameters:
tc- The traversal context to use when determining the extent.- Returns:
- The model coordinate extent.
-
preRender
public void preRender(ColladaTraversalContext tc, DrawContext dc)
Pre-Render this element. Renders the scene contained in this document.- Specified by:
preRenderin interfaceColladaRenderable- Parameters:
tc- the current COLLADA traversal context.dc- the current draw context.
-
render
public void render(ColladaTraversalContext tc, DrawContext dc)
Render this element. Renders the scene contained in this document.- Specified by:
renderin interfaceColladaRenderable- Parameters:
tc- the current COLLADA traversal context.dc- the current draw context.
-
getMatrix
protected Matrix getMatrix()
Indicates the transform matrix applied to this document.- Returns:
- Transform matrix.
-
getScale
protected double getScale()
Indicates the scale factored applied to this document. The scale is specified by theasset/unitelement.- Returns:
- Scale applied to the document. Returns 1.0 if the document does not specify a scale.
-
computeScale
protected double computeScale()
Indicates the scale defined by the asset/unit element. This scale converts the document's units to meters.- Returns:
- Scale for this document, or 1.0 if no scale is defined.
-
reset
protected void reset()
Clear cached values. Values will be recomputed the next time this document is rendered.
-
getParserContext
protected XMLEventParserContext getParserContext()
Indicates the parser context used by this document.- Returns:
- The parser context used to parse the document.
-
getItemByID
public java.lang.Object getItemByID(java.lang.String id)
Finds a named element in the document.- Parameters:
id- the element's identifier. If null, null is returned.- Returns:
- the element requested, or null if there is no corresponding element in the document.
-
getSupportFilePath
public java.lang.String getSupportFilePath(java.lang.String link) throws java.io.IOExceptionDetermines the path of a supporting file (such an image). If a resource resolver has been specified, the resource resolver will be invoked to determine the file path. Otherwise, the path will be resolved relative to the COLLADA document's file path or URL.- Parameters:
link- Relative path to resolve.- Returns:
- Absolute path of the resource, or null if the resource cannot be resolved.
- Throws:
java.io.IOException- If an error occurs while attempting to resolve the resource.
-
-