GLTF. GLTFModel

GLTFModel - A loaded model: its parts, and everything as one mesh

Constructor

new GLTFModel(parts)

Parameters:
NameTypeDescription
partsArray.<GLTFPart>

@param {Array} [animations] @param {Object} [nodeTree]

Members

animations :Array.<GLTFAnimation>

Type:
  • Array.<GLTFAnimation>
Properties
TypeDescription
Array.<GLTFAnimation>

The animations, play one through createObject's GLTFObject

bounds :Object|undefined

Type:
  • Object | undefined

mesh

Properties
TypeDescription
Mesh

Every part combined, each tinted with its material color; the texture is textureInfo, and blending and unlit stay with the parts, which createObject draws

parts

Properties
TypeDescription
Array.<GLTFPart>

One per primitive of every node that has a mesh

textureInfo :TextureInfo|undefined

Type:
  • TextureInfo | undefined
Properties
TypeDescription
TextureInfo | undefined

The texture to draw mesh with, when every part uses the same one

Methods

center() → {GLTFModel}

Move every part so the center of the model's bounds is on the origin, like Mesh.center

Returns:
Type: 
GLTFModel

createObject(pos3Dopt) → {GLTFObject}

Make an object at a position with a child per part, so each keeps its own texture, color and blending, and the model's animations can play on it; the way to show a model with windows or other see through parts, which the combined mesh draws solid, or one that moves

Parameters:
NameTypeAttributesDescription
pos3DVector3<optional>
Returns:
  • The root, move and turn it and the parts follow
Type: 
GLTFObject

dispose()

Free the GPU buffers of every part's mesh and of the combined mesh, and the textures, for a model that is done with, like a level's models when the next level loads

  • Destroy the objects createObject made from it first; a mesh drawn again only uploads again, but a freed texture is gone

fit(sizeopt) → {GLTFModel}

Scale every part evenly so the model's largest extent is a size, like Mesh.fit, for models of unknown units

Parameters:
NameTypeAttributesDefaultDescription
sizenumber<optional>
1
Returns:
Type: 
GLTFModel

getAnimation(animation) → {GLTFAnimation|undefined}

Find an animation by name or number

Parameters:
NameTypeDescription
animationstring | number | GLTFAnimation
Returns:
Type: 
GLTFAnimation | undefined

getBounds() → {Object}

The box around every part, measured once and again after transform, so change the model through that

Returns:
Type: 
Object

getPose(animation, time) → {Array.<Matrix4>}

How far each part has moved from its resting place at a time in an animation, one matrix per part

  • createObject's GLTFObject calls this as it plays, a game only needs it to pose something by hand
Parameters:
NameTypeDescription
animationGLTFAnimation
timenumber

Seconds into it

Returns:
Type: 
Array.<Matrix4>

transform(matrix) → {GLTFModel}

Move, turn or scale every part and the combined mesh together

Parameters:
NameTypeDescription
matrixMatrix4 | Vector3

Transform, or just an offset to move by

Returns:
Type: 
GLTFModel