Class IntModelInstance

  • All Implemented Interfaces:
    IntRenderableProvider

    public class IntModelInstance
    extends java.lang.Object
    implements IntRenderableProvider
    An instance of a IntModel, allows to specify global transform and modify the materials, as it has a copy of the model's materials. Multiple instances can be created from the same IntModel, all sharing the meshes and textures of the IntModel. The IntModel owns the meshes and textures, to dispose of these, the IntModel has to be disposed. Therefor, the IntModel must outlive all its IntModelInstances

    The IntModelInstance creates a full copy of all materials, nodes and animations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      com.badlogic.gdx.utils.Array<IntAnimation> animations
      animations of the model, modifying node transformations
      static boolean defaultShareKeyframes
      Whether, by default, NodeKeyframe's are shared amongst IntModel and IntModelInstance.
      com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g3d.Material> materials
      the materials of the model, used by nodes that have a graphical representation FIXME not sure if superfluous, allows modification of materials without having to traverse the nodes
      IntModel model
      the IntModel this instances derives from
      com.badlogic.gdx.utils.Array<IntNode> nodes
      root nodes of the model
      com.badlogic.gdx.math.Matrix4 transform
      the world transform
      java.lang.Object userData
      user definable value, which is passed to the IntShader.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntModelInstance​(IntModel model)
      Constructs a new IntModelInstance with all nodes and materials of the given model.
      IntModelInstance​(IntModelInstance copyFrom)
      Constructs a new IntModelInstance which is an copy of the specified IntModelInstance.
      IntModelInstance​(IntModelInstance copyFrom, com.badlogic.gdx.math.Matrix4 transform)
      Constructs a new IntModelInstance which is an copy of the specified IntModelInstance.
      IntModelInstance​(IntModelInstance copyFrom, com.badlogic.gdx.math.Matrix4 transform, boolean shareKeyframes)
      Constructs a new IntModelInstance which is an copy of the specified IntModelInstance.
      IntModelInstance​(IntModel model, float x, float y, float z)
      Constructs a new IntModelInstance at the specified position.
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform)
      Constructs a new IntModelInstance with the specified transform.
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, com.badlogic.gdx.utils.Array<java.lang.String> rootNodeIds)
      Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, com.badlogic.gdx.utils.Array<java.lang.String> rootNodeIds, boolean shareKeyframes)
      Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, java.lang.String... rootNodeIds)
      Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, java.lang.String nodeId, boolean mergeTransform)  
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, java.lang.String nodeId, boolean parentTransform, boolean mergeTransform)
      Recursively searches the mode for the specified node.
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform)  
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Matrix4 transform, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes)  
      IntModelInstance​(IntModel model, com.badlogic.gdx.math.Vector3 position)
      Constructs a new IntModelInstance at the specified position.
      IntModelInstance​(IntModel model, com.badlogic.gdx.utils.Array<java.lang.String> rootNodeIds)
      Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      IntModelInstance​(IntModel model, java.lang.String... rootNodeIds)
      Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      IntModelInstance​(IntModel model, java.lang.String nodeId, boolean mergeTransform)  
      IntModelInstance​(IntModel model, java.lang.String nodeId, boolean parentTransform, boolean mergeTransform)
      Recursively searches the mode for the specified node.
      IntModelInstance​(IntModel model, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform)  
    • Field Detail

      • defaultShareKeyframes

        public static boolean defaultShareKeyframes
        Whether, by default, NodeKeyframe's are shared amongst IntModel and IntModelInstance. Can be overridden per IntModelInstance using the constructor argument.
      • materials

        public final com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g3d.Material> materials
        the materials of the model, used by nodes that have a graphical representation FIXME not sure if superfluous, allows modification of materials without having to traverse the nodes
      • nodes

        public final com.badlogic.gdx.utils.Array<IntNode> nodes
        root nodes of the model
      • animations

        public final com.badlogic.gdx.utils.Array<IntAnimation> animations
        animations of the model, modifying node transformations
      • transform

        public com.badlogic.gdx.math.Matrix4 transform
        the world transform
      • userData

        public java.lang.Object userData
        user definable value, which is passed to the IntShader.
    • Constructor Detail

      • IntModelInstance

        public IntModelInstance​(IntModel model)
        Constructs a new IntModelInstance with all nodes and materials of the given model.
        Parameters:
        model - The IntModel to create an instance of.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                java.lang.String nodeId,
                                boolean mergeTransform)
        Parameters:
        model - The source IntModel
        nodeId - The ID of the root IntNode of the IntModel for the instance to contain
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                java.lang.String nodeId,
                                boolean mergeTransform)
        Parameters:
        model - The source IntModel
        transform - The Matrix4 instance for this IntModelInstance to reference or null to create a new matrix.
        nodeId - The ID of the root IntNode of the IntModel for the instance to contain
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                java.lang.String nodeId,
                                boolean parentTransform,
                                boolean mergeTransform)
        Recursively searches the mode for the specified node.
        Parameters:
        model - The source IntModel
        nodeId - The ID of the IntNode within the IntModel for the instance to contain
        parentTransform - True to apply the parent's node transform to the instance (only applicable if recursive is true).
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                java.lang.String nodeId,
                                boolean parentTransform,
                                boolean mergeTransform)
        Recursively searches the mode for the specified node.
        Parameters:
        model - The source IntModel
        transform - The Matrix4 instance for this IntModelInstance to reference or null to create a new matrix.
        nodeId - The ID of the IntNode within the IntModel for the instance to contain
        parentTransform - True to apply the parent's node transform to the instance (only applicable if recursive is true).
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                java.lang.String nodeId,
                                boolean recursive,
                                boolean parentTransform,
                                boolean mergeTransform)
        Parameters:
        model - The source IntModel
        nodeId - The ID of the IntNode within the IntModel for the instance to contain
        recursive - True to recursively search the IntModel's node tree, false to only search for a root node
        parentTransform - True to apply the parent's node transform to the instance (only applicable if recursive is true).
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                java.lang.String nodeId,
                                boolean recursive,
                                boolean parentTransform,
                                boolean mergeTransform)
        Parameters:
        model - The source IntModel
        transform - The Matrix4 instance for this IntModelInstance to reference or null to create a new matrix.
        nodeId - The ID of the IntNode within the IntModel for the instance to contain
        recursive - True to recursively search the IntModel's node tree, false to only search for a root node
        parentTransform - True to apply the parent's node transform to the instance (only applicable if recursive is true).
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                java.lang.String nodeId,
                                boolean recursive,
                                boolean parentTransform,
                                boolean mergeTransform,
                                boolean shareKeyframes)
        Parameters:
        model - The source IntModel
        transform - The Matrix4 instance for this IntModelInstance to reference or null to create a new matrix.
        nodeId - The ID of the IntNode within the IntModel for the instance to contain
        recursive - True to recursively search the IntModel's node tree, false to only search for a root node
        parentTransform - True to apply the parent's node transform to the instance (only applicable if recursive is true).
        mergeTransform - True to apply the source node transform to the instance transform, resetting the node transform.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                java.lang.String... rootNodeIds)
        Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                java.lang.String... rootNodeIds)
        Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.utils.Array<java.lang.String> rootNodeIds)
        Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                com.badlogic.gdx.utils.Array<java.lang.String> rootNodeIds)
        Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform,
                                com.badlogic.gdx.utils.Array<java.lang.String> rootNodeIds,
                                boolean shareKeyframes)
        Constructs a new IntModelInstance with only the specified nodes and materials of the given model.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Vector3 position)
        Constructs a new IntModelInstance at the specified position.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                float x,
                                float y,
                                float z)
        Constructs a new IntModelInstance at the specified position.
      • IntModelInstance

        public IntModelInstance​(IntModel model,
                                com.badlogic.gdx.math.Matrix4 transform)
        Constructs a new IntModelInstance with the specified transform.
      • IntModelInstance

        public IntModelInstance​(IntModelInstance copyFrom)
        Constructs a new IntModelInstance which is an copy of the specified IntModelInstance.
      • IntModelInstance

        public IntModelInstance​(IntModelInstance copyFrom,
                                com.badlogic.gdx.math.Matrix4 transform)
        Constructs a new IntModelInstance which is an copy of the specified IntModelInstance.
      • IntModelInstance

        public IntModelInstance​(IntModelInstance copyFrom,
                                com.badlogic.gdx.math.Matrix4 transform,
                                boolean shareKeyframes)
        Constructs a new IntModelInstance which is an copy of the specified IntModelInstance.
    • Method Detail

      • copy

        public IntModelInstance copy()
        Returns:
        A newly created IntModelInstance which is a copy of this IntModelInstance
      • getRenderables

        public void getRenderables​(com.badlogic.gdx.utils.Array<IntRenderable> renderables,
                                   com.badlogic.gdx.utils.Pool<IntRenderable> pool)
        Traverses the IntNode hierarchy and collects IntRenderable instances for every node with a graphical representation. IntRenderables are obtained from the provided pool. The resulting array can be rendered via a IntModelBatch.
        Specified by:
        getRenderables in interface IntRenderableProvider
        Parameters:
        renderables - the output array
        pool - the pool to obtain IntRenderables from
      • getRenderable

        public IntRenderable getRenderable​(IntRenderable out)
        Returns:
        The renderable of the first node's first part.
      • getRenderables

        protected void getRenderables​(IntNode node,
                                      com.badlogic.gdx.utils.Array<IntRenderable> renderables,
                                      com.badlogic.gdx.utils.Pool<IntRenderable> pool)
      • calculateTransforms

        public void calculateTransforms()
        Calculates the local and world transform of all IntNode instances in this model, recursively. First each IntNode.localTransform transform is calculated based on the translation, rotation and scale of each IntNode. Then each IntNode.calculateWorldTransform() is calculated, based on the parent's world transform and the local transform of each IntNode. Finally, the animation bone matrices are updated accordingly.

        This method can be used to recalculate all transforms if any of the IntNode's local properties (translation, rotation, scale) was modified.
      • calculateBoundingBox

        public com.badlogic.gdx.math.collision.BoundingBox calculateBoundingBox​(com.badlogic.gdx.math.collision.BoundingBox out)
        Calculate the bounding box of this model instance. This is a potential slow operation, it is advised to cache the result.
        Parameters:
        out - the BoundingBox that will be set with the bounds.
        Returns:
        the out parameter for chaining
      • extendBoundingBox

        public com.badlogic.gdx.math.collision.BoundingBox extendBoundingBox​(com.badlogic.gdx.math.collision.BoundingBox out)
        Extends the bounding box with the bounds of this model instance. This is a potential slow operation, it is advised to cache the result.
        Parameters:
        out - the BoundingBox that will be extended with the bounds.
        Returns:
        the out parameter for chaining
      • getAnimation

        public IntAnimation getAnimation​(java.lang.String id)
        Parameters:
        id - The ID of the animation to fetch (case sensitive).
        Returns:
        The IntAnimation with the specified id, or null if not available.
      • getAnimation

        public IntAnimation getAnimation​(java.lang.String id,
                                         boolean ignoreCase)
        Parameters:
        id - The ID of the animation to fetch.
        ignoreCase - whether to use case sensitivity when comparing the animation id.
        Returns:
        The IntAnimation with the specified id, or null if not available.
      • getMaterial

        public com.badlogic.gdx.graphics.g3d.Material getMaterial​(java.lang.String id)
        Parameters:
        id - The ID of the material to fetch.
        Returns:
        The Material with the specified id, or null if not available.
      • getMaterial

        public com.badlogic.gdx.graphics.g3d.Material getMaterial​(java.lang.String id,
                                                                  boolean ignoreCase)
        Parameters:
        id - The ID of the material to fetch.
        ignoreCase - whether to use case sensitivity when comparing the material id.
        Returns:
        The Material with the specified id, or null if not available.
      • getNode

        public IntNode getNode​(java.lang.String id)
        Parameters:
        id - The ID of the node to fetch.
        Returns:
        The IntNode with the specified id, or null if not found.
      • getNode

        public IntNode getNode​(java.lang.String id,
                               boolean recursive)
        Parameters:
        id - The ID of the node to fetch.
        recursive - false to fetch a root node only, true to search the entire node tree for the specified node.
        Returns:
        The IntNode with the specified id, or null if not found.
      • getNode

        public IntNode getNode​(java.lang.String id,
                               boolean recursive,
                               boolean ignoreCase)
        Parameters:
        id - The ID of the node to fetch.
        recursive - false to fetch a root node only, true to search the entire node tree for the specified node.
        ignoreCase - whether to use case sensitivity when comparing the node id.
        Returns:
        The IntNode with the specified id, or null if not found.