#How to make the 3d-Object accessible outside the OBJLoader - function?
3 messages · Page 1 of 1 (latest)
by not writing it like that, threejs is inherently async, you shouldn't try to confront it with callbacks. this pattern is even called "callback hell" 😬
javascript is equipped to handle async tasks with async/await and promises:
async function app() {
const objLoader = new OBJLoader()
const textureLoader = new TextureLoader()
...
const [obj, texture] = await Promise.all([
new Promise((res, rej) => objLoader.load("model.obj", res, undefined, rej),
new Promise((res, rej) => textureLoader.load("image.png", res, undefined, rej),
...
])
// you can acces obj & texture here