[Bug Report] Model.js, updateVersion.js (about compressed texture loading)

**Hi **
**I found some issues about compressed texture. **

One of my b3dm(gltf1.0 layout) have crn textures.

It is not displayed at 1.36.

Problems are related 2 source files :

issue 1. Source/ThirdParty/GltfPipeline/updateVersion.js

issue 2. Source/Scene/Model.js

issue 1: about gltf1.0 to gltf2.0

After 1.36, model.js convert gltf 1.x => 2.0 at runtime.

But some case, it can’t convert perfect(it is not big issue because anyway we have to go gltf 2.0 somday).

and is it not converted well. so I tried fix it and it works for me: (“For compressedImage3DTiles (ex. CRN, KTX, …) blocks” added)

function objectsToArrays(gltf) { at Source/ThirdParty/GltfPipeline/updateVersion.js

ForEach.image(gltf, function(image) {

    var extensions = image.extensions;

    if (defined(extensions)) {

        var binaryGltf = extensions.KHR_binary_glTF;

        if (defined(binaryGltf)) {

            image.bufferView = globalMapping.bufferViews[binaryGltf.bufferView];

            image.mimeType = binaryGltf.mimeType;

            delete extensions.KHR_binary_glTF;

        }

        if (Object.keys(extensions).length === 0) {

            delete image.extensions;

        }

    }

    **//////////////////////////////////////////////////////////////////////////////////////////**

//For compressedImage3DTiles (ex. CRN, KTX, …)

var extras = image.extras;

if(defined(extras)){

var compressedImage3DTiles = extras.compressedImage3DTiles;

for(var compressName in compressedImage3DTiles){

if(compressedImage3DTiles.hasOwnProperty(compressName)){

var compress = compressedImage3DTiles[compressName];

var binaryGltfForCompress = compress.extensions.KHR_binary_glTF;

if(defined(compress.extensions) && defined(binaryGltfForCompress)){

compress.bufferView = globalMapping.bufferViews[binaryGltfForCompress.bufferView];

compress.mimeType = binaryGltfForCompress.mimeType;

if(!defined(image.bufferView)){

image.bufferView = compress.bufferView;

}

if(!defined(image.mimeType)){ //just use first mimeType

image.mimeType = compress.mimeType;

}

delete compress.extensions.KHR_binary_glTF;

}

if (Object.keys(compress.extensions).length === 0) {

delete compress.extensions;

}

}

}

}

//////////////////////////////////////////////////////////////////////////////////////////

function moveByteStrideToBufferView(gltf) at Source/ThirdParty/GltfPipeline/updateVersion.js

ForEach.image(gltf, function(image) {

    var imageBufferView = image.bufferView;

    if (defined(imageBufferView)) {

        image.bufferView = bufferViewShiftMap[imageBufferView];

    }

    **//////////////////////////////////////////////////////////////////////////////////////////**

//For compressedImage3DTiles (ex. CRN, KTX, …)

if(defined(image.extras)){

var compressedImage3DTiles = image.extras.compressedImage3DTiles;

for(var compressName in compressedImage3DTiles){

if(compressedImage3DTiles.hasOwnProperty(compressName)){

var compress = compressedImage3DTiles[compressName];

var oldImageBufferView = compress.bufferView;

if (defined(compress.bufferView)) {

compress.bufferView = bufferViewShiftMap[oldImageBufferView];

}

}

}

}

//////////////////////////////////////////////////////////////////////////////////////////

});

``

issue 2:

it is simple mistake: **in ****Source/Scene/Model.js (**add imageId comments added)

function loadTexturesFromBufferViews(model) {

var loadResources = model._loadResources;

if (loadResources.pendingBufferLoads !== 0) {

return;

}

while (loadResources.texturesToCreateFromBufferView.length > 0) {

var gltfTexture = loadResources.texturesToCreateFromBufferView.dequeue();

var gltf = model.gltf;

var bufferView = gltf.bufferViews[gltfTexture.bufferView];

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);

//=> add imageId

loadKTX(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id, gltfTexture.bufferView)).otherwise(onerror);

++model._loadResources.pendingTextureLoads;

} else if (gltfTexture.mimeType === ‘image/crn’) {

//loadCRN(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id)).otherwise(onerror);

//=> add imageId

loadCRN(loadResources.getBuffer(bufferView)).then(imageLoad(model, gltfTexture.id, gltfTexture.bufferView)).otherwise(onerror);

++model._loadResources.pendingTextureLoads;

} else {

var onload = getOnImageCreatedFromTypedArray(loadResources, gltfTexture);

loadImageFromTypedArray(loadResources.getBuffer(bufferView), gltfTexture.mimeType)

.then(onload).otherwise(onerror);

++loadResources.pendingBufferViewToImage;

}

}

}

``

After two patches, I could see it normally.

I just want to it help someone.

thanks, Cesium team

shyoo

Thanks for the report once again - can you check out this PR? - https://github.com/AnalyticalGraphicsInc/cesium/pull/5753. The code is slightly modified from your posted version.

It works. It’s good enough for me.

Many thanks for quick fix.

shyoo.

Thanks again for the report, #5753 was merged into master and will be released in the September version of Cesium.

Patrick