Skip to content

Commit

Permalink
add tile load and unload events
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemckinstry committed Jan 10, 2025
1 parent 0717fcf commit 3b394ce
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,7 @@ function updateTiles(tileset, frameState, passOptions) {
statistics.incrementSelectionCounts(tile.content);
++statistics.selected;
}
//debugger;
const emptyTiles = tileset._emptyTiles;
for (let i = 0; i < emptyTiles.length; ++i) {
const tile = emptyTiles[i];
Expand Down Expand Up @@ -3287,6 +3288,7 @@ function update(tileset, frameState, passStatistics, passOptions) {

const statistics = tileset._statistics;
statistics.clear();
//debugger;

// Resets the visibility check for each pass
++tileset._updatedVisibilityFrame;
Expand Down
43 changes: 43 additions & 0 deletions packages/engine/Source/Scene/VoxelPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,49 @@ function VoxelPrimitive(options) {
}
}

/**
* The event fired to indicate that a tile's content was loaded.
* <p>
* The loaded tile is passed to the event listener.
* </p>
* <p>
* This event is fired during the tileset traversal while the frame is being rendered
* so that updates to the tile take effect in the same frame. Do not create or modify
* Cesium entities or primitives during the event listener.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* voxelPrimitive.tileLoad.addEventListener(function(tile) {
* console.log('A tile was loaded.');
* });
*/
this.tileLoad = new Event();

/**
* The event fired to indicate that a tile's content was unloaded.
* <p>
* The unloaded {@link Cesium3DTile} is passed to the event listener.
* </p>
* <p>
* This event is fired immediately before the tile's content is unloaded while the frame is being
* rendered so that the event listener has access to the tile's content. Do not create
* or modify Cesium entities or primitives during the event listener.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* primitive.tileUnload.addEventListener(function(tile) {
* console.log('A tile was unloaded from the cache.');
* });
*
*/
this.tileUnload = new Event();

// If the provider fails to initialize the primitive will fail too.
const provider = this._provider;
initialize(this, provider);
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/Source/Scene/VoxelTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ function requestData(that, keyframeNode) {
function postRequestSuccess(result) {
that._simultaneousRequestCount--;
const length = provider.types.length;
that._primitive.tileLoad.raiseEvent();

if (!defined(result)) {
keyframeNode.state = KeyframeNode.LoadState.UNAVAILABLE;
Expand Down Expand Up @@ -645,6 +646,7 @@ function loadAndUnload(that, frameState) {
destroyedCount++;

const discardNode = keyframeNodesInMegatexture[addNodeIndex];
that._primitive.tileUnload.raiseEvent();
discardNode.spatialNode.destroyKeyframeNode(
discardNode,
that.megatextures,
Expand Down

0 comments on commit 3b394ce

Please sign in to comment.