Makes a placed model move: plays the movements its file came with, and eases between them.
A rigged model is a skin stretched over bones. A movement turns the bones, and the skin follows,
which is why one model can walk, run and fall over without three copies of it existing.
It moves the model createModel gave back, and only that one. Every model placed from a file
has bones of its own, so five enemies of one file can walk, jump and stand still each on their
own, each with an animator of its own.
It can be asked for a movement before the file has arrived, which is the ordinary case: the
model comes back still loading, so play is remembered and honoured the moment it shows up.
fade is what makes it look like a character rather than a demo. Asked to change movement over
half a second, it turns the bones from where one has them to where the other does; cutting
straight across snaps a leg from behind to in front in a single frame.
only plays a movement on part of the body, the rest carrying on with what it was doing: a
second animator on the same model, its bones named, shows over the first. The last one made goes
on top. With nothing playing it leaves those bones to the one below, and a movement that ends
hands them back, eased by its fade.
Ejemplo
export const Level: TSceneFn = () => {
useCamera3d({ projection: 'perspective', transform: { z: 200 } });
useDirectionalLight({ intensity: 1 });
const file = useLoadModel({ src: '/models/fox.glb' });
const fox = createModel({ model: file });
const moves = useSkeletalAnimation(fox, { play: 'Walk', fade: 0.25 });
const keys = useKeyboard();
useUpdate(() => {
if (keys.justPressed('Space')) moves.play('Run');
});
return createScene();
};
Ejemplo
export const Level: TSceneFn = () => {
useCamera3d({ projection: 'perspective', transform: { z: 20 } });
useDirectionalLight({ intensity: 1 });
const hero = createModel({ model: useLoadModel({ src: '/models/hero.glb' }) });
useSkeletalAnimation(hero, { play: 'run' });
const top = useSkeletalAnimation(hero, { only: ['spine'], fade: 0.2, clips: { greet: { loop: false } } });
const keys = useKeyboard();
useUpdate(() => {
if (keys.justPressed('Space')) top.play('greet');
});
return createScene();
};