diff --git a/src/components/gltf-bundle.js b/src/components/gltf-bundle.js index 85238043fb2319dd1a6e55bc953186890fd2e721..3a3ce057c4f75d31d3724fe36ca6a0679651e869 100644 --- a/src/components/gltf-bundle.js +++ b/src/components/gltf-bundle.js @@ -5,6 +5,10 @@ AFRAME.registerComponent("gltf-bundle", { init: async function() { this._addGltfEntitiesForBundleJson = this._addGltfEntitiesForBundleJson.bind(this); + this.baseURL = new URL(this.data.src, window.location.href); + const pathParts = this.baseURL.pathname.split("/"); + pathParts.pop(); + this.baseURL.pathname = pathParts.join("/") + "/"; const res = await fetch(this.data.src); const data = await res.json(); @@ -16,10 +20,13 @@ AFRAME.registerComponent("gltf-bundle", { for (let i = 0; i < bundleJson.assets.length; i++) { const asset = bundleJson.assets[i]; - const src = asset.src; + + // TODO: for now just skip resources, eventually we will want to hold on to a reference so that we can use them + if (asset.type === "resource") continue; + + const src = new URL(asset.src, this.baseURL).href; const gltfEl = document.createElement("a-entity"); gltfEl.setAttribute("gltf-model-plus", { src }); - gltfEl.setAttribute("position", "0 0 0"); loaded.push(new Promise(resolve => gltfEl.addEventListener("model-loaded", resolve))); this.el.appendChild(gltfEl); }