Reputation: 43
After importing gltf object it doesn't assign it to outside variable. Model appears in browser but I can't access it.
let model;
gltfLoader.load('./assets/javaLogo.gltf', function(gltf){
model = gltf.scene;
model.scale.set(44,44,44);
scene.add(model);
model.position.x = 44;
model.position.y = -12;
});
console.log(model);// undefined
Upvotes: 0
Views: 170
Reputation: 123
The console.log gets executed immediately after you start to load the model at that time it has not finished loading. You can test this by having a console.log inside the callback function. (It will be executed after the one which logs undefined)
If you wanna access the model right after loading, you can do that inside the callback function. If you want to access it for example in an event listener you can still do that, but you have to make sure model isn't undefined anymore before that.
Upvotes: 1