I have loaded a model with GLTFLoader and I can use it normally with three.js inside the Loader method. However, I can't seem to access it from outside of it and I'm not sure why.
class Model {
constructor(link) {
this.link = link;
this.gltfLoader = new GLTFLoader();
}
load() {
this.gltfLoader.load(
this.link,
(gltf) => {
scene.add(gltf.scene);
}
);
}
}
const girl = new Model("/imported/girl/scene.gltf");
girl.load();
How can I access the gltf parameter from outside the loader?
I've tried setting a global value but It's not working because it's an async method and the value is always undefined. For example, I've setted a variable right before the class (let globalGLTF;), then, within the loader.load method, I assigned a global value (globalGLTF = gltf.scene;). When I call this variable from outside the method, it always returns undefined because the loader is async. I also think this isn't the best way of accessing it because I'm using a class to load the models. I'm trying to find a way where I can simply call something like girl.model and access the GLTF file. Is this possible?