Skip to content

Commit

Permalink
add tile failed event
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemckinstry committed Jan 14, 2025
1 parent ceaf56c commit bfe4c11
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
26 changes: 26 additions & 0 deletions packages/engine/Source/Scene/VoxelPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,32 @@ function VoxelPrimitive(options) {
*/
this.tileLoad = new Event();

/**
* The event fired to indicate that a tile's content failed to load.
* <p>
* If there are no event listeners, error messages will be logged to the console.
* </p>
* <p>
* The error object passed to the listener contains two properties:
* <ul>
* <li><code>url</code>: the url of the failed tile.</li>
* <li><code>message</code>: the error message.</li>
* </ul>
* <p>
* If multiple contents are present, this event is raised once per inner content with errors.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.tileFailed.addEventListener(function(error) {
* console.log(`An error occurred loading tile: ${error.url}`);
* console.log(`Error: ${error.message}`);
* });
*/
this.tileFailed = new Event();

/**
* The event fired to indicate that a tile's content was unloaded.
* <p>
Expand Down
42 changes: 32 additions & 10 deletions packages/engine/Source/Scene/VoxelTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,18 @@ function requestData(that, keyframeNode) {
}

const provider = that._primitive._provider;
const { keyframe, spatialNode } = keyframeNode;
if (spatialNode.level >= provider._implicitTileset.availableLevels) {
return;
}

const requestOptions = {
tileLevel: spatialNode.level,
tileX: spatialNode.x,
tileY: spatialNode.y,
tileZ: spatialNode.z,
keyframe: keyframe,
};

function postRequestSuccess(result) {
that._simultaneousRequestCount--;
Expand Down Expand Up @@ -458,24 +470,34 @@ function requestData(that, keyframeNode) {
}
}

function postRequestFailure() {
function postRequestFailure(options) {
const { requestOptions, error } = options;
const message = defined(error.message) ? error.message : error.toString();
const url = `${requestOptions.tileLevel}/${requestOptions.tileX}/${requestOptions.tileY}/${requestOptions.tileZ}`;
that._simultaneousRequestCount--;
if (that._primitive.tileFailed.numberOfListeners > 0) {
that._primitive.tileFailed.raiseEvent({
url: url,
message: message,
});
} else {
console.log(`A 3D tile failed to load: ${url}`);
console.log(`Error: ${message}`);
if (defined(error.stack)) {
console.log(error.stack);
}
}
keyframeNode.state = KeyframeNode.LoadState.FAILED;
}

const { keyframe, spatialNode } = keyframeNode;
const promise = provider.requestData({
tileLevel: spatialNode.level,
tileX: spatialNode.x,
tileY: spatialNode.y,
tileZ: spatialNode.z,
keyframe: keyframe,
});
const promise = provider.requestData(requestOptions);

if (defined(promise)) {
that._simultaneousRequestCount++;
keyframeNode.state = KeyframeNode.LoadState.RECEIVING;
promise.then(postRequestSuccess).catch(postRequestFailure);
promise
.then(postRequestSuccess)
.catch((error) => postRequestFailure({ requestOptions, error }));
} else {
keyframeNode.state = KeyframeNode.LoadState.FAILED;
}
Expand Down

0 comments on commit bfe4c11

Please sign in to comment.