APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.g3d

public Class Model

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Disposable
Imports
com.badlogic.gdx.assets.loaders.ModelLoader, com.badlogic.gdx.graphics.GL20, .Mesh, .Texture, .VertexAttributes, com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute, .ColorAttribute, .FloatAttribute, .TextureAttribute, com.badlogic.gdx.graphics.g3d.model.Animation, .MeshPart, .Node, .NodeAnimation, .NodeKeyframe, .NodePart, com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation, .ModelData, .ModelMaterial, .ModelMesh, .ModelMeshPart, .ModelNode, .ModelNodeAnimation, .ModelNodeKeyframe, .ModelNodePart, .ModelTexture, com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor, .TextureProvider, .TextureProvider.FileTextureProvider, com.badlogic.gdx.math.Matrix4, .Quaternion, .Vector3, com.badlogic.gdx.math.collision.BoundingBox, com.badlogic.gdx.utils.Array, .ArrayMap, .BufferUtils, .Disposable, .GdxRuntimeException, .ObjectMap, java.nio.Buffer, .ShortBuffer

A model represents a 3D assets. It stores a hierarchy of nodes. A node has a transform and optionally a graphical part in form of a MeshPart and Material. Mesh parts reference subsets of vertices in one of the meshes of the model. Animations can be applied to nodes, to modify their transform (translation, rotation, scale) over time.

A model can be rendered by creating a ModelInstance from it. That instance has an additional transform to position the model in the world, and allows modification of materials and nodes without destroying the original model. The original model is the owner of any meshes and textures, all instances created from the model share these resources. Disposing the model will automatically make all instances invalid!

A model is created from ModelData, which in turn is loaded by a ModelLoader.
Author
badlogic, xoppa

Field Summary

Modifier and TypeField and Description
public final Array<Animation>
animations

animations of the model, modifying node transformations

protected final Array<Disposable>
disposables

Array of disposable resources like textures or meshes the Model is responsible for disposing

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

public final Array<Mesh>
meshes

the meshes of the model

public final Array<MeshPart>
meshParts

parts of meshes, used by nodes that have a graphical representation FIXME not sure if superfluous, stored in Nodes as well, could be useful to create bullet meshes

private ObjectMap<NodePart, ArrayMap<String, Matrix4>>
public final Array<Node>
nodes

root nodes of the model

Constructor Summary

AccessConstructor and Description
public
Model()

Constructs an empty model.

public
Model(ModelData
the ModelData got from e.g. ModelLoader
modelData
)

Constructs a new Model based on the ModelData.

public
Model(ModelData
the ModelData got from e.g. ModelLoader
modelData
,
TextureProvider
the TextureProvider to use for loading the textures
textureProvider
)

Constructs a new Model based on the ModelData.

Method Summary

Modifier and TypeMethod and Description
public BoundingBox

Returns:

the out parameter for chaining
calculateBoundingBox
(final BoundingBox
the BoundingBox that will be set with the bounds.
out
)

Calculate the bounding box of this model instance.

public void
calculateTransforms()

Calculates the local and world transform of all Node instances in this model, recursively.

protected Material
protected void
public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

public BoundingBox

Returns:

the out parameter for chaining
extendBoundingBox
(final BoundingBox
the BoundingBox that will be extended with the bounds.
out
)

Extends the bounding box with the bounds of this model instance.

public Animation
getAnimation(final String
The ID of the animation to fetch (case sensitive).
id
)

Returns: The Animation with the specified id, or null if not available.

public Animation
getAnimation(final String
The ID of the animation to fetch.
id
,
boolean
whether to use case sensitivity when comparing the animation id.
ignoreCase
)

Returns: The Animation with the specified id, or null if not available.

public Iterable<Disposable>
getManagedDisposables()

Returns: the Disposable objects that will be disposed when the dispose() method is called.

public Material
getMaterial(final String
The ID of the material to fetch.
id
)

Returns: The Material with the specified id, or null if not available.

public Material
getMaterial(final String
The ID of the material to fetch.
id
,
boolean
whether to use case sensitivity when comparing the material id.
ignoreCase
)

Returns: The Material with the specified id, or null if not available.

public Node
getNode(final String
The ID of the node to fetch.
id
)

Returns: The Node with the specified id, or null if not found.

public Node
getNode(final String
The ID of the node to fetch.
id
,
boolean
false to fetch a root node only, true to search the entire node tree for the specified node.
recursive
)

Returns: The Node with the specified id, or null if not found.

public Node
getNode(final String
The ID of the node to fetch.
id
,
boolean
false to fetch a root node only, true to search the entire node tree for the specified node.
recursive
,
boolean
whether to use case sensitivity when comparing the node id.
ignoreCase
)

Returns: The Node with the specified id, or null if not found.

protected void
load(ModelData modelData, TextureProvider textureProvider)

protected void
protected void
loadMaterials(Iterable<ModelMaterial> modelMaterials, TextureProvider textureProvider)

protected void
protected Node
loadNode(ModelNode modelNode)

protected void
public void
manageDisposable(Disposable
the Disposable
disposable
)

Adds a Disposable to be managed and disposed by this Model.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

animationsback to summary
public final Array<Animation> animations

animations of the model, modifying node transformations

disposablesback to summary
protected final Array<Disposable> disposables

Array of disposable resources like textures or meshes the Model is responsible for disposing

materialsback to summary
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

meshesback to summary
public final Array<Mesh> meshes

the meshes of the model

meshPartsback to summary
public final Array<MeshPart> meshParts

parts of meshes, used by nodes that have a graphical representation FIXME not sure if superfluous, stored in Nodes as well, could be useful to create bullet meshes

nodePartBonesback to summary
private ObjectMap<NodePart, ArrayMap<String, Matrix4>> nodePartBones
nodesback to summary
public final Array<Node> nodes

root nodes of the model

Constructor Detail

Modelback to summary
public Model()

Constructs an empty model. Manual created models do not manage their resources by default. Use manageDisposable(Disposable) to add resources to be managed by this model.

Modelback to summary
public Model(ModelData modelData)

Constructs a new Model based on the ModelData. Texture files will be loaded from the internal file storage via an FileTextureProvider.

Parameters
modelData:ModelData

the ModelData got from e.g. ModelLoader

Modelback to summary
public Model(ModelData modelData, TextureProvider textureProvider)

Constructs a new Model based on the ModelData.

Parameters
modelData:ModelData

the ModelData got from e.g. ModelLoader

textureProvider:TextureProvider

the TextureProvider to use for loading the textures

Method Detail

calculateBoundingBoxback to summary
public BoundingBox calculateBoundingBox(final 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:BoundingBox

the BoundingBox that will be set with the bounds.

Returns:BoundingBox

the out parameter for chaining

calculateTransformsback to summary
public void calculateTransforms()

Calculates the local and world transform of all Node instances in this model, recursively. First each Node#localTransform transform is calculated based on the translation, rotation and scale of each Node. Then each Node#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.
convertMaterialback to summary
protected Material convertMaterial(ModelMaterial mtl, TextureProvider textureProvider)
convertMeshback to summary
protected void convertMesh(ModelMesh modelMesh)
disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Doc from com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

Annotations
@Override
extendBoundingBoxback to summary
public BoundingBox extendBoundingBox(final 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:BoundingBox

the BoundingBox that will be extended with the bounds.

Returns:BoundingBox

the out parameter for chaining

getAnimationback to summary
public Animation getAnimation(final String id)
Parameters
id:String

The ID of the animation to fetch (case sensitive).

Returns:Animation

The Animation with the specified id, or null if not available.

getAnimationback to summary
public Animation getAnimation(final String id, boolean ignoreCase)
Parameters
id:String

The ID of the animation to fetch.

ignoreCase:boolean

whether to use case sensitivity when comparing the animation id.

Returns:Animation

The Animation with the specified id, or null if not available.

getManagedDisposablesback to summary
public Iterable<Disposable> getManagedDisposables()
Returns:Iterable<Disposable>

the Disposable objects that will be disposed when the dispose() method is called.

getMaterialback to summary
public Material getMaterial(final String id)
Parameters
id:String

The ID of the material to fetch.

Returns:Material

The Material with the specified id, or null if not available.

getMaterialback to summary
public Material getMaterial(final String id, boolean ignoreCase)
Parameters
id:String

The ID of the material to fetch.

ignoreCase:boolean

whether to use case sensitivity when comparing the material id.

Returns:Material

The Material with the specified id, or null if not available.

getNodeback to summary
public Node getNode(final String id)
Parameters
id:String

The ID of the node to fetch.

Returns:Node

The Node with the specified id, or null if not found.

getNodeback to summary
public Node getNode(final String id, boolean recursive)
Parameters
id:String

The ID of the node to fetch.

recursive:boolean

false to fetch a root node only, true to search the entire node tree for the specified node.

Returns:Node

The Node with the specified id, or null if not found.

getNodeback to summary
public Node getNode(final String id, boolean recursive, boolean ignoreCase)
Parameters
id:String

The ID of the node to fetch.

recursive:boolean

false to fetch a root node only, true to search the entire node tree for the specified node.

ignoreCase:boolean

whether to use case sensitivity when comparing the node id.

Returns:Node

The Node with the specified id, or null if not found.

loadback to summary
protected void load(ModelData modelData, TextureProvider textureProvider)
loadAnimationsback to summary
protected void loadAnimations(Iterable<ModelAnimation> modelAnimations)
loadMaterialsback to summary
protected void loadMaterials(Iterable<ModelMaterial> modelMaterials, TextureProvider textureProvider)
loadMeshesback to summary
protected void loadMeshes(Iterable<ModelMesh> meshes)
loadNodeback to summary
protected Node loadNode(ModelNode modelNode)
loadNodesback to summary
protected void loadNodes(Iterable<ModelNode> modelNodes)
manageDisposableback to summary
public void manageDisposable(Disposable disposable)

Adds a Disposable to be managed and disposed by this Model. Can be used to keep track of manually loaded textures for ModelInstance.

Parameters
disposable:Disposable

the Disposable