I want to use several instances of a model, defined in a glb file, in a game.
Rather than get the glb file over the network multiple times, I want to just get it once and then clone it. But I can’t see how to do that cloning.
Here is what I’m trying so far:
const CHARACTER_PATH = "/models/character.glb";
let myGltf, myClone;
//Promisified version of GLTFLoader.load()
function loadGLTF(url) {
return new Promise((resolve, reject) => {
new GLTFLoader().load(
url,
(gltf) => resolve(gltf),
undefined, //loading progress unused
(error) => reject(error)
);
});
}
loadGLTF(CHARACTER_PATH)
.then((gltf) => {
myGltf = gltf; //ok
// myClone = structuredClone(myGltf); //DomException
})
.catch((error) => {
console.log(error);
});
I can’t just use a clone of gltf.scene because the animations are in gltf.animations.
Any help appreciated.