Skip to content

Instantly share code, notes, and snippets.

@loorlab
Created June 9, 2023 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loorlab/2a3fec388734253fdb49899c9ed4d964 to your computer and use it in GitHub Desktop.
Save loorlab/2a3fec388734253fdb49899c9ed4d964 to your computer and use it in GitHub Desktop.
Load Multiple GLTF - Three.js
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