-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for polylines on terrain via entity API #6689
Merged
bagnell
merged 4 commits into
CesiumGS:master
from
likangning93:polylinesOnTerrain-entity
Jun 18, 2018
+1,468
−88
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
365 changes: 365 additions & 0 deletions
365
Source/DataSources/StaticGroundPolylinePerMaterialBatch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,365 @@ | ||
define([ | ||
'../Core/AssociativeArray', | ||
'../Core/defined', | ||
'../Core/DistanceDisplayCondition', | ||
'../Core/DistanceDisplayConditionGeometryInstanceAttribute', | ||
'../Core/ShowGeometryInstanceAttribute', | ||
'../Scene/GroundPolylinePrimitive', | ||
'../Scene/PolylineColorAppearance', | ||
'../Scene/PolylineMaterialAppearance', | ||
'./BoundingSphereState', | ||
'./ColorMaterialProperty', | ||
'./MaterialProperty', | ||
'./Property' | ||
], function( | ||
AssociativeArray, | ||
defined, | ||
DistanceDisplayCondition, | ||
DistanceDisplayConditionGeometryInstanceAttribute, | ||
ShowGeometryInstanceAttribute, | ||
GroundPolylinePrimitive, | ||
PolylineColorAppearance, | ||
PolylineMaterialAppearance, | ||
BoundingSphereState, | ||
ColorMaterialProperty, | ||
MaterialProperty, | ||
Property) { | ||
'use strict'; | ||
|
||
var distanceDisplayConditionScratch = new DistanceDisplayCondition(); | ||
var defaultDistanceDisplayCondition = new DistanceDisplayCondition(); | ||
|
||
// Encapsulates a Primitive and all the entities that it represents. | ||
function Batch(orderedGroundPrimitives, materialProperty, zIndex) { | ||
var appearanceType; | ||
if (materialProperty instanceof ColorMaterialProperty) { | ||
appearanceType = PolylineColorAppearance; | ||
} else { | ||
appearanceType = PolylineMaterialAppearance; | ||
} | ||
|
||
this.orderedGroundPrimitives = orderedGroundPrimitives; // scene level primitive collection | ||
this.appearanceType = appearanceType; | ||
this.materialProperty = materialProperty; | ||
this.updaters = new AssociativeArray(); | ||
this.createPrimitive = true; | ||
this.primitive = undefined; // a GroundPolylinePrimitive encapsulating all the entities | ||
this.oldPrimitive = undefined; | ||
this.geometry = new AssociativeArray(); | ||
this.material = undefined; | ||
this.updatersWithAttributes = new AssociativeArray(); | ||
this.attributes = new AssociativeArray(); | ||
this.invalidated = false; | ||
this.removeMaterialSubscription = materialProperty.definitionChanged.addEventListener(Batch.prototype.onMaterialChanged, this); | ||
this.subscriptions = new AssociativeArray(); | ||
this.showsUpdated = new AssociativeArray(); | ||
this.zIndex = zIndex; | ||
} | ||
|
||
Batch.prototype.onMaterialChanged = function() { | ||
this.invalidated = true; | ||
}; | ||
|
||
// Check if the given updater's material is compatible with this batch | ||
Batch.prototype.isMaterial = function(updater) { | ||
var material = this.materialProperty; | ||
var updaterMaterial = updater.fillMaterialProperty; | ||
|
||
if (updaterMaterial === material || | ||
(updaterMaterial instanceof ColorMaterialProperty && material instanceof ColorMaterialProperty)) { | ||
return true; | ||
} | ||
return defined(material) && material.equals(updaterMaterial); | ||
}; | ||
|
||
Batch.prototype.add = function(time, updater, geometryInstance) { | ||
var id = updater.id; | ||
this.updaters.set(id, updater); | ||
this.geometry.set(id, geometryInstance); | ||
// Updaters with dynamic attributes must be tracked separately, may exit the batch | ||
if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty)) { | ||
this.updatersWithAttributes.set(id, updater); | ||
} else { | ||
var that = this; | ||
// Listen for show changes. These will be synchronized in updateShows. | ||
this.subscriptions.set(id, updater.entity.definitionChanged.addEventListener(function(entity, propertyName, newValue, oldValue) { | ||
if (propertyName === 'isShowing') { | ||
that.showsUpdated.set(updater.id, updater); | ||
} | ||
})); | ||
} | ||
this.createPrimitive = true; | ||
}; | ||
|
||
Batch.prototype.remove = function(updater) { | ||
var id = updater.id; | ||
this.createPrimitive = this.geometry.remove(id) || this.createPrimitive; | ||
if (this.updaters.remove(id)) { | ||
this.updatersWithAttributes.remove(id); | ||
var unsubscribe = this.subscriptions.get(id); | ||
if (defined(unsubscribe)) { | ||
unsubscribe(); | ||
this.subscriptions.remove(id); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
Batch.prototype.update = function(time) { | ||
var isUpdated = true; | ||
var primitive = this.primitive; | ||
var orderedGroundPrimitives = this.orderedGroundPrimitives; | ||
var geometries = this.geometry.values; | ||
var attributes; | ||
var i; | ||
|
||
if (this.createPrimitive) { | ||
var geometriesLength = geometries.length; | ||
if (geometriesLength > 0) { | ||
if (defined(primitive)) { | ||
// Keep a handle to the old primitive so it can be removed when the updated version is ready. | ||
if (!defined(this.oldPrimitive)) { | ||
this.oldPrimitive = primitive; | ||
} else { | ||
// For if the new primitive changes again before it is ready. | ||
orderedGroundPrimitives.remove(primitive); | ||
} | ||
} | ||
|
||
for (i = 0; i < geometriesLength; i++) { | ||
var geometry = geometries[i]; | ||
var originalAttributes = geometry.attributes; | ||
attributes = this.attributes.get(geometry.id.id); | ||
|
||
if (defined(attributes)) { | ||
if (defined(originalAttributes.show)) { | ||
originalAttributes.show.value = attributes.show; | ||
} | ||
if (defined(originalAttributes.color)) { | ||
originalAttributes.color.value = attributes.color; | ||
} | ||
} | ||
} | ||
|
||
primitive = new GroundPolylinePrimitive({ | ||
show : false, | ||
asynchronous : true, | ||
geometryInstances : geometries, | ||
appearance : new this.appearanceType() | ||
}); | ||
|
||
if (this.appearanceType === PolylineMaterialAppearance) { | ||
this.material = MaterialProperty.getValue(time, this.materialProperty, this.material); | ||
primitive.appearance.material = this.material; | ||
} | ||
|
||
orderedGroundPrimitives.add(primitive, this.zIndex); | ||
isUpdated = false; | ||
} else { | ||
if (defined(primitive)) { | ||
orderedGroundPrimitives.remove(primitive); | ||
primitive = undefined; | ||
} | ||
var oldPrimitive = this.oldPrimitive; | ||
if (defined(oldPrimitive)) { | ||
orderedGroundPrimitives.remove(oldPrimitive); | ||
this.oldPrimitive = undefined; | ||
} | ||
} | ||
|
||
this.attributes.removeAll(); | ||
this.primitive = primitive; | ||
this.createPrimitive = false; | ||
} else if (defined(primitive) && primitive.ready) { | ||
primitive.show = true; | ||
if (defined(this.oldPrimitive)) { | ||
orderedGroundPrimitives.remove(this.oldPrimitive); | ||
this.oldPrimitive = undefined; | ||
} | ||
|
||
if (this.appearanceType === PolylineMaterialAppearance) { | ||
this.material = MaterialProperty.getValue(time, this.materialProperty, this.material); | ||
this.primitive.appearance.material = this.material; | ||
} | ||
var updatersWithAttributes = this.updatersWithAttributes.values; | ||
var length = updatersWithAttributes.length; | ||
for (i = 0; i < length; i++) { | ||
var updater = updatersWithAttributes[i]; | ||
var entity = updater.entity; | ||
var instance = this.geometry.get(updater.id); | ||
|
||
attributes = this.attributes.get(instance.id.id); | ||
if (!defined(attributes)) { | ||
attributes = primitive.getGeometryInstanceAttributes(instance.id); | ||
this.attributes.set(instance.id.id, attributes); | ||
} | ||
|
||
var show = entity.isShowing && (updater.hasConstantFill || updater.isFilled(time)); | ||
var currentShow = attributes.show[0] === 1; | ||
if (show !== currentShow) { | ||
attributes.show = ShowGeometryInstanceAttribute.toValue(show, attributes.show); | ||
} | ||
|
||
var distanceDisplayConditionProperty = updater.distanceDisplayConditionProperty; | ||
if (!Property.isConstant(distanceDisplayConditionProperty)) { | ||
var distanceDisplayCondition = Property.getValueOrDefault(distanceDisplayConditionProperty, time, defaultDistanceDisplayCondition, distanceDisplayConditionScratch); | ||
if (!DistanceDisplayCondition.equals(distanceDisplayCondition, attributes._lastDistanceDisplayCondition)) { | ||
attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(distanceDisplayCondition, attributes._lastDistanceDisplayCondition); | ||
attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition); | ||
} | ||
} | ||
} | ||
|
||
this.updateShows(primitive); | ||
} else if (defined(primitive) && !primitive.ready) { | ||
isUpdated = false; | ||
} | ||
return isUpdated; | ||
}; | ||
|
||
Batch.prototype.updateShows = function(primitive) { | ||
var showsUpdated = this.showsUpdated.values; | ||
var length = showsUpdated.length; | ||
for (var i = 0; i < length; i++) { | ||
var updater = showsUpdated[i]; | ||
var entity = updater.entity; | ||
var instance = this.geometry.get(updater.id); | ||
|
||
var attributes = this.attributes.get(instance.id.id); | ||
if (!defined(attributes)) { | ||
attributes = primitive.getGeometryInstanceAttributes(instance.id); | ||
this.attributes.set(instance.id.id, attributes); | ||
} | ||
|
||
var show = entity.isShowing; | ||
var currentShow = attributes.show[0] === 1; | ||
if (show !== currentShow) { | ||
attributes.show = ShowGeometryInstanceAttribute.toValue(show, attributes.show); | ||
} | ||
} | ||
this.showsUpdated.removeAll(); | ||
}; | ||
|
||
Batch.prototype.contains = function(updater) { | ||
return this.updaters.contains(updater.id); | ||
}; | ||
|
||
Batch.prototype.getBoundingSphere = function(updater, result) { | ||
var primitive = this.primitive; | ||
if (!primitive.ready) { | ||
return BoundingSphereState.PENDING; | ||
} | ||
var attributes = primitive.getGeometryInstanceAttributes(updater.entity); | ||
if (!defined(attributes) || !defined(attributes.boundingSphere) || | ||
(defined(attributes.show) && attributes.show[0] === 0)) { | ||
return BoundingSphereState.FAILED; | ||
} | ||
attributes.boundingSphere.clone(result); | ||
return BoundingSphereState.DONE; | ||
}; | ||
|
||
Batch.prototype.destroy = function() { | ||
var primitive = this.primitive; | ||
var orderedGroundPrimitives = this.orderedGroundPrimitives; | ||
if (defined(primitive)) { | ||
orderedGroundPrimitives.remove(primitive); | ||
} | ||
var oldPrimitive = this.oldPrimitive; | ||
if (defined(oldPrimitive)) { | ||
orderedGroundPrimitives.remove(oldPrimitive); | ||
} | ||
this.removeMaterialSubscription(); | ||
}; | ||
|
||
/** | ||
* @private | ||
*/ | ||
function StaticGroundPolylinePerMaterialBatch(orderedGroundPrimitives) { | ||
this._items = []; | ||
this._orderedGroundPrimitives = orderedGroundPrimitives; | ||
} | ||
|
||
StaticGroundPolylinePerMaterialBatch.prototype.add = function(time, updater) { | ||
var items = this._items; | ||
var length = items.length; | ||
var geometryInstance = updater.createFillGeometryInstance(time); | ||
var zIndex = Property.getValueOrDefault(updater.zIndex, 0); | ||
// Check if the Entity represented by the updater has the same material or a material representable with per-instance color. | ||
for (var i = 0; i < length; ++i) { | ||
var item = items[i]; | ||
if (item.isMaterial(updater) && | ||
item.zIndex === zIndex) { | ||
item.add(time, updater, geometryInstance); | ||
return; | ||
} | ||
} | ||
// If a compatible batch wasn't found, create a new batch. | ||
var batch = new Batch(this._orderedGroundPrimitives, updater.fillMaterialProperty, zIndex); | ||
batch.add(time, updater, geometryInstance); | ||
items.push(batch); | ||
}; | ||
|
||
StaticGroundPolylinePerMaterialBatch.prototype.remove = function(updater) { | ||
var items = this._items; | ||
var length = items.length; | ||
for (var i = length - 1; i >= 0; i--) { | ||
var item = items[i]; | ||
if (item.remove(updater)) { | ||
if (item.updaters.length === 0) { | ||
items.splice(i, 1); | ||
item.destroy(); | ||
} | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
StaticGroundPolylinePerMaterialBatch.prototype.update = function(time) { | ||
var i; | ||
var items = this._items; | ||
var length = items.length; | ||
|
||
for (i = length - 1; i >= 0; i--) { | ||
var item = items[i]; | ||
if (item.invalidated) { | ||
items.splice(i, 1); | ||
var updaters = item.updaters.values; | ||
var updatersLength = updaters.length; | ||
for (var h = 0; h < updatersLength; h++) { | ||
this.add(time, updaters[h]); | ||
} | ||
item.destroy(); | ||
} | ||
} | ||
|
||
var isUpdated = true; | ||
for (i = 0; i < length; i++) { | ||
isUpdated = items[i].update(time) && isUpdated; | ||
} | ||
return isUpdated; | ||
}; | ||
|
||
StaticGroundPolylinePerMaterialBatch.prototype.getBoundingSphere = function(updater, result) { | ||
var items = this._items; | ||
var length = items.length; | ||
for (var i = 0; i < length; i++) { | ||
var item = items[i]; | ||
if (item.contains(updater)){ | ||
return item.getBoundingSphere(updater, result); | ||
} | ||
} | ||
return BoundingSphereState.FAILED; | ||
}; | ||
|
||
StaticGroundPolylinePerMaterialBatch.prototype.removeAllPrimitives = function() { | ||
var items = this._items; | ||
var length = items.length; | ||
for (var i = 0; i < length; i++) { | ||
items[i].destroy(); | ||
} | ||
this._items.length = 0; | ||
}; | ||
|
||
return StaticGroundPolylinePerMaterialBatch; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
388 changes: 388 additions & 0 deletions
388
Specs/DataSources/StaticGroundPolylinePerMaterialBatchSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,388 @@ | ||
defineSuite([ | ||
'DataSources/StaticGroundPolylinePerMaterialBatch', | ||
'Core/BoundingSphere', | ||
'Core/Cartesian3', | ||
'Core/Color', | ||
'Core/DistanceDisplayCondition', | ||
'Core/JulianDate', | ||
'Core/Math', | ||
'Core/TimeInterval', | ||
'Core/TimeIntervalCollection', | ||
'DataSources/BoundingSphereState', | ||
'DataSources/ConstantProperty', | ||
'DataSources/Entity', | ||
'DataSources/PolylineOutlineMaterialProperty', | ||
'DataSources/PolylineGeometryUpdater', | ||
'DataSources/PolylineGraphics', | ||
'DataSources/TimeIntervalCollectionProperty', | ||
'Scene/GroundPolylinePrimitive', | ||
'Scene/MaterialAppearance', | ||
'Specs/createScene', | ||
'Specs/pollToPromise' | ||
], function( | ||
StaticGroundPolylinePerMaterialBatch, | ||
BoundingSphere, | ||
Cartesian3, | ||
Color, | ||
DistanceDisplayCondition, | ||
JulianDate, | ||
CesiumMath, | ||
TimeInterval, | ||
TimeIntervalCollection, | ||
BoundingSphereState, | ||
ConstantProperty, | ||
Entity, | ||
PolylineOutlineMaterialProperty, | ||
PolylineGeometryUpdater, | ||
PolylineGraphics, | ||
TimeIntervalCollectionProperty, | ||
GroundPolylinePrimitive, | ||
MaterialAppearance, | ||
createScene, | ||
pollToPromise) { | ||
'use strict'; | ||
|
||
var time = JulianDate.now(); | ||
var scene; | ||
beforeAll(function() { | ||
scene = createScene(); | ||
}); | ||
|
||
afterAll(function() { | ||
scene.destroyForSpecs(); | ||
}); | ||
|
||
function createGroundPolyline() { | ||
var polyline = new PolylineGraphics(); | ||
polyline.clampToGround = new ConstantProperty(true); | ||
polyline.positions = new ConstantProperty(Cartesian3.fromRadiansArray([ | ||
0, 0, | ||
1, 0, | ||
1, 1, | ||
0, 1 | ||
])); | ||
return polyline; | ||
} | ||
|
||
it('handles shared material being invalidated with geometry', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives); | ||
|
||
var polyline1 = createGroundPolyline(); | ||
polyline1.material = new PolylineOutlineMaterialProperty(); | ||
|
||
var entity = new Entity({ | ||
polyline : polyline1 | ||
}); | ||
|
||
var polyline2 = createGroundPolyline(); | ||
polyline2.material = new PolylineOutlineMaterialProperty(); | ||
|
||
var entity2 = new Entity({ | ||
polyline : polyline2 | ||
}); | ||
|
||
var updater = new PolylineGeometryUpdater(entity, scene); | ||
var updater2 = new PolylineGeometryUpdater(entity2, scene); | ||
batch.add(time, updater); | ||
batch.add(time, updater2); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(1); | ||
polyline1.material.outlineWidth = new ConstantProperty(0.5); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(2); | ||
batch.removeAllPrimitives(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('updates with sampled distance display condition out of range', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var validTime = JulianDate.fromIso8601('2018-02-14T04:10:00+1100'); | ||
var ddc = new TimeIntervalCollectionProperty(); | ||
ddc.intervals.addInterval(TimeInterval.fromIso8601({ | ||
iso8601: '2018-02-14T04:00:00+1100/2018-02-14T04:15:00+1100', | ||
data: new DistanceDisplayCondition(1.0, 2.0) | ||
})); | ||
var polyline = createGroundPolyline(); | ||
polyline.distanceDisplayCondition = ddc; | ||
var entity = new Entity({ | ||
availability: new TimeIntervalCollection([TimeInterval.fromIso8601({iso8601: '2018-02-14T04:00:00+1100/2018-02-14T04:30:00+1100'})]), | ||
polyline: polyline | ||
}); | ||
|
||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives); | ||
|
||
var updater = new PolylineGeometryUpdater(entity, scene); | ||
batch.add(validTime, updater); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(validTime); | ||
scene.render(validTime); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(1); | ||
var primitive = scene.groundPrimitives.get(0); | ||
var attributes = primitive.getGeometryInstanceAttributes(entity); | ||
expect(attributes.distanceDisplayCondition).toEqualEpsilon([1.0, 2.0], CesiumMath.EPSILON6); | ||
|
||
batch.update(time); | ||
scene.render(time); | ||
|
||
primitive = scene.groundPrimitives.get(0); | ||
attributes = primitive.getGeometryInstanceAttributes(entity); | ||
expect(attributes.distanceDisplayCondition).toEqual([0.0, Infinity]); | ||
|
||
batch.removeAllPrimitives(); | ||
}); | ||
}); | ||
|
||
it('shows only one primitive while rebuilding primitive', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives, MaterialAppearance); | ||
|
||
function buildEntity() { | ||
var polyline = createGroundPolyline(); | ||
polyline.material = new PolylineOutlineMaterialProperty({ | ||
color : Color.ORANGE, | ||
outlineWidth : 2, | ||
outlineColor : Color.BLACK | ||
}); | ||
|
||
return new Entity({ | ||
polyline : polyline | ||
}); | ||
} | ||
|
||
function renderScene() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
} | ||
|
||
var entity1 = buildEntity(); | ||
var entity2 = buildEntity(); | ||
|
||
var updater1 = new PolylineGeometryUpdater(entity1, scene); | ||
var updater2 = new PolylineGeometryUpdater(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(); | ||
}); | ||
}); | ||
|
||
it('batches entities that both use color materials', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives, MaterialAppearance); | ||
var polyline1 = createGroundPolyline(); | ||
polyline1.material = Color.RED; | ||
var entity = new Entity({ | ||
polyline : polyline1 | ||
}); | ||
|
||
var polyline2 = createGroundPolyline(); | ||
polyline2.material = Color.RED; | ||
var entity2 = new Entity({ | ||
polyline : polyline2 | ||
}); | ||
|
||
var updater = new PolylineGeometryUpdater(entity, scene); | ||
var updater2 = new PolylineGeometryUpdater(entity2, scene); | ||
batch.add(time, updater); | ||
batch.add(time, updater2); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(1); | ||
|
||
batch.removeAllPrimitives(); | ||
}); | ||
}); | ||
|
||
it('batches entities with the same material but different Z indices separately', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives); | ||
|
||
var polyline1 = createGroundPolyline(); | ||
polyline1.material = new PolylineOutlineMaterialProperty(); | ||
polyline1.zIndex = 0; | ||
|
||
var entity = new Entity({ | ||
polyline : polyline1 | ||
}); | ||
|
||
var polyline2 = createGroundPolyline(); | ||
polyline2.material = new PolylineOutlineMaterialProperty(); | ||
polyline2.zIndex = 1; | ||
|
||
var entity2 = new Entity({ | ||
polyline : polyline2 | ||
}); | ||
|
||
var updater = new PolylineGeometryUpdater(entity, scene); | ||
var updater2 = new PolylineGeometryUpdater(entity2, scene); | ||
batch.add(time, updater); | ||
batch.add(time, updater2); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(2); | ||
|
||
batch.removeAllPrimitives(); | ||
}); | ||
}); | ||
|
||
it('removes entities', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives); | ||
|
||
var polyline1 = createGroundPolyline(); | ||
polyline1.material = new PolylineOutlineMaterialProperty(); | ||
|
||
var entity = new Entity({ | ||
polyline : polyline1 | ||
}); | ||
|
||
var updater = new PolylineGeometryUpdater(entity, scene); | ||
batch.add(time, updater); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(1); | ||
|
||
batch.remove(updater); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}); | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(0); | ||
batch.removeAllPrimitives(); | ||
}); | ||
}); | ||
|
||
it('gets bounding spheres', function() { | ||
if (!GroundPolylinePrimitive.isSupported(scene)) { | ||
// Don't fail if GroundPolylinePrimitive is not supported | ||
return; | ||
} | ||
|
||
var resultSphere = new BoundingSphere(); | ||
var batch = new StaticGroundPolylinePerMaterialBatch(scene.groundPrimitives); | ||
|
||
var polyline1 = createGroundPolyline(); | ||
polyline1.material = new PolylineOutlineMaterialProperty(); | ||
|
||
var entity = new Entity({ | ||
polyline : polyline1 | ||
}); | ||
|
||
var updater = new PolylineGeometryUpdater(entity, scene); | ||
|
||
var state = batch.getBoundingSphere(updater, resultSphere); | ||
expect(state).toEqual(BoundingSphereState.FAILED); | ||
|
||
batch.add(time, updater); | ||
|
||
batch.update(time); | ||
state = batch.getBoundingSphere(updater, resultSphere); | ||
expect(state).toEqual(BoundingSphereState.PENDING); | ||
|
||
return pollToPromise(function() { | ||
scene.initializeFrame(); | ||
var isUpdated = batch.update(time); | ||
scene.render(time); | ||
return isUpdated; | ||
}).then(function() { | ||
expect(scene.groundPrimitives.length).toEqual(1); | ||
|
||
state = batch.getBoundingSphere(updater, resultSphere); | ||
expect(state).toEqual(BoundingSphereState.DONE); | ||
|
||
batch.removeAllPrimitives(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly copied from
StaticGroundGeometryPerMaterialBatch
, it just allows a lot more flexibility in batching and needs its own primitive-type.