From 85221b2465ebe529715848de92ce1adf655be250 Mon Sep 17 00:00:00 2001 From: Robert Long <robert@robertlong.me> Date: Mon, 6 Aug 2018 15:52:21 -0700 Subject: [PATCH] DRY up resolving GLTF uris --- src/components/gltf-model-plus.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index 7128e506a..c12a0cad6 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -209,6 +209,10 @@ async function loadEnvMap() { return texture; } +function resolveGLTFUri(gltfProperty, basePath) { + return resolveMedia(new URL(gltfProperty.uri, basePath).href).then(({ raw }) => (gltfProperty.uri = raw)); +} + async function loadGLTF(src, preferredTechnique, onProgress) { const { raw, origin, contentType } = await resolveMedia(src); const basePath = THREE.LoaderUtils.extractUrlBase(origin); @@ -236,21 +240,13 @@ async function loadGLTF(src, preferredTechnique, onProgress) { if (images) { for (const image of images) { - const imagePromise = resolveMedia(new URL(image.uri, parser.options.path).href).then(({ raw }) => { - image.uri = raw; - }); - - pendingFarsparkPromises.push(imagePromise); + pendingFarsparkPromises.push(resolveGLTFUri(image, parser.options.path)); } } if (buffers) { for (const buffer of buffers) { - const bufferPromise = resolveMedia(new URL(buffer.uri, parser.options.path).href).then(({ raw }) => { - buffer.uri = raw; - }); - - pendingFarsparkPromises.push(bufferPromise); + pendingFarsparkPromises.push(resolveGLTFUri(buffer, parser.options.path)); } } -- GitLab