From 88a8de1a45628394ae6a3c813ee081062a047ec4 Mon Sep 17 00:00:00 2001 From: roderickgreen Date: Mon, 2 Apr 2018 23:02:58 -0400 Subject: [PATCH 1/4] Fixes #3945: Flickering when adding a new polygon entity --- CONTRIBUTORS.md | 2 + .../DataSources/StaticGeometryColorBatch.js | 2 + .../StaticGeometryPerMaterialBatch.js | 2 + .../DataSources/StaticOutlineGeometryBatch.js | 2 + .../StaticGeometryColorBatchSpec.js | 62 ++++++++++++++++ .../StaticGeometryPerMaterialBatchSpec.js | 73 +++++++++++++++++++ .../StaticOutlineGeometryBatchSpec.js | 65 +++++++++++++++++ 7 files changed, 208 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6e7bb89fe518..67402d648316 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -102,6 +102,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Natanael Rivera](https://github.com/nrivera-Novetta/) * [Justin Burr](https://github.com/jburr-nc/) * [Jeremy Marzano](https://github.com/JeremyMarzano-ISPA/) +* [Orbit Logic](http://www.orbitlogic.com) + * [Roderick Green](https://github.com/roderickgreen/) ## [Individual CLA](Documentation/Contributors/CLAs/individual-cla-agi-v1.0.txt) * [Victor Berchet](https://github.com/vicb) diff --git a/Source/DataSources/StaticGeometryColorBatch.js b/Source/DataSources/StaticGeometryColorBatch.js index 086ba3a08979..a56555b00428 100644 --- a/Source/DataSources/StaticGeometryColorBatch.js +++ b/Source/DataSources/StaticGeometryColorBatch.js @@ -156,6 +156,7 @@ define([ } primitive = new Primitive({ + show : false, asynchronous : true, geometryInstances : geometries, appearance : new this.appearanceType({ @@ -184,6 +185,7 @@ define([ this.createPrimitive = false; this.waitingOnCreate = true; } else if (defined(primitive) && primitive.ready) { + primitive.show = true; if (defined(this.oldPrimitive)) { primitives.remove(this.oldPrimitive); this.oldPrimitive = undefined; diff --git a/Source/DataSources/StaticGeometryPerMaterialBatch.js b/Source/DataSources/StaticGeometryPerMaterialBatch.js index 792e0e0f7c49..e39eb7042240 100644 --- a/Source/DataSources/StaticGeometryPerMaterialBatch.js +++ b/Source/DataSources/StaticGeometryPerMaterialBatch.js @@ -153,6 +153,7 @@ define([ } primitive = new Primitive({ + show : false, asynchronous : true, geometryInstances : geometries, appearance : new this.appearanceType({ @@ -182,6 +183,7 @@ define([ this.primitive = primitive; this.createPrimitive = false; } else if (defined(primitive) && primitive.ready) { + primitive.show = true; if (defined(this.oldPrimitive)) { primitives.remove(this.oldPrimitive); this.oldPrimitive = undefined; diff --git a/Source/DataSources/StaticOutlineGeometryBatch.js b/Source/DataSources/StaticOutlineGeometryBatch.js index 20e0a558590b..ff882923f7a1 100644 --- a/Source/DataSources/StaticOutlineGeometryBatch.js +++ b/Source/DataSources/StaticOutlineGeometryBatch.js @@ -111,6 +111,7 @@ define([ } primitive = new Primitive({ + show : false, asynchronous : true, geometryInstances : geometries, appearance : new PerInstanceColorAppearance({ @@ -142,6 +143,7 @@ define([ this.createPrimitive = false; this.waitingOnCreate = true; } else if (defined(primitive) && primitive.ready) { + primitive.show = true; if (defined(this.oldPrimitive)) { primitives.remove(this.oldPrimitive); this.oldPrimitive = undefined; diff --git a/Specs/DataSources/StaticGeometryColorBatchSpec.js b/Specs/DataSources/StaticGeometryColorBatchSpec.js index 92a2e3c99b5d..3586a6d036f2 100644 --- a/Specs/DataSources/StaticGeometryColorBatchSpec.js +++ b/Specs/DataSources/StaticGeometryColorBatchSpec.js @@ -274,4 +274,66 @@ defineSuite([ batch.removeAllPrimitives(); }); }); + + it('shows only one primitive while rebuilding primitive', function() { + var batch = new StaticGeometryColorBatch(scene.primitives, PerInstanceColorAppearance, undefined, false, ShadowMode.DISABLED); + + function buildEntity() { + return new Entity({ + position : new Cartesian3(1234, 5678, 9101112), + ellipse : { + semiMajorAxis : 2, + semiMinorAxis : 1, + material : Color.RED.withAlpha(0.5), + height : 0 + } + }); + } + + function renderScene() { + scene.initializeFrame(); + var isUpdated = batch.update(time); + scene.render(time); + return isUpdated; + } + + var entity1 = buildEntity(); + var entity2 = buildEntity(); + + var updater1 = new EllipseGeometryUpdater(entity1, scene); + var updater2 = new EllipseGeometryUpdater(entity2, scene); + + batch.add(time, updater1); + return pollToPromise(renderScene) + .then(function() { + expect(scene.primitives.length).toEqual(1); + var primitive = scene.primitives.get(0); + expect(primitive.show).toBeTruthy(); + }) + .then(function() { + batch.add(time, updater2); + }) + .then(function() { + return pollToPromise(function() { + renderScene(); + return scene.primitives.length === 2; + }); + }) + .then(function() { + var showCount = 0; + expect(scene.primitives.length).toEqual(2); + showCount += !!scene.primitives.get(0).show; + showCount += !!scene.primitives.get(1).show; + expect(showCount).toEqual(1); + }) + .then(function() { + return pollToPromise(renderScene); + }) + .then(function() { + expect(scene.primitives.length).toEqual(1); + var primitive = scene.primitives.get(0); + expect(primitive.show).toBeTruthy(); + batch.removeAllPrimitives(); + }); + }); }); diff --git a/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js b/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js index bd80c13c6ca1..c1464f6b350f 100644 --- a/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js +++ b/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/StaticGeometryPerMaterialBatch', + 'Core/Cartesian2', 'Core/Cartesian3', 'Core/Color', 'Core/DistanceDisplayCondition', @@ -26,6 +27,7 @@ defineSuite([ 'Specs/pollToPromise' ], function( StaticGeometryPerMaterialBatch, + Cartesian2, Cartesian3, Color, DistanceDisplayCondition, @@ -240,4 +242,75 @@ defineSuite([ batch.removeAllPrimitives(); }); }); + + it('shows only one primitive while rebuilding primitive', function() { + var batch = new StaticGeometryPerMaterialBatch(scene.primitives, MaterialAppearance, undefined, false, ShadowMode.DISABLED); + + function buildEntity() { + var material = new GridMaterialProperty({ + color : Color.YELLOW, + cellAlpha : 0.3, + lineCount : new Cartesian2(8, 8), + lineThickness : new Cartesian2(2.0, 2.0) + }); + + return new Entity({ + position : new Cartesian3(1234, 5678, 9101112), + ellipse : { + semiMajorAxis : 2, + semiMinorAxis : 1, + height : 0, + material: material + } + }); + } + + function renderScene() { + scene.initializeFrame(); + var isUpdated = batch.update(time); + scene.render(time); + return isUpdated; + } + + var entity1 = buildEntity(); + var entity2 = buildEntity(); + + var updater1 = new EllipseGeometryUpdater(entity1, scene); + var updater2 = new EllipseGeometryUpdater(entity2, scene); + + batch.add(time, updater1); + return pollToPromise(renderScene) + .then(function() { + expect(scene.primitives.length).toEqual(1); + var primitive = scene.primitives.get(0); + expect(primitive.show).toBeTruthy(); + }) + .then(function() { + batch.add(time, updater2); + }) + .then(function() { + return pollToPromise(function() { + renderScene(); + return scene.primitives.length === 2; + }); + }) + .then(function() { + var showCount = 0; + expect(scene.primitives.length).toEqual(2); + showCount += !!scene.primitives.get(0).show; + showCount += !!scene.primitives.get(1).show; + expect(showCount).toEqual(1); + }) + + .then(function() { + return pollToPromise(renderScene); + }) + .then(function() { + expect(scene.primitives.length).toEqual(1); + var primitive = scene.primitives.get(0); + expect(primitive.show).toBeTruthy(); + + batch.removeAllPrimitives(); + }); + }); }); diff --git a/Specs/DataSources/StaticOutlineGeometryBatchSpec.js b/Specs/DataSources/StaticOutlineGeometryBatchSpec.js index 35ae2727939b..dd90cc876c5a 100644 --- a/Specs/DataSources/StaticOutlineGeometryBatchSpec.js +++ b/Specs/DataSources/StaticOutlineGeometryBatchSpec.js @@ -184,4 +184,69 @@ defineSuite([ batch.removeAllPrimitives(); }); }); + + it('shows only one primitive while rebuilding primitive', function() { + var batch = new StaticOutlineGeometryBatch(scene.primitives, scene, false, ShadowMode.DISABLED); + + function buildEntity() { + return new Entity({ + position : new Cartesian3(1234, 5678, 9101112), + ellipse : { + semiMajorAxis : 2, + semiMinorAxis : 1, + height : 0, + outline : true, + outlineColor : Color.RED.withAlpha(0.5) + } + }); + } + + function renderScene() { + scene.initializeFrame(); + var isUpdated = batch.update(time); + scene.render(time); + return isUpdated; + } + + var entity1 = buildEntity(); + var entity2 = buildEntity(); + + var updater1 = new EllipseGeometryUpdater(entity1, scene); + var updater2 = new EllipseGeometryUpdater(entity2, scene); + + batch.add(time, updater1); + return pollToPromise(renderScene) + .then(function() { + expect(scene.primitives.length).toEqual(1); + var primitive = scene.primitives.get(0); + expect(primitive.show).toBeTruthy(); + }) + .then(function() { + batch.add(time, updater2); + }) + .then(function() { + return pollToPromise(function() { + renderScene(); + return scene.primitives.length === 2; + }); + }) + .then(function() { + var showCount = 0; + expect(scene.primitives.length).toEqual(2); + showCount += !!scene.primitives.get(0).show; + showCount += !!scene.primitives.get(1).show; + expect(showCount).toEqual(1); + }) + + .then(function() { + return pollToPromise(renderScene); + }) + .then(function() { + expect(scene.primitives.length).toEqual(1); + var primitive = scene.primitives.get(0); + expect(primitive.show).toBeTruthy(); + + batch.removeAllPrimitives(); + }); + }); }); From d6de977ac44fbaf6438476559e0596eca9c5336a Mon Sep 17 00:00:00 2001 From: Roderick Green Date: Thu, 5 Apr 2018 16:14:55 -0400 Subject: [PATCH 2/4] apply polygon flicker fix to StaticGroundGeometryColorBatch --- .../StaticGroundGeometryColorBatch.js | 2 + .../StaticGroundGeometryColorBatchSpec.js | 68 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/Source/DataSources/StaticGroundGeometryColorBatch.js b/Source/DataSources/StaticGroundGeometryColorBatch.js index c41ae6d881d6..9dcfc20bfde6 100644 --- a/Source/DataSources/StaticGroundGeometryColorBatch.js +++ b/Source/DataSources/StaticGroundGeometryColorBatch.js @@ -111,6 +111,7 @@ define([ } primitive = new GroundPrimitive({ + show : false, asynchronous : true, geometryInstances : geometries, classificationType : this.classificationType @@ -134,6 +135,7 @@ define([ this.createPrimitive = false; this.waitingOnCreate = true; } else if (defined(primitive) && primitive.ready) { + primitive.show = true; if (defined(this.oldPrimitive)) { primitives.remove(this.oldPrimitive); this.oldPrimitive = undefined; diff --git a/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js b/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js index 4216a08e2455..d1d471a35e44 100644 --- a/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js +++ b/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js @@ -169,4 +169,72 @@ defineSuite([ batch.removeAllPrimitives(); }); }); + + it('shows only one primitive while rebuilding primitive', function() { + if (!GroundPrimitive.isSupported(scene)) { + return; + } + + var batch = new StaticGroundGeometryColorBatch(scene.groundPrimitives, ClassificationType.BOTH); + function buildEntity() { + return new Entity({ + position : new Cartesian3(1234, 5678, 9101112), + ellipse : { + semiMajorAxis : 2, + semiMinorAxis : 1, + height : 0, + outline : true, + outlineColor : Color.RED.withAlpha(0.5) + } + }); + } + + function renderScene() { + scene.initializeFrame(); + var isUpdated = batch.update(time); + scene.render(time); + return isUpdated; + } + + var entity1 = buildEntity(); + var entity2 = buildEntity(); + + var updater1 = new EllipseGeometryUpdater(entity1, scene); + var updater2 = new EllipseGeometryUpdater(entity2, scene); + + batch.add(time, updater1); + return pollToPromise(renderScene) + .then(function() { + expect(scene.groundPrimitives.length).toEqual(1); + var primitive = scene.groundPrimitives.get(0); + expect(primitive.show).toBeTruthy(); + }) + .then(function() { + batch.add(time, updater2); + }) + .then(function() { + return pollToPromise(function() { + renderScene(); + return scene.groundPrimitives.length === 2; + }); + }) + .then(function() { + var showCount = 0; + expect(scene.groundPrimitives.length).toEqual(2); + showCount += !!scene.groundPrimitives.get(0).show; + showCount += !!scene.groundPrimitives.get(1).show; + expect(showCount).toEqual(1); + }) + + .then(function() { + return pollToPromise(renderScene); + }) + .then(function() { + expect(scene.groundPrimitives.length).toEqual(1); + var primitive = scene.groundPrimitives.get(0); + expect(primitive.show).toBeTruthy(); + + batch.removeAllPrimitives(); + }); + }); }); From 87cfb66e73bd41d0259177b0bae29f4acf9adecc Mon Sep 17 00:00:00 2001 From: Roderick Green Date: Tue, 10 Apr 2018 13:45:10 -0600 Subject: [PATCH 3/4] Minor code cleanup --- Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js | 1 - Specs/DataSources/StaticGroundGeometryColorBatchSpec.js | 1 - Specs/DataSources/StaticOutlineGeometryBatchSpec.js | 1 - 3 files changed, 3 deletions(-) diff --git a/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js b/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js index c1464f6b350f..297d4084ab30 100644 --- a/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js +++ b/Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js @@ -301,7 +301,6 @@ defineSuite([ showCount += !!scene.primitives.get(1).show; expect(showCount).toEqual(1); }) - .then(function() { return pollToPromise(renderScene); }) diff --git a/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js b/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js index d1d471a35e44..32d95f9f05f6 100644 --- a/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js +++ b/Specs/DataSources/StaticGroundGeometryColorBatchSpec.js @@ -225,7 +225,6 @@ defineSuite([ showCount += !!scene.groundPrimitives.get(1).show; expect(showCount).toEqual(1); }) - .then(function() { return pollToPromise(renderScene); }) diff --git a/Specs/DataSources/StaticOutlineGeometryBatchSpec.js b/Specs/DataSources/StaticOutlineGeometryBatchSpec.js index dd90cc876c5a..ba79994bc5bf 100644 --- a/Specs/DataSources/StaticOutlineGeometryBatchSpec.js +++ b/Specs/DataSources/StaticOutlineGeometryBatchSpec.js @@ -237,7 +237,6 @@ defineSuite([ showCount += !!scene.primitives.get(1).show; expect(showCount).toEqual(1); }) - .then(function() { return pollToPromise(renderScene); }) From 83db3486ece6cd94f18ec8f9637aad0540d92e8d Mon Sep 17 00:00:00 2001 From: Roderick Green Date: Tue, 10 Apr 2018 13:45:19 -0600 Subject: [PATCH 4/4] Updated CHANGES.md --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a59dc50a0861..6d9488ada1b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,10 +8,10 @@ Change Log * Fixed glTF support to handle meshes with and without tangent vectors, and with/without morph targets, sharing one material. [#6421](https://github.com/AnalyticalGraphicsInc/cesium/pull/6421) * Fixed glTF support to handle skinned meshes when no skin is supplied. [#6061](https://github.com/AnalyticalGraphicsInc/cesium/issues/6061) * Allow loadWithXhr to work with string URLs in a web worker. -* `GroundPrimitive`s and `ClassificationPrimitive`s will become ready when `show` is `false`. [#6428](https://github.com/AnalyticalGraphicsInc/cesium/pull/6428) +* `GroundPrimitive`s and `ClassificationPrimitive`s will become ready when `show` is `false`. [#6428](https://github.com/AnalyticalGraphicsInc/cesium/pull/6428) * Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912) * Fix parsing Cesium.js in older browsers that do not support all TypedArray types. [#6396](https://github.com/AnalyticalGraphicsInc/cesium/pull/6396) - +* Fix flicker when adding, removing, or modifiying entities. [#3945](https://github.com/AnalyticalGraphicsInc/cesium/issues/3945) ##### Additions :tada: * Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426)