Package com.badlogic.gdx.graphics.g3d
Class Model
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.Model
-
- All Implemented Interfaces:
Disposable
public class Model extends java.lang.Object implements Disposable
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 aMeshPartandMaterial. 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 aModelInstancefrom 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 fromModelData, which in turn is loaded by aModelLoader.
-
-
Field Summary
Fields Modifier and Type Field Description Array<Animation>animationsanimations of the model, modifying node transformationsprotected Array<Disposable>disposablesArray of disposable resources like textures or meshes the Model is responsible for disposingArray<Material>materialsthe 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 nodesArray<Mesh>meshesthe meshes of the modelArray<MeshPart>meshPartsparts 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 meshesArray<Node>nodesroot nodes of the model
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BoundingBoxcalculateBoundingBox(BoundingBox out)Calculate the bounding box of this model instance.voidcalculateTransforms()Calculates the local and world transform of allNodeinstances in this model, recursively.protected MaterialconvertMaterial(ModelMaterial mtl, TextureProvider textureProvider)protected voidconvertMesh(ModelMesh modelMesh)voiddispose()Releases all resources of this object.BoundingBoxextendBoundingBox(BoundingBox out)Extends the bounding box with the bounds of this model instance.AnimationgetAnimation(java.lang.String id)AnimationgetAnimation(java.lang.String id, boolean ignoreCase)java.lang.Iterable<Disposable>getManagedDisposables()MaterialgetMaterial(java.lang.String id)MaterialgetMaterial(java.lang.String id, boolean ignoreCase)NodegetNode(java.lang.String id)NodegetNode(java.lang.String id, boolean recursive)NodegetNode(java.lang.String id, boolean recursive, boolean ignoreCase)protected voidload(ModelData modelData, TextureProvider textureProvider)protected voidloadAnimations(java.lang.Iterable<ModelAnimation> modelAnimations)protected voidloadMaterials(java.lang.Iterable<ModelMaterial> modelMaterials, TextureProvider textureProvider)protected voidloadMeshes(java.lang.Iterable<ModelMesh> meshes)protected NodeloadNode(ModelNode modelNode)protected voidloadNodes(java.lang.Iterable<ModelNode> modelNodes)voidmanageDisposable(Disposable disposable)Adds aDisposableto be managed and disposed by this Model.
-
-
-
Field Detail
-
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
-
meshParts
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
-
disposables
protected final Array<Disposable> disposables
Array of disposable resources like textures or meshes the Model is responsible for disposing
-
-
Constructor Detail
-
Model
public Model()
Constructs an empty model. Manual created models do not manage their resources by default. UsemanageDisposable(Disposable)to add resources to be managed by this model.
-
Model
public Model(ModelData modelData)
Constructs a new Model based on theModelData. Texture files will be loaded from the internal file storage via anTextureProvider.FileTextureProvider.- Parameters:
modelData- theModelDatagot from e.g.ModelLoader
-
Model
public Model(ModelData modelData, TextureProvider textureProvider)
Constructs a new Model based on theModelData.- Parameters:
modelData- theModelDatagot from e.g.ModelLoadertextureProvider- theTextureProviderto use for loading the textures
-
-
Method Detail
-
load
protected void load(ModelData modelData, TextureProvider textureProvider)
-
loadAnimations
protected void loadAnimations(java.lang.Iterable<ModelAnimation> modelAnimations)
-
loadNodes
protected void loadNodes(java.lang.Iterable<ModelNode> modelNodes)
-
loadMeshes
protected void loadMeshes(java.lang.Iterable<ModelMesh> meshes)
-
convertMesh
protected void convertMesh(ModelMesh modelMesh)
-
loadMaterials
protected void loadMaterials(java.lang.Iterable<ModelMaterial> modelMaterials, TextureProvider textureProvider)
-
convertMaterial
protected Material convertMaterial(ModelMaterial mtl, TextureProvider textureProvider)
-
manageDisposable
public void manageDisposable(Disposable disposable)
Adds aDisposableto be managed and disposed by this Model. Can be used to keep track of manually loaded textures forModelInstance.- Parameters:
disposable- the Disposable
-
getManagedDisposables
public java.lang.Iterable<Disposable> getManagedDisposables()
- Returns:
- the
Disposableobjects that will be disposed when thedispose()method is called.
-
dispose
public void dispose()
Description copied from interface:DisposableReleases all resources of this object.- Specified by:
disposein interfaceDisposable
-
calculateTransforms
public void calculateTransforms()
Calculates the local and world transform of allNodeinstances in this model, recursively. First eachNode.localTransformtransform 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- theBoundingBoxthat 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- theBoundingBoxthat 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
Animationwith 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
Animationwith 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
Materialwith 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
Materialwith 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
Nodewith 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
Nodewith 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
Nodewith the specified id, or null if not found.
-
-