Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for binary glTFs storing CRN and KTX textures #5753

Merged
merged 3 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -1574,7 +1579,7 @@ define([
id : id,
image : undefined,
bufferView : bufferViewId,
mimeType : gltfImage.mimeType
mimeType : mimeType
});
} else {
++model._loadResources.pendingTextureLoads;
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions Source/ThirdParty/GltfPipeline/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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];
}
}
}
}
});
}

Expand Down
30 changes: 24 additions & 6 deletions Specs/Scene/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand All @@ -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);
});
});
Expand All @@ -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);
});
});
Expand All @@ -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);
});
});
Expand Down