From 9d1dbad64512bcf079a361758de5a292ec595416 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 13 Jul 2017 19:45:44 -0400 Subject: [PATCH 1/3] Tile load event --- CHANGES.md | 1 + Source/Scene/Cesium3DTileset.js | 21 ++++++++++++++++++++- Specs/Scene/Cesium3DTilesetSpec.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 9e29bfe3909a..1f60aa75f9ab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log * Added ability to show tile urls in the 3D Tiles Inspector. [#5592](https://github.com/AnalyticalGraphicsInc/cesium/pull/5592) * Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139) +* Added `tileLoad` event to `Cesium3DTileset`. ### 1.35.2 - 2017-07-11 diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 1f649a04fd32..08393476bcca 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -366,6 +366,22 @@ define([ */ this.allTilesLoaded = new Event(); + /** + * The event fired to indicate that a tile's content was loaded. + *

+ * The loaded {@link Cesium3DTile} is passed to the event listener. + *

+ * + * @type {Event} + * @default new Event() + * + * @example + * tileset.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. *

@@ -1223,7 +1239,10 @@ define([ var removeFunction = removeFromProcessingQueue(tileset, tile); tile.contentReadyToProcessPromise.then(addToProcessingQueue(tileset, tile)); - tile.contentReadyPromise.then(removeFunction).otherwise(removeFunction); + tile.contentReadyPromise.then(function() { + removeFunction(); + tileset.tileLoad.raiseEvent(tile); + }).otherwise(removeFunction); } function requestTiles(tileset, outOfCore) { diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index 1f21d699218c..ada5da0669a7 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -1607,6 +1607,34 @@ defineSuite([ }); }); + it('tile load event is raised', function() { + viewNothing(); + return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { + var spyUpdate = jasmine.createSpy('listener'); + tileset.tileLoad.addEventListener(spyUpdate); + tileset.maximumMemoryUsage = 0; + viewRootOnly(); + return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { + // Root is loaded + expect(spyUpdate.calls.count()).toEqual(1); + expect(spyUpdate.calls.argsFor(0)[0]).toBe(tileset._root); + spyUpdate.calls.reset(); + + // Unload from cache + viewNothing(); + scene.renderForSpecs(); + expect(tileset.statistics.numberOfTilesWithContentReady).toEqual(0); + + // Look at root again + viewRootOnly(); + return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { + expect(spyUpdate.calls.count()).toEqual(1); + expect(spyUpdate.calls.argsFor(0)[0]).toBe(tileset._root); + }); + }); + }); + }); + it('destroys', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { var root = tileset._root; From 92c6b672bc333fa2f075a21297aa9e1ac53bd84d Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 13 Jul 2017 19:48:27 -0400 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 59bfa62f0c0f..cbab0751fdaf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Change Log * Added ability to show tile urls in the 3D Tiles Inspector. [#5592](https://github.com/AnalyticalGraphicsInc/cesium/pull/5592) * Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139) -* Added `tileLoad` event to `Cesium3DTileset`. +* Added `tileLoad` event to `Cesium3DTileset`. [#5628](https://github.com/AnalyticalGraphicsInc/cesium/pull/5628) * Added ability to provide a `width` and `height` to `scene.pick`. [#5602](https://github.com/AnalyticalGraphicsInc/cesium/pull/5602) ### 1.35.2 - 2017-07-11 From c65788f701e5e06e8be700059a3ae1af7c7e510d Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 14 Jul 2017 09:51:43 -0400 Subject: [PATCH 3/3] Add back warning note --- Source/Scene/Cesium3DTileset.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 08393476bcca..bfbd478217a6 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -371,6 +371,11 @@ define([ *

* The loaded {@link Cesium3DTile} is passed to the event listener. *

+ *

+ * 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. + *

* * @type {Event} * @default new Event()