From 09fceaa46b97ca0add9ba0f9e3e585df08d44af9 Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Thu, 5 Apr 2018 17:30:06 -0700 Subject: [PATCH] Support for relative asset urls in bundles --- src/components/gltf-bundle.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/gltf-bundle.js b/src/components/gltf-bundle.js index 85238043f..3a3ce057c 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); } -- GitLab