From 15a38ffcd841652a6d3165dc6281de2c22f86d0c Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Wed, 18 Jul 2018 16:12:55 -0700 Subject: [PATCH] Fix issue where loader could overwrite mesh after it had been set --- src/components/gltf-model-plus.js | 5 +++-- src/components/media-loader.js | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index a9cef5ae4..bc8d90bc2 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -266,10 +266,10 @@ AFRAME.registerComponent("gltf-model-plus", { this.model = model.scene || model.scenes[0]; this.model.animations = model.animations; - this.el.setObject3D("mesh", this.model); + let object3DToSet = this.model; if (this.data.inflate && (this.inflatedEl = inflateEntities(this.model, this.templates, gltfPath))) { this.el.appendChild(this.inflatedEl); - this.el.setObject3D("mesh", this.inflatedEl.object3D); + object3DToSet = this.inflatedEl.object3D; // TODO: Still don't fully understand the lifecycle here and how it differs between browsers, we should dig in more // Wait one tick for the appended custom elements to be connected before attaching templates await nextTick(); @@ -278,6 +278,7 @@ AFRAME.registerComponent("gltf-model-plus", { attachTemplate(this.el, name, this.templates[name]); } } + this.el.setObject3D("mesh", object3DToSet); this.el.emit("model-loaded", { format: "gltf", model: this.model }); } catch (e) { console.error("Failed to load glTF model", e, this); diff --git a/src/components/media-loader.js b/src/components/media-loader.js index b2d5a7f2d..49090837f 100644 --- a/src/components/media-loader.js +++ b/src/components/media-loader.js @@ -63,6 +63,14 @@ AFRAME.registerComponent("media-loader", { const contentType = (meta && meta.expected_content_type) || (await fetchContentType(raw)); if (contentType.startsWith("image/") || contentType.startsWith("video/")) { + this.el.addEventListener( + "image-loaded", + () => { + console.log("clearing timeout"); + clearTimeout(this.showLoaderTimeout); + }, + { once: true } + ); this.el.setAttribute("image-plus", { src: raw, contentType }); } else if (contentType.startsWith("model/gltf") || url.endsWith(".gltf") || url.endsWith(".glb")) { this.el.addEventListener( -- GitLab