LittleJS 1.31.0

GLTF

GLTFObject

GLTFObject - A model as an object with a child per part, which plays the model's animations

  • model.createObject makes one; move, turn and scale it like any EngineObject3D and the parts follow
  • play starts an animation by name or number, and the object moves its parts each frame as it runs
  • The parts' meshes stay where they rest, an animation moves the child objects that draw them
  • Its color multiplies every part's own and transparent makes them all blend, so a hit flash or a fade, by the color's alpha, is set on the object; the other draw settings it sets away from the default, emissive or shader, take the parts' place
  • A see through object casts a shadow only where it is textured, so with transparent set its untextured parts cast none, whatever the alpha; set it only while it fades

Extends EngineObject3D

Constructor

new GLTFObject(model, pos3D)gltf.js:293

Make the object and its parts, model.createObject is the usual way

model GLTFModel
pos3D Vector3 optional
const door = model.createObject(vec3(0, 0, 5));
door.play('open', false); // once, holding the last pose

Members

Methods

Inherited from EngineObject3D

Inherited from EngineObject

Members

animation : GLTFAnimation|undefinedgltf.js:309

The animation playing, or the last one, undefined for none

animationLoop : booleangltf.js:315

Start again at the end, or stop there and hold the last pose

animationPlaying : booleangltf.js:317

Whether it is moving through the animation now

animationSpeed : numbergltf.js:313

How fast it plays, 1 is as made, negative plays it backward

animationTime : numbergltf.js:311

Seconds into the animation

blendFrom : {animation?: GLTFAnimation, time?: number, speed?: number, loop?: boolean, * nodes?: Map<number, GLTFNodeTRS>}|undefinedgltf.js:322

The model it shows

The child that draws each of the model's parts, in the order of model.parts, which an animation poses; one destroyed or taken off the object is left alone

poseNodes : Map<number, GLTFNodeTRS>|undefinedgltf.js:328
poseWorldOf : (function(number): Matrix4)|undefinedgltf.js:331

Methods

destroy(immediate)gltf.js:364

Destroy the object and its parts, and free the meshes its skinned parts bend, which are its own

immediate boolean optional
getJointMatrix(name) → Matrix4|undefinedgltf.js:489

A node's matrix in the world as the model is posed now, by its name in the file, to hang something on a joint, a sword on a hand or a hat on a head; undefined when the model has no node of that name

name string
play(animation, loop, speed, blend)gltf.js:386

Play an animation from its start, at once or cross-faded from the pose it is in

  • A play with a blend of the animation already playing goes on with it, so state code may call it each update, and so does one of an animation that played to its end and stopped while it was called each update, a death held on its last pose; without a blend it starts the animation again
  • Each update means from update code, every update: one called from render, or missed for an update, starts it again with the fade
  • Called each update with a loop or speed that moves the held pose, played backward from its end or set to loop, it goes on from there, a door closing; the same way again holds it, so an attack held down plays once, and plays again on a play without a blend or after an update with no play. After stop() it starts again
animation string|number|GLTFAnimation optional, default 0

Its name, its number in model.animations, or itself

loop boolean optional, default true

Start again at the end, or stop there

speed number optional, default 1

1 is as made, negative plays it backward from its end

blend number optional, default 0

Seconds to cross-fade from the pose it is in, 0 to switch at once; the animation it comes from goes on through the fade, and a fade started during another fades from the mix there

setAnimationTime(time)gltf.js:425

Put the parts where the animation has them at a time, playing or not

time number

Seconds into the animation

Stop the animation where it is, the parts hold that pose; a cross-fade going on stops too, holding the mix

update()gltf.js:462

Move through the animation, and a cross-fade into it, called automatically each frame