From e3357232428ceb0db2db9f7c7a86b070ab0e6681 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 14 Aug 2017 22:27:07 -0400 Subject: [PATCH 1/3] Fix loading for binary crn and ktx --- Source/Scene/Model.js | 12 +++++-- .../ThirdParty/GltfPipeline/updateVersion.js | 32 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 11ff60dc3e65..5fb81de4deea 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -1532,6 +1532,7 @@ define([ var extras = gltfImage.extras; var bufferViewId = gltfImage.bufferView; + var mimeType = gltfImage.mimeType; uri = gltfImage.uri; // First check for a compressed texture @@ -1542,24 +1543,28 @@ define([ var etc1 = extras.compressedImage3DTiles.etc1; if (context.s3tc && defined(crunch)) { + mimeType = crunch.mimeType; if (defined(crunch.bufferView)) { bufferViewId = crunch.bufferView; } else { uri = crunch.uri; } } else if (context.s3tc && defined(s3tc)) { + mimeType = s3tc.mimeType; if (defined(s3tc.bufferView)) { bufferViewId = s3tc.bufferView; } else { uri = s3tc.uri; } } else if (context.pvrtc && defined(pvrtc)) { + mimeType = pvrtc.mimeType; if (defined(pvrtc.bufferView)) { bufferViewId = pvrtc.bufferView; } else { uri = pvrtc.uri; } } else if (context.etc1 && defined(etc1)) { + mimeType = etc1.mimeType; if (defined(etc1.bufferView)) { bufferViewId = etc1.bufferView; } else { @@ -1574,7 +1579,7 @@ define([ id : id, image : undefined, bufferView : bufferViewId, - mimeType : gltfImage.mimeType + mimeType : mimeType }); } else { ++model._loadResources.pendingTextureLoads; @@ -2193,14 +2198,15 @@ define([ var gltf = model.gltf; var bufferView = gltf.bufferViews[gltfTexture.bufferView]; + var imageId = gltf.textures[gltfTexture.id].source; var onerror = getFailedLoadFunction(model, 'image', 'id: ' + gltfTexture.id + ', bufferView: ' + gltfTexture.bufferView); if (gltfTexture.mimeType === 'image/ktx') { - loadKTX(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id)).otherwise(onerror); + loadKTX(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id, imageId)).otherwise(onerror); ++model._loadResources.pendingTextureLoads; } else if (gltfTexture.mimeType === 'image/crn') { - loadCRN(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id)).otherwise(onerror); + loadCRN(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id, imageId)).otherwise(onerror); ++model._loadResources.pendingTextureLoads; } else { var onload = getOnImageCreatedFromTypedArray(loadResources, gltfTexture); diff --git a/Source/ThirdParty/GltfPipeline/updateVersion.js b/Source/ThirdParty/GltfPipeline/updateVersion.js index d832de0ebbb4..d6d42ea1535b 100644 --- a/Source/ThirdParty/GltfPipeline/updateVersion.js +++ b/Source/ThirdParty/GltfPipeline/updateVersion.js @@ -507,6 +507,26 @@ define([ delete image.extensions; } } + if (defined(image.extras)) { + var compressedImages = image.extras.compressedImage3DTiles; + for (var type in compressedImages) { + if (compressedImages.hasOwnProperty(type)) { + var compressedImage = compressedImages[type]; + var compressedExtensions = compressedImage.extensions; + if (defined(compressedExtensions)) { + var compressedBinaryGltf = compressedExtensions.KHR_binary_glTF; + if (defined(compressedBinaryGltf)) { + compressedImage.bufferView = globalMapping.bufferViews[compressedBinaryGltf.bufferView]; + compressedImage.mimeType = compressedBinaryGltf.mimeType; + delete compressedExtensions.KHR_binary_glTF; + } + if (Object.keys(extensions).length === 0) { + delete compressedImage.extensions; + } + } + } + } + } }); ForEach.texture(gltf, function(texture) { if (defined(texture.sampler)) { @@ -769,6 +789,18 @@ define([ if (defined(imageBufferView)) { image.bufferView = bufferViewShiftMap[imageBufferView]; } + if (defined(image.extras)) { + var compressedImages = image.extras.compressedImage3DTiles; + for (var type in compressedImages) { + if (compressedImages.hasOwnProperty(type)) { + var compressedImage = compressedImages[type]; + var compressedImageBufferView = compressedImage.bufferView; + if (defined(compressedImageBufferView)) { + compressedImage.bufferView = bufferViewShiftMap[compressedImageBufferView]; + } + } + } + } }); } From 158eae4338fec3cdc767cf77d2499365b560e66a Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 14 Aug 2017 22:29:16 -0400 Subject: [PATCH 2/3] Updated CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index ce03d1c674e1..6ba8450ba119 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Change Log * Fixed some issues with `disableDepthTestDistance` [#5501](https://github.com/AnalyticalGraphicsInc/cesium/issues/5501) [#5331](https://github.com/AnalyticalGraphicsInc/cesium/issues/5331) [#5621](https://github.com/AnalyticalGraphicsInc/cesium/issues/5621) * Added several new Bing Maps styles: `CANVAS_DARK`, `CANVAS_LIGHT`, and `CANVAS_GRAY`. * Added `Cesium3DTileset.loadJson` to support overriding the default tileset loading behavior. [#5685](https://github.com/AnalyticalGraphicsInc/cesium/pull/5685) +* Fixed loading of binary glTFs containing CRN or KTX textures. [#5753](https://github.com/AnalyticalGraphicsInc/cesium/pull/5753) ### 1.36 - 2017-08-01 From 2dd77a981cb28275a5aa45d51544139ab40bedd7 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sun, 20 Aug 2017 14:30:23 -0400 Subject: [PATCH 3/3] Make compressed texture tests slightly better --- Specs/Scene/ModelSpec.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index 2921b8bbc639..366752e5853a 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -888,22 +888,31 @@ defineSuite([ }); it('renders textured box with external KTX texture', function() { - return loadModel(texturedBoxKTXUrl).then(function(m) { + return loadModel(texturedBoxKTXUrl, { + incrementallyLoadTextures : false + }).then(function(m) { verifyRender(m); + expect(Object.keys(m._rendererResources.textures).length).toBe(1); primitives.remove(m); }); }); it('renders textured box with embedded binary KTX texture', function() { - return loadModel(texturedBoxKTXBinaryUrl).then(function(m) { + return loadModel(texturedBoxKTXBinaryUrl, { + incrementallyLoadTextures : false + }).then(function(m) { verifyRender(m); + expect(Object.keys(m._rendererResources.textures).length).toBe(1); primitives.remove(m); }); }); it('renders textured box with embedded base64 encoded KTX texture', function() { - return loadModel(texturedBoxKTXEmbeddedUrl).then(function(m) { + return loadModel(texturedBoxKTXEmbeddedUrl, { + incrementallyLoadTextures : false + }).then(function(m) { verifyRender(m); + expect(Object.keys(m._rendererResources.textures).length).toBe(1); primitives.remove(m); }); }); @@ -912,8 +921,11 @@ defineSuite([ if (!scene.context.s3tc) { return; } - return loadModel(texturedBoxCRNUrl).then(function(m) { + return loadModel(texturedBoxCRNUrl, { + incrementallyLoadTextures : false + }).then(function(m) { verifyRender(m); + expect(Object.keys(m._rendererResources.textures).length).toBe(1); primitives.remove(m); }); }); @@ -922,8 +934,11 @@ defineSuite([ if (!scene.context.s3tc) { return; } - return loadModel(texturedBoxCRNBinaryUrl).then(function(m) { + return loadModel(texturedBoxCRNBinaryUrl, { + incrementallyLoadTextures : false + }).then(function(m) { verifyRender(m); + expect(Object.keys(m._rendererResources.textures).length).toBe(1); primitives.remove(m); }); }); @@ -932,8 +947,11 @@ defineSuite([ if (!scene.context.s3tc) { return; } - return loadModel(texturedBoxCRNEmbeddedUrl).then(function(m) { + return loadModel(texturedBoxCRNEmbeddedUrl, { + incrementallyLoadTextures : false + }).then(function(m) { verifyRender(m); + expect(Object.keys(m._rendererResources.textures).length).toBe(1); primitives.remove(m); }); });