-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Mesh, Scene } from 'three'; | ||
import { LoadingManager, Mesh, Scene } from 'three'; | ||
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; | ||
import { applyMaterials } from './materials'; | ||
|
||
|
@@ -8,23 +8,25 @@ export const loadModel = ( | |
onProgress?: (progress: number) => void, | ||
onLoad?: () => void | ||
): void => { | ||
const loader = new GLTFLoader(); | ||
loader.load( | ||
url, | ||
(gltf) => { | ||
gltf.scene.traverse((child) => { | ||
if (child instanceof Mesh) { | ||
applyMaterials(child); | ||
} | ||
}); | ||
scene.add(gltf.scene); | ||
onLoad?.(); | ||
}, | ||
(progress) => { | ||
onProgress?.((progress.loaded / progress.total) * 100); | ||
}, | ||
(error) => { | ||
console.error('An error happened', error); | ||
} | ||
); | ||
const manager = new LoadingManager(); | ||
Check failure on line 11 in src/three/loader.ts
|
||
manager.onProgress = (_url, itemsLoaded, itemsTotal) => { | ||
onProgress?.((itemsLoaded / itemsTotal) * 100); | ||
}; | ||
manager.onLoad = () => { | ||
onLoad?.(); | ||
}; | ||
manager.onError = (error) => { | ||
console.error('An error happened', error); | ||
}; | ||
|
||
const loader = new GLTFLoader(manager); | ||
loader.load(url, (gltf) => { | ||
gltf.scene.traverse((child) => { | ||
if (child instanceof Mesh) { | ||
applyMaterials(child); | ||
} | ||
}); | ||
scene.add(gltf.scene); | ||
onLoad?.(); | ||
}); | ||
}; |