diff --git a/CHANGES.md b/CHANGES.md index a5d1d0eab7f2..34f80cc4f458 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Change Log * Added small improvements to the atmosphere. [#5741](https://github.com/AnalyticalGraphicsInc/cesium/pull/5741) * Fixed a bug that caused imagery splitting to work incorrectly when CSS pixels were not equivalent to WebGL drawing buffer pixels, such as on high DPI displays in Microsoft Edge and Internet Explorer. * 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 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]; + } + } + } + } }); } 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); }); });