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 StaticGeometryMaterialBatch remove #7163

Merged
merged 4 commits into from
Oct 22, 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 @@ -9,6 +9,7 @@ Change Log
* Added `cutoutRectangle` to `ImageryLayer`, which allows cutting out rectangular areas in imagery layers to reveal underlying imagery. [#7056](https://github.com/AnalyticalGraphicsInc/cesium/pull/7056)

##### Fixes :wrench:
* Fixed issue removing geometry entities with different materials [#7163](https://github.com/AnalyticalGraphicsInc/cesium/pull/7163)
* Fixed an issue where `pickPosition` would return incorrect results when called after `sampleHeight` or `clampToHeight`. [#7113](https://github.com/AnalyticalGraphicsInc/cesium/pull/7113)
* Fixed a crash when using `BingMapsGeocoderService` [#7143](https://github.com/AnalyticalGraphicsInc/cesium/issues/7143)

Expand Down
4 changes: 3 additions & 1 deletion Source/DataSources/StaticGeometryColorBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ define([
this.subscriptions.remove(id);
this.showsUpdated.remove(id);
}
return true;
}
return false;
};

Batch.prototype.update = function(time) {
Expand Down Expand Up @@ -353,8 +355,8 @@ define([
if (item.updaters.length === 0) {
items.splice(i, 1);
item.destroy();
return true;
}
return true;
}
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion Source/DataSources/StaticGeometryPerMaterialBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ define([
this.subscriptions.remove(id);
this.showsUpdated.remove(id);
}
return true;
}
return this.createPrimitive;
return false;
};

var colorScratch = new Color();
Expand Down
2 changes: 2 additions & 0 deletions Source/DataSources/StaticOutlineGeometryBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ define([
this.subscriptions.remove(id);
this.showsUpdated.remove(id);
}
return true;
}
return false;
};

Batch.prototype.update = function(time) {
Expand Down
66 changes: 66 additions & 0 deletions Specs/DataSources/StaticGeometryPerMaterialBatchSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defineSuite([
'Core/Math',
'Core/TimeInterval',
'Core/TimeIntervalCollection',
'DataSources/BoxGeometryUpdater',
'DataSources/CheckerboardMaterialProperty',
'DataSources/ColorMaterialProperty',
'DataSources/ConstantPositionProperty',
'DataSources/ConstantProperty',
Expand All @@ -18,6 +20,7 @@ defineSuite([
'DataSources/PolylineArrowMaterialProperty',
'DataSources/PolylineGeometryUpdater',
'DataSources/PolylineGraphics',
'DataSources/StripeMaterialProperty',
'DataSources/TimeIntervalCollectionProperty',
'Scene/MaterialAppearance',
'Scene/PolylineColorAppearance',
Expand All @@ -35,6 +38,8 @@ defineSuite([
CesiumMath,
TimeInterval,
TimeIntervalCollection,
BoxGeometryUpdater,
CheckerboardMaterialProeprty,
ColorMaterialProperty,
ConstantPositionProperty,
ConstantProperty,
Expand All @@ -45,6 +50,7 @@ defineSuite([
PolylineArrowMaterialProperty,
PolylineGeometryUpdater,
PolylineGraphics,
StripeMaterialProperty,
TimeIntervalCollectionProperty,
MaterialAppearance,
PolylineColorAppearance,
Expand Down Expand Up @@ -312,4 +318,64 @@ defineSuite([
batch.removeAllPrimitives();
});
});

it('removes all updaters', function() {
var batch = new StaticGeometryPerMaterialBatch(scene.primitives, MaterialAppearance, undefined, false, ShadowMode.DISABLED);

function buildEntity(MaterialProperty) {
var material = new MaterialProperty({
evenColor : Color.YELLOW,
oddColor: Color.BLUE
});

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(StripeMaterialProperty);
var entity2 = buildEntity(CheckerboardMaterialProeprty);
var entity3 = buildEntity(StripeMaterialProperty);
var entity4 = buildEntity(CheckerboardMaterialProeprty);

var updater1 = new EllipseGeometryUpdater(entity1, scene);
var updater2 = new EllipseGeometryUpdater(entity2, scene);
var updater3 = new EllipseGeometryUpdater(entity3, scene);
var updater4 = new EllipseGeometryUpdater(entity4, scene);
var emptyUpdater = new BoxGeometryUpdater(entity1, scene);

batch.add(time, updater1);
batch.add(time, updater2);
batch.add(time, updater3);
batch.add(time, updater4);
return pollToPromise(renderScene)
.then(function() {
expect(scene.primitives.length).toEqual(2);
})
.then(function() {
batch.remove(updater1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have time to refactor these things, we should probably have remove return true/false at this level as well so we can test that items are added/removed as expected.

batch.remove(updater2);
batch.remove(emptyUpdater);
batch.remove(updater3);
batch.remove(updater4);
return pollToPromise(renderScene);
})
.then(function() {
expect(scene.primitives.length).toEqual(0);
batch.removeAllPrimitives();
});
});
});