Skip to content

Commit

Permalink
Update gltf-model update w/ meshopt load callback
Browse files Browse the repository at this point in the history
This was an old upstream update that was missed ~2021
ref #621
  • Loading branch information
hi-liang committed Mar 1, 2024
1 parent 14905df commit 1c72b34
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/aframe-mods/gltf-model-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ AFRAME.components['gltf-model'].Component.prototype.update = function update() {
// register with model-progress system to handle model loading events
document.querySelector('a-scene').systems['model-progress'].registerModel(el, src);

this.loader.load(
src,
(gltfModel) => {
self.model = gltfModel.scene || gltfModel.scenes[0];
self.model.animations = gltfModel.animations;
self.model.asset = gltfModel.asset; // save asset
el.setObject3D('mesh', self.model);
el.emit('model-loaded', { format: 'gltf', model: self.model });
},
(xhr) => {
el.emit('model-progress', { src, loaded: xhr.loaded, total: xhr.total });
},
(error) => {
const message = error && error.message ? error.message : 'Failed to load glTF model';
console.error(message);
el.emit('model-error', { format: 'gltf', src });
}
);
this.ready.then(() => {
self.loader.load(
src,
(gltfModel) => {
self.model = gltfModel.scene || gltfModel.scenes[0];
self.model.animations = gltfModel.animations;
self.model.asset = gltfModel.asset; // save asset
el.setObject3D('mesh', self.model);
el.emit('model-loaded', { format: 'gltf', model: self.model });
},
(xhr) => {
el.emit('model-progress', { src, loaded: xhr.loaded, total: xhr.total });
},
(error) => {
const message = error && error.message ? error.message : 'Failed to load glTF model';
console.error(message);
el.emit('model-error', { format: 'gltf', src });
}
);
});
};

0 comments on commit 1c72b34

Please sign in to comment.