Skip to content
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

Fix ground polyline with dynamic color #6927

Merged
merged 5 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Change Log
* Fixed a crash when setting show to `false` on a polyline clamped to the ground. [#6912](https://github.com/AnalyticalGraphicsInc/cesium/issues/6912)
* Fixed crash that happened when calling `scene.pick` after setting a new terrain provider [#6918](https://github.com/AnalyticalGraphicsInc/cesium/pull/6918)
* Fixed an issue that caused the browser to hang when using `drillPick` on a polyline clamped to the ground. [6907](https://github.com/AnalyticalGraphicsInc/cesium/issues/6907)
* Fixed an issue where color wasn't updated propertly for polylines clamped to ground [#6927](https://github.com/AnalyticalGraphicsInc/cesium/pull/6927)

### 1.48 - 2018-08-01

Expand Down
14 changes: 14 additions & 0 deletions Source/DataSources/StaticGroundPolylinePerMaterialBatch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
define([
'../Core/AssociativeArray',
'../Core/Color',
'../Core/ColorGeometryInstanceAttribute',
'../Core/defined',
'../Core/DistanceDisplayCondition',
'../Core/DistanceDisplayConditionGeometryInstanceAttribute',
Expand All @@ -13,6 +15,8 @@ define([
'./Property'
], function(
AssociativeArray,
Color,
ColorGeometryInstanceAttribute,
defined,
DistanceDisplayCondition,
DistanceDisplayConditionGeometryInstanceAttribute,
Expand All @@ -26,6 +30,7 @@ define([
Property) {
'use strict';

var scratchColor = new Color();
var distanceDisplayConditionScratch = new DistanceDisplayCondition();
var defaultDistanceDisplayCondition = new DistanceDisplayCondition();

Expand Down Expand Up @@ -195,6 +200,15 @@ define([
this.attributes.set(instance.id.id, attributes);
}

if (!updater.fillMaterialProperty.isConstant) {
var colorProperty = updater.fillMaterialProperty.color;
var resultColor = Property.getValueOrDefault(colorProperty, time, Color.WHITE, scratchColor);
if (!Color.equals(attributes._lastColor, resultColor)) {
attributes._lastColor = Color.clone(resultColor, attributes._lastColor);
attributes.color = ColorGeometryInstanceAttribute.toValue(resultColor, attributes.color);
}
}

var show = entity.isShowing && (updater.hasConstantFill || updater.isFilled(time));
var currentShow = attributes.show[0] === 1;
if (show !== currentShow) {
Expand Down
48 changes: 48 additions & 0 deletions Specs/DataSources/StaticGroundPolylinePerMaterialBatchSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defineSuite([
'Core/TimeInterval',
'Core/TimeIntervalCollection',
'DataSources/BoundingSphereState',
'DataSources/ColorMaterialProperty',
'DataSources/ConstantProperty',
'DataSources/Entity',
'DataSources/PolylineOutlineMaterialProperty',
Expand All @@ -32,6 +33,7 @@ defineSuite([
TimeInterval,
TimeIntervalCollection,
BoundingSphereState,
ColorMaterialProperty,
ConstantProperty,
Entity,
PolylineOutlineMaterialProperty,
Expand Down Expand Up @@ -122,6 +124,52 @@ defineSuite([
});
});

it('updates with sampled color 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 color = new TimeIntervalCollectionProperty();
color.intervals.addInterval(TimeInterval.fromIso8601({
iso8601: '2018-02-14T04:00:00+1100/2018-02-14T04:15:00+1100',
data: Color.RED
}));
var polyline = createGroundPolyline();
polyline.material = new ColorMaterialProperty(color);
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.color).toEqual([255, 0, 0, 255]);

batch.update(time);
scene.render(time);

primitive = scene.groundPrimitives.get(0);
attributes = primitive.getGeometryInstanceAttributes(entity);
expect(attributes.color).toEqual([255, 255, 255, 255]);

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
Expand Down