Class ColladaRoot

    • 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.
      • position

        protected Position position
        This shape's geographic location. The altitude is relative to this shapes altitude mode.
      • 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.
      • 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 new ColladaRoot for a ColladaDoc instance. 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.IOException
        Create a new ColladaRoot for a File.
        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.IOException
        Create a new ColladaRoot for a URL.
        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.IOException
        Create a new ColladaRoot for a InputStream.
        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 a File or a String identifying either a file path or a URL. Null is returned if the source type is not recognized.
        Parameters:
        docSource - either a File or a String identifying a file path or URL.
        Returns:
        a new ColladaRoot for 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 a File or a String identifying either a file path or a URL. Null is returned if the source type is not recognized.
        Parameters:
        docSource - either a File or a String identifying a file path or URL.
        Returns:
        a new ColladaRoot for 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.IOException
        Called just before the constructor returns. If overriding this method be sure to invoke super.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)
      • 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:
        isHighlighted in interface Highlightable
        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:
        setHighlighted in interface Highlightable
        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, where linkBase identifies a document, including the current document, and linkRef is the id of the desired element.

        If linkBase refers to a local COLLADA file and linkRef is non-null, the return value is the element identified by linkRef. If linkRef is null, the return value is a parsed ColladaRoot for the COLLADA file identified by linkBase. Otherwise, linkBase is 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, where linkBase identifies a remote document, and linkRef is the id of the desired element. This method retrieves resources asynchronously using the FileStore.

        The return value is null if the file is not yet available in the FileStore. If linkBase refers to a COLLADA file and linkRef is non-null, the return value is the element identified by linkRef. If linkBase refers to a COLLADA file and linkRef is null, the return value is a parsed ColladaRoot for the COLLADA file identified by linkBase. Otherwise the return value is a URL to 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 the linkBase is 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:
        true if mimeType can 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 ColladaRoot representing 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 by WWXML.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 during initialize() to create the parser context. The parser context is created by the global XMLEventParserContextFactory.
        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:
        this if 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.
      • render

        public void render​(ColladaTraversalContext tc,
                           DrawContext dc)
        Render this element. Renders the scene contained in this document.
        Specified by:
        render in interface ColladaRenderable
        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 the asset/unit element.
        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.IOException
        Determines 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.