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

Added workaround for broken tilesets. #6125

Merged
merged 1 commit into from
Jan 18, 2018
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
4 changes: 4 additions & 0 deletions Source/Core/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ define([
* @param {Boolean{ [proxy=false] If true, the url is processed the proxy object if defined.
*/
Resource.prototype.getUrlComponent = function(query, proxy) {
if(this.isDataUri) {
return this._url;
}

var uri = new Uri(this._url);

if (query) {
Expand Down
7 changes: 6 additions & 1 deletion Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ define([
baseResource = Resource.createIfNeeded(baseResource);

if (defined(contentHeader)) {
var contentHeaderUrl = contentHeader.url;
if (tileset._brokenUrlWorkaround && contentHeaderUrl.length > 0 && (contentHeaderUrl[0] === '/')) {
contentHeaderUrl = contentHeader.url = contentHeaderUrl.substring(1);
}

hasEmptyContent = false;
contentState = Cesium3DTileContentState.UNLOADED;
contentResource = baseResource.getDerivedResource({
url : contentHeader.url
url : contentHeaderUrl
});
serverKey = RequestScheduler.getServerKey(contentResource.getUrlComponent());
} else {
Expand Down
91 changes: 81 additions & 10 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ define([
'../Core/Event',
'../Core/getBaseUri',
'../Core/getExtensionFromUri',
'../Core/getMagic',
'../Core/isDataUri',
'../Core/JulianDate',
'../Core/loadArrayBuffer',
'../Core/loadJson',
'../Core/ManagedArray',
'../Core/Math',
Expand Down Expand Up @@ -55,8 +57,10 @@ define([
Event,
getBaseUri,
getExtensionFromUri,
getMagic,
isDataUri,
JulianDate,
loadArrayBuffer,
loadJson,
ManagedArray,
CesiumMath,
Expand Down Expand Up @@ -680,20 +684,87 @@ define([
*/
this.debugShowUrl = defaultValue(options.debugShowUrl, false);

// A bunch of tilesets were generated that have a leading / in front of all URLs in the tileset.json. If the tiles aren't
// at the root of the domain they will not load anymore. If we find a b3dm file with a leading slash, we test load a tile.
// If it succeeds we continue on. If it fails, we set this to true so we know to strip the slash when loading tiles.
this._brokenUrlWorkaround = false;

var that = this;

// We don't know the distance of the tileset until tileset.json is loaded, so use the default distance for now
Cesium3DTileset.loadJson(tilesetResource).then(function(tilesetJson) {
that._root = that.loadTileset(tilesetResource, tilesetJson);
var gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis) ? Axis.fromName(tilesetJson.asset.gltfUpAxis) : Axis.Y;
that._asset = tilesetJson.asset;
that._properties = tilesetJson.properties;
that._geometricError = tilesetJson.geometricError;
that._gltfUpAxis = gltfUpAxis;
that._readyPromise.resolve(that);
}).otherwise(function(error) {
that._readyPromise.reject(error);
Cesium3DTileset.loadJson(tilesetResource)
.then(function(tilesetJson) {
return detectBrokenUrlWorkaround(that, tilesetResource, tilesetJson);
})
.then(function(tilesetJson) {
if (that._brokenUrlWorkaround) {
deprecationWarning('Cesium3DTileset.leadingSlash', 'Having a leading slash in a tile URL that is actually relative to the tileset.json is deprecated.');
}

that._root = that.loadTileset(tilesetResource, tilesetJson);
var gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis) ? Axis.fromName(tilesetJson.asset.gltfUpAxis) : Axis.Y;
that._asset = tilesetJson.asset;
that._properties = tilesetJson.properties;
that._geometricError = tilesetJson.geometricError;
that._gltfUpAxis = gltfUpAxis;
that._readyPromise.resolve(that);
}).otherwise(function(error) {
that._readyPromise.reject(error);
});
}

function detectBrokenUrlWorkaround(tileset, tilesetResource, tilesetJson) {
var testUrl = findBrokenUrl(tilesetJson.root);

// If it's an empty string, we are good to load the tileset.
if (!defined(testUrl) || (testUrl.length === 0)) {
return tilesetJson;
}

var testResource = tilesetResource.getDerivedResource({
url : testUrl
});

return loadArrayBuffer(testResource)
.then(function(buffer) {
var uint8Array = new Uint8Array(buffer);
var magic = getMagic(uint8Array);

// If its not a b3dm file, then use workaround
// This accounts for servers that return an error page with a 200 status code
tileset._brokenUrlWorkaround = (magic !== 'b3dm');

return tilesetJson;
})
.otherwise(function() {
// Tile failed to load, so use the workaround
tileset._brokenUrlWorkaround = true;
return tilesetJson;
});
}

var brokenUrlRegex = /^\/.+\.b3dm$/;

function findBrokenUrl(node) {
var content = node.content;
if (defined(content) && defined(content.url)) {
if (brokenUrlRegex.test(content.url)) {
return content.url;
}

return '';
}

var children = node.children;
if (!defined(children)) {
var count = children.length;
for (var i = 0; i < count; ++i) {
var result = findBrokenUrl(children[i]);
if (defined(result)) {
return result;
}
}
}
}

defineProperties(Cesium3DTileset.prototype, {
Expand Down