Capítulo 817 de 859
Three.js is a rendering library, not a game engine — building a game on top of it means adding your own systems for loading/animating multiple models, organizing game logic (e.g. an Entity Component System), and sequencing time-based behavior (e.g. coroutines).
LoadingManager: coordinates loading multiple models via shared onProgress/onLoad callbacks so the game can wait for everything before starting and show a progress bar.SkeletonUtils.clone: clones an animated/skinned glTF scene properly so multiple independent instances of the same character can be created and animated separately.AnimationMixer + AnimationAction per instance: each cloned model gets its own mixer so its animations play independently of other clones of the same asset.GameObject is a thin wrapper around an Object3D plus a list of components; GameObject.update() just calls update() on each component.function* waitSeconds(duration) {
while (duration > 0) {
duration -= globals.deltaTime;
yield;
}
}
class CoroutineRunner {
constructor() {
this.generatorStacks = [];
this.addQueue = [];
this.removeQueue = new Set();
}
add(generator, delay = 0) {
const genStack = [generator];
if (delay) genStack.push(waitSeconds(delay));
this.addQueue.push(genStack);
}
// update() advances each generator stack once per frame
}
LoadingManager to coordinate loading multiple models and drive a progress bar before gameplay starts.SkeletonUtils.clone, not a plain object clone, so each instance can animate independently.GameObject composed of components) is a common way to keep growing game logic organized.