Package com.badlogic.gdx.graphics.g3d
Class ModelInstance
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.ModelInstance
-
- All Implemented Interfaces:
RenderableProvider
public class ModelInstance extends java.lang.Object implements RenderableProvider
An instance of aModel
, 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 Model, all sharing the meshes and textures of the Model. The Model owns the meshes and textures, to dispose of these, the Model has to be disposed. Therefor, the Model must outlive all its ModelInstances The ModelInstance creates a full copy of all materials, nodes and animations.
-
-
Field Summary
Fields Modifier and Type Field Description Array<Animation>
animations
animations of the model, modifying node transformationsstatic boolean
defaultShareKeyframes
Whether, by default,NodeKeyframe
's are shared amongstModel
and ModelInstance.Array<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 nodesModel
model
theModel
this instances derives fromArray<Node>
nodes
root nodes of the modelMatrix4
transform
the world transformjava.lang.Object
userData
user definable value, which is passed to theShader
.
-
Constructor Summary
Constructors Constructor Description ModelInstance(Model model)
Constructs a new ModelInstance with all nodes and materials of the given model.ModelInstance(ModelInstance copyFrom)
Constructs a new ModelInstance which is an copy of the specified ModelInstance.ModelInstance(ModelInstance copyFrom, Matrix4 transform)
Constructs a new ModelInstance which is an copy of the specified ModelInstance.ModelInstance(ModelInstance copyFrom, Matrix4 transform, boolean shareKeyframes)
Constructs a new ModelInstance which is an copy of the specified ModelInstance.ModelInstance(Model model, float x, float y, float z)
Constructs a new ModelInstance at the specified position.ModelInstance(Model model, Matrix4 transform)
Constructs a new ModelInstance with the specified transform.ModelInstance(Model model, Matrix4 transform, Array<java.lang.String> rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.ModelInstance(Model model, Matrix4 transform, Array<java.lang.String> rootNodeIds, boolean shareKeyframes)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.ModelInstance(Model model, Matrix4 transform, java.lang.String... rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean mergeTransform)
ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean parentTransform, boolean mergeTransform)
Recursively searches the mode for the specified node.ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform)
ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes)
ModelInstance(Model model, Vector3 position)
Constructs a new ModelInstance at the specified position.ModelInstance(Model model, Array<java.lang.String> rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.ModelInstance(Model model, java.lang.String... rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.ModelInstance(Model model, java.lang.String nodeId, boolean mergeTransform)
ModelInstance(Model model, java.lang.String nodeId, boolean parentTransform, boolean mergeTransform)
Recursively searches the mode for the specified node.ModelInstance(Model model, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BoundingBox
calculateBoundingBox(BoundingBox out)
Calculate the bounding box of this model instance.void
calculateTransforms()
Calculates the local and world transform of allNode
instances in this model, recursively.ModelInstance
copy()
void
copyAnimation(Animation sourceAnim)
Copy the source animation to this ModelInstancevoid
copyAnimation(Animation sourceAnim, boolean shareKeyframes)
Copy the source animation to this ModelInstancevoid
copyAnimations(java.lang.Iterable<Animation> source)
Copy source animations to this ModelInstancevoid
copyAnimations(java.lang.Iterable<Animation> source, boolean shareKeyframes)
Copy source animations to this ModelInstanceBoundingBox
extendBoundingBox(BoundingBox out)
Extends the bounding box with the bounds of this model instance.Animation
getAnimation(java.lang.String id)
Animation
getAnimation(java.lang.String id, boolean ignoreCase)
Material
getMaterial(java.lang.String id)
Material
getMaterial(java.lang.String id, boolean ignoreCase)
Node
getNode(java.lang.String id)
Node
getNode(java.lang.String id, boolean recursive)
Node
getNode(java.lang.String id, boolean recursive, boolean ignoreCase)
Renderable
getRenderable(Renderable out)
Renderable
getRenderable(Renderable out, Node node)
Renderable
getRenderable(Renderable out, Node node, NodePart nodePart)
protected void
getRenderables(Node node, Array<Renderable> renderables, Pool<Renderable> pool)
void
getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)
Traverses the Node hierarchy and collectsRenderable
instances for every node with a graphical representation.
-
-
-
Field Detail
-
defaultShareKeyframes
public static boolean defaultShareKeyframes
Whether, by default,NodeKeyframe
's are shared amongstModel
and ModelInstance. Can be overridden per ModelInstance using the constructor argument.
-
materials
public final Array<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
-
animations
public final Array<Animation> animations
animations of the model, modifying node transformations
-
transform
public Matrix4 transform
the world transform
-
userData
public java.lang.Object userData
user definable value, which is passed to theShader
.
-
-
Constructor Detail
-
ModelInstance
public ModelInstance(Model model)
Constructs a new ModelInstance with all nodes and materials of the given model.- Parameters:
model
- TheModel
to create an instance of.
-
ModelInstance
public ModelInstance(Model model, java.lang.String nodeId, boolean mergeTransform)
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean mergeTransform)
- Parameters:
model
- The sourceModel
transform
- TheMatrix4
instance for this ModelInstance to reference or null to create a new matrix.nodeId
- The ID of the rootNode
of theModel
for the instance to containmergeTransform
- True to apply the source node transform to the instance transform, resetting the node transform.
-
ModelInstance
public ModelInstance(Model model, java.lang.String nodeId, boolean parentTransform, boolean mergeTransform)
Recursively searches the mode for the specified node.- Parameters:
model
- The sourceModel
nodeId
- The ID of theNode
within theModel
for the instance to containparentTransform
- 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.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean parentTransform, boolean mergeTransform)
Recursively searches the mode for the specified node.- Parameters:
model
- The sourceModel
transform
- TheMatrix4
instance for this ModelInstance to reference or null to create a new matrix.nodeId
- The ID of theNode
within theModel
for the instance to containparentTransform
- 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.
-
ModelInstance
public ModelInstance(Model model, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform)
- Parameters:
model
- The sourceModel
nodeId
- The ID of theNode
within theModel
for the instance to containrecursive
- True to recursively search the Model's node tree, false to only search for a root nodeparentTransform
- 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.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform)
- Parameters:
model
- The sourceModel
transform
- TheMatrix4
instance for this ModelInstance to reference or null to create a new matrix.nodeId
- The ID of theNode
within theModel
for the instance to containrecursive
- True to recursively search the Model's node tree, false to only search for a root nodeparentTransform
- 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.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, java.lang.String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes)
- Parameters:
model
- The sourceModel
transform
- TheMatrix4
instance for this ModelInstance to reference or null to create a new matrix.nodeId
- The ID of theNode
within theModel
for the instance to containrecursive
- True to recursively search the Model's node tree, false to only search for a root nodeparentTransform
- 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.
-
ModelInstance
public ModelInstance(Model model, java.lang.String... rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, java.lang.String... rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.
-
ModelInstance
public ModelInstance(Model model, Array<java.lang.String> rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, Array<java.lang.String> rootNodeIds)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform, Array<java.lang.String> rootNodeIds, boolean shareKeyframes)
Constructs a new ModelInstance with only the specified nodes and materials of the given model.
-
ModelInstance
public ModelInstance(Model model, Vector3 position)
Constructs a new ModelInstance at the specified position.
-
ModelInstance
public ModelInstance(Model model, float x, float y, float z)
Constructs a new ModelInstance at the specified position.
-
ModelInstance
public ModelInstance(Model model, Matrix4 transform)
Constructs a new ModelInstance with the specified transform.
-
ModelInstance
public ModelInstance(ModelInstance copyFrom)
Constructs a new ModelInstance which is an copy of the specified ModelInstance.
-
ModelInstance
public ModelInstance(ModelInstance copyFrom, Matrix4 transform)
Constructs a new ModelInstance which is an copy of the specified ModelInstance.
-
ModelInstance
public ModelInstance(ModelInstance copyFrom, Matrix4 transform, boolean shareKeyframes)
Constructs a new ModelInstance which is an copy of the specified ModelInstance.
-
-
Method Detail
-
copy
public ModelInstance copy()
- Returns:
- A newly created ModelInstance which is a copy of this ModelInstance
-
copyAnimations
public void copyAnimations(java.lang.Iterable<Animation> source)
Copy source animations to this ModelInstance- Parameters:
source
- Iterable collection of source animationsAnimation
-
copyAnimations
public void copyAnimations(java.lang.Iterable<Animation> source, boolean shareKeyframes)
Copy source animations to this ModelInstance- Parameters:
source
- Iterable collection of source animationsAnimation
shareKeyframes
- Shallow copy ofNodeKeyframe
's if it's true, otherwise make a deep copy.
-
copyAnimation
public void copyAnimation(Animation sourceAnim)
Copy the source animation to this ModelInstance- Parameters:
sourceAnim
- The source animationAnimation
-
copyAnimation
public void copyAnimation(Animation sourceAnim, boolean shareKeyframes)
Copy the source animation to this ModelInstance- Parameters:
sourceAnim
- The source animationAnimation
shareKeyframes
- Shallow copy ofNodeKeyframe
's if it's true, otherwise make a deep copy.
-
getRenderables
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)
Traverses the Node hierarchy and collectsRenderable
instances for every node with a graphical representation. Renderables are obtained from the provided pool. The resulting array can be rendered via aModelBatch
.- Specified by:
getRenderables
in interfaceRenderableProvider
- Parameters:
renderables
- the output arraypool
- the pool to obtain Renderables from
-
getRenderable
public Renderable getRenderable(Renderable out)
- Returns:
- The renderable of the first node's first part.
-
getRenderable
public Renderable getRenderable(Renderable out, Node node)
- Returns:
- The renderable of the node's first part.
-
getRenderable
public Renderable getRenderable(Renderable out, Node node, NodePart nodePart)
-
getRenderables
protected void getRenderables(Node node, Array<Renderable> renderables, Pool<Renderable> pool)
-
calculateTransforms
public void calculateTransforms()
Calculates the local and world transform of allNode
instances in this model, recursively. First eachNode.localTransform
transform is calculated based on the translation, rotation and scale of each Node. Then eachNode.calculateWorldTransform()
is calculated, based on the parent's world transform and the local transform of each Node. Finally, the animation bone matrices are updated accordingly. This method can be used to recalculate all transforms if any of the Node's local properties (translation, rotation, scale) was modified.
-
calculateBoundingBox
public BoundingBox calculateBoundingBox(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
- theBoundingBox
that will be set with the bounds.- Returns:
- the out parameter for chaining
-
extendBoundingBox
public BoundingBox extendBoundingBox(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
- theBoundingBox
that will be extended with the bounds.- Returns:
- the out parameter for chaining
-
getAnimation
public Animation getAnimation(java.lang.String id)
- Parameters:
id
- The ID of the animation to fetch (case sensitive).- Returns:
- The
Animation
with the specified id, or null if not available.
-
getAnimation
public Animation 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
Animation
with the specified id, or null if not available.
-
getMaterial
public 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 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 Node getNode(java.lang.String id)
- Parameters:
id
- The ID of the node to fetch.- Returns:
- The
Node
with the specified id, or null if not found.
-
getNode
public Node 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
Node
with the specified id, or null if not found.
-
getNode
public Node 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
Node
with the specified id, or null if not found.
-
-