I've been experimenting with different methods to accomplish this task: I'm looking to load a model and then have the function return it.
var loader = new THREE.GLTFLoader();
loader.crossOrigin = true;
var loadedModel = loader.load('model.gltf', function (data) {
var object = data.scene;
return object;
}
Next, I want to call another function and pass loadedModel
:
loadToScene(loadedModel);
Additionally, I would like it to load to the scene multiple times if needed. Let's hardcode it for twice in this example:
function loadToScene(model){
model.position.set(0,0,0);
scene.add(model);
model.position.set(0,0,5);
scene.add(model);
}
I struggled to find a way to retain the data.scene
once the scope of loader
ends.
Is there a solution to achieve this?