Created
June 9, 2023 21:49
-
-
Save loorlab/2a3fec388734253fdb49899c9ed4d964 to your computer and use it in GitHub Desktop.
Load Multiple GLTF - Three.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gltfLoader = new GLTFLoader() | |
// Array de archivos GLTF | |
const gltfFiles = [ | |
'models/Model/glTF/model1.gltf', | |
'models/Model/glTF/model2.gltf' | |
//'models/Model/glTF/other_model.gltf' | |
]; | |
// Función para cargar cada archivo GLTF | |
function loadGLTF(file) { | |
return new Promise((resolve, reject) => { | |
gltfLoader.load( | |
file, | |
(gltf) => { | |
gltf.scene.scale.set(0.5, 0.5, 0.5); | |
scene.add(gltf.scene); | |
resolve(); | |
}, | |
undefined, | |
reject | |
); | |
}); | |
} | |
// Función para cargar múltiples archivos GLTF secuencialmente | |
function loadMultipleGLTFs() { | |
const promises = gltfFiles.map((file) => loadGLTF(file)); | |
return Promise.all(promises); | |
} | |
// Llamar a la función para cargar los archivos GLTF | |
loadMultipleGLTFs() | |
.then(() => { | |
console.log('Archivos GLTF cargados exitosamente'); | |
}) | |
.catch((error) => { | |
console.error('Error al cargar los archivos GLTF:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment