From 067a13d8754b873afa50b479d387a46f5aaaadd0 Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Mon, 1 Aug 2016 17:06:13 -0400 Subject: [PATCH 1/4] Fixed typo when creating GroundPrimitives. --- .../gallery/CZML Polygon - Intervals, Availability.html | 6 ++++-- Source/DataSources/CorridorGeometryUpdater.js | 2 +- Source/DataSources/EllipseGeometryUpdater.js | 2 +- Source/DataSources/PolygonGeometryUpdater.js | 2 +- Source/DataSources/RectangleGeometryUpdater.js | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html b/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html index 6138d7d1afef..790631ca9ebb 100644 --- a/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html +++ b/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html @@ -138,8 +138,10 @@ } }]; -var viewer = new Cesium.Viewer('cesiumContainer'); -viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); +Cesium.GroundPrimitive.initializeTerrainHeights().then(function() { + var viewer = new Cesium.Viewer('cesiumContainer'); + viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); +}); //Sandcastle_End Sandcastle.finishedLoading(); diff --git a/Source/DataSources/CorridorGeometryUpdater.js b/Source/DataSources/CorridorGeometryUpdater.js index f1b071a14ba8..67c55bc99d22 100644 --- a/Source/DataSources/CorridorGeometryUpdater.js +++ b/Source/DataSources/CorridorGeometryUpdater.js @@ -592,7 +592,7 @@ define([ } this._primitive = groundPrimitives.add(new GroundPrimitive({ - geometryInstance : new GeometryInstance({ + geometryInstances : new GeometryInstance({ id : entity, geometry : new CorridorGeometry(options), attributes: { diff --git a/Source/DataSources/EllipseGeometryUpdater.js b/Source/DataSources/EllipseGeometryUpdater.js index 7f204a09a7a8..8f2b0eca90b6 100644 --- a/Source/DataSources/EllipseGeometryUpdater.js +++ b/Source/DataSources/EllipseGeometryUpdater.js @@ -609,7 +609,7 @@ define([ } this._primitive = groundPrimitives.add(new GroundPrimitive({ - geometryInstance : new GeometryInstance({ + geometryInstances : new GeometryInstance({ id : entity, geometry : new EllipseGeometry(options), attributes: { diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index 0d88fef25369..f3e284dfa533 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -630,7 +630,7 @@ define([ } this._primitive = groundPrimitives.add(new GroundPrimitive({ - geometryInstance : new GeometryInstance({ + geometryInstances : new GeometryInstance({ id : entity, geometry : new PolygonGeometry(options), attributes: { diff --git a/Source/DataSources/RectangleGeometryUpdater.js b/Source/DataSources/RectangleGeometryUpdater.js index 9a997f42c8c7..c55d5e7994a6 100644 --- a/Source/DataSources/RectangleGeometryUpdater.js +++ b/Source/DataSources/RectangleGeometryUpdater.js @@ -602,7 +602,7 @@ define([ } this._primitive = groundPrimitives.add(new GroundPrimitive({ - geometryInstance : new GeometryInstance({ + geometryInstances : new GeometryInstance({ id : entity, geometry : new RectangleGeometry(options), attributes: { From 934828e1d74e3383f9925c39fb9cf9c35822781e Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Tue, 2 Aug 2016 10:32:35 -0400 Subject: [PATCH 2/4] Changed datasources to initialize terrain heights, so the user doesn't have to. --- .../gallery/CZML Polygon - Intervals, Availability.html | 6 ++---- Source/DataSources/DataSourceDisplay.js | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html b/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html index 790631ca9ebb..6138d7d1afef 100644 --- a/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html +++ b/Apps/Sandcastle/gallery/CZML Polygon - Intervals, Availability.html @@ -138,10 +138,8 @@ } }]; -Cesium.GroundPrimitive.initializeTerrainHeights().then(function() { - var viewer = new Cesium.Viewer('cesiumContainer'); - viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); -}); +var viewer = new Cesium.Viewer('cesiumContainer'); +viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)); //Sandcastle_End Sandcastle.finishedLoading(); diff --git a/Source/DataSources/DataSourceDisplay.js b/Source/DataSources/DataSourceDisplay.js index c7f48feb1255..f28bb9dde0e4 100644 --- a/Source/DataSources/DataSourceDisplay.js +++ b/Source/DataSources/DataSourceDisplay.js @@ -7,6 +7,7 @@ define([ '../Core/destroyObject', '../Core/DeveloperError', '../Core/EventHelper', + '../Scene/GroundPrimitive', './BillboardVisualizer', './BoundingSphereState', './BoxGeometryUpdater', @@ -33,6 +34,7 @@ define([ destroyObject, DeveloperError, EventHelper, + GroundPrimitive, BillboardVisualizer, BoundingSphereState, BoxGeometryUpdater, @@ -77,6 +79,8 @@ define([ throw new DeveloperError('dataSourceCollection is required.'); } //>>includeEnd('debug'); + + GroundPrimitive.initializeTerrainHeights(); var scene = options.scene; var dataSourceCollection = options.dataSourceCollection; @@ -231,6 +235,10 @@ define([ } //>>includeEnd('debug'); + if (!GroundPrimitive._initialized) { + return false; + } + var result = true; var i; From efe5ae7f16a22a479384e1597c5c475d57d8eae4 Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Tue, 2 Aug 2016 10:54:15 -0400 Subject: [PATCH 3/4] Fixed DataSourceDisplay tests to already have terrain heights loaded. Added a test that makes sure update returns false till the terrain heights promise resolves. --- Specs/DataSources/DataSourceDisplaySpec.js | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Specs/DataSources/DataSourceDisplaySpec.js b/Specs/DataSources/DataSourceDisplaySpec.js index 2a8b59a21725..b98af6d33b73 100644 --- a/Specs/DataSources/DataSourceDisplaySpec.js +++ b/Specs/DataSources/DataSourceDisplaySpec.js @@ -7,6 +7,7 @@ defineSuite([ 'DataSources/BoundingSphereState', 'DataSources/DataSourceCollection', 'DataSources/Entity', + 'Scene/GroundPrimitive', 'Specs/createScene', 'Specs/MockDataSource' ], function( @@ -17,6 +18,7 @@ defineSuite([ BoundingSphereState, DataSourceCollection, Entity, + GroundPrimitive, createScene, MockDataSource) { 'use strict'; @@ -27,6 +29,8 @@ defineSuite([ beforeAll(function() { scene = createScene(); dataSourceCollection = new DataSourceCollection(); + + return GroundPrimitive.initializeTerrainHeights(); }); afterAll(function() { @@ -339,4 +343,27 @@ defineSuite([ return display.update(); }).toThrowDeveloperError(); }); + + it('verify update returns false till terrain heights are initialized', function() { + GroundPrimitive._initialized = false; + GroundPrimitive._initPromise = undefined; + + var source1 = new MockDataSource(); + var source2 = new MockDataSource(); + + display = new DataSourceDisplay({ + scene : scene, + dataSourceCollection : dataSourceCollection, + visualizersCallback : visualizersCallback + }); + dataSourceCollection.add(source1); + dataSourceCollection.add(source2); + display.update(Iso8601.MINIMUM_VALUE); + expect(display.ready).toBe(false); + + return GroundPrimitive.initializeTerrainHeights().then(function() { + display.update(Iso8601.MINIMUM_VALUE); + expect(display.ready).toBe(true); + }); + }); }, 'WebGL'); From 8fa2ff3f960efc8481f50cebee1f52879e1161f3 Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Tue, 2 Aug 2016 11:20:50 -0400 Subject: [PATCH 4/4] Fixed unpredictability in the tests. We call initializeTerrainHeights where we need them and uninitialize when done, so we don't effect other tests. --- Specs/DataSources/DataSourceDisplaySpec.js | 6 ++++++ Specs/DataSources/GeometryVisualizerSpec.js | 9 +++++++++ Specs/Scene/GroundPrimitiveSpec.js | 11 +++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Specs/DataSources/DataSourceDisplaySpec.js b/Specs/DataSources/DataSourceDisplaySpec.js index b98af6d33b73..4ed201bdae44 100644 --- a/Specs/DataSources/DataSourceDisplaySpec.js +++ b/Specs/DataSources/DataSourceDisplaySpec.js @@ -35,6 +35,11 @@ defineSuite([ afterAll(function() { scene.destroyForSpecs(); + + // Leave ground primitive uninitialized + GroundPrimitive._initialized = false; + GroundPrimitive._initPromise = undefined; + GroundPrimitive._terrainHeights = undefined; }); afterEach(function() { @@ -347,6 +352,7 @@ defineSuite([ it('verify update returns false till terrain heights are initialized', function() { GroundPrimitive._initialized = false; GroundPrimitive._initPromise = undefined; + GroundPrimitive._terrainHeights = undefined; var source1 = new MockDataSource(); var source2 = new MockDataSource(); diff --git a/Specs/DataSources/GeometryVisualizerSpec.js b/Specs/DataSources/GeometryVisualizerSpec.js index f7b897a052cd..a4732555e599 100644 --- a/Specs/DataSources/GeometryVisualizerSpec.js +++ b/Specs/DataSources/GeometryVisualizerSpec.js @@ -22,6 +22,7 @@ defineSuite([ 'DataSources/StaticGeometryPerMaterialBatch', 'DataSources/StaticGroundGeometryColorBatch', 'DataSources/StaticOutlineGeometryBatch', + 'Scene/GroundPrimitive', 'Specs/createDynamicProperty', 'Specs/createScene', 'Specs/pollToPromise' @@ -48,6 +49,7 @@ defineSuite([ StaticGeometryPerMaterialBatch, StaticGroundGeometryColorBatch, StaticOutlineGeometryBatch, + GroundPrimitive, createDynamicProperty, createScene, pollToPromise) { @@ -58,10 +60,17 @@ defineSuite([ var scene; beforeAll(function() { scene = createScene(); + + return GroundPrimitive.initializeTerrainHeights(); }); afterAll(function() { scene.destroyForSpecs(); + + // Leave ground primitive uninitialized + GroundPrimitive._initialized = false; + GroundPrimitive._initPromise = undefined; + GroundPrimitive._terrainHeights = undefined; }); it('Can create and destroy', function() { diff --git a/Specs/Scene/GroundPrimitiveSpec.js b/Specs/Scene/GroundPrimitiveSpec.js index 0e5e87f4da96..80bac3ec1568 100644 --- a/Specs/Scene/GroundPrimitiveSpec.js +++ b/Specs/Scene/GroundPrimitiveSpec.js @@ -70,20 +70,23 @@ defineSuite([ var primitive; var depthPrimitive; - beforeAll(function(done) { + beforeAll(function() { scene = createScene(); scene.fxaa = false; context = scene.context; ellipsoid = Ellipsoid.WGS84; - GroundPrimitive.initializeTerrainHeights().then(function() { - done(); - }); + return GroundPrimitive.initializeTerrainHeights(); }); afterAll(function() { scene.destroyForSpecs(); + + // Leave ground primitive uninitialized + GroundPrimitive._initialized = false; + GroundPrimitive._initPromise = undefined; + GroundPrimitive._terrainHeights = undefined; }); function MockGlobePrimitive(primitive) {