From 6a26e201d6ef7b8966efa862bdd448c052f2053d Mon Sep 17 00:00:00 2001 From: johnshaughnessy <johnfshaughnessy@gmail.com> Date: Fri, 3 Aug 2018 10:19:18 -0700 Subject: [PATCH] Support zipped gltf file uploads. --- src/components/gltf-model-plus.js | 2 +- src/components/media-loader.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index b5904f0fc..8b1d02b7d 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -200,7 +200,7 @@ function cachedLoadGLTF(src, basePath, contentType, preferredTechnique, onProgre try { let gltfUrl = src; let onLoad = resolve; - if (contentType === "model/gltf+zip") { + if (contentType === "model/gltf+zip" || contentType === "application/x-zip-compressed") { const fileMap = await getFilesFromSketchfabZip(src); gltfUrl = fileMap["scene.gtlf"]; onLoad = model => { diff --git a/src/components/media-loader.js b/src/components/media-loader.js index 1ae37f321..b97074439 100644 --- a/src/components/media-loader.js +++ b/src/components/media-loader.js @@ -84,7 +84,12 @@ AFRAME.registerComponent("media-loader", { } this.el.setAttribute("image-plus", { src: blobUrl || raw, contentType }); this.el.setAttribute("position-at-box-shape-border", { target: ".delete-button", dirs: ["forward", "back"] }); - } else if (contentType.startsWith("model/gltf") || url.endsWith(".gltf") || url.endsWith(".glb")) { + } else if ( + contentType.indexOf("x-zip-compressed") !== -1 || + contentType.startsWith("model/gltf") || + url.endsWith(".gltf") || + url.endsWith(".glb") + ) { this.el.addEventListener( "model-loaded", () => { @@ -94,8 +99,17 @@ AFRAME.registerComponent("media-loader", { { once: true } ); this.el.addEventListener("model-error", this.onError, { once: true }); + let blobUrl; + if (token) { + const modelResponse = await fetch(raw, { + method: "GET", + headers: { Authorization: `Token ${token}` } + }); + const blob = await modelResponse.blob(); + blobUrl = window.URL.createObjectURL(blob); + } this.el.setAttribute("gltf-model-plus", { - src: raw, + src: blobUrl || raw, contentType, basePath: THREE.LoaderUtils.extractUrlBase(origin), inflate: true -- GitLab