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 dynamic partial ellipsoids #8277

Merged
merged 4 commits into from
Oct 15, 2019
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

### 1.63 - 2019-11-01

##### Fixes :wrench:
* Fix dynamic ellipsoids using `innerRadii`, `minimumClock`, `maximumClock`, `minimumCone` or `maximumCone`. [#8277](https://github.com/AnalyticalGraphicsInc/cesium/pull/8277)

### 1.62 - 2019-10-01

##### Deprecated :hourglass_flowing_sand:
Expand Down
48 changes: 32 additions & 16 deletions Source/DataSources/EllipsoidGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Property from './Property.js';

var offsetScratch = new Cartesian3();
var radiiScratch = new Cartesian3();
var innerRadiiScratch = new Cartesian3();
var scratchColor = new Color();
var unitSphere = new Cartesian3(1, 1, 1);

Expand Down Expand Up @@ -83,8 +84,8 @@ import Property from './Property.js';
* @memberof EllipsoidGeometryUpdater.prototype
* @readonly
*/
terrainOffsetProperty: {
get: function() {
terrainOffsetProperty : {
get : function() {
return this._terrainOffsetProperty;
}
}
Expand Down Expand Up @@ -117,7 +118,7 @@ import Property from './Property.js';
show : show,
distanceDisplayCondition : distanceDisplayConditionAttribute,
color : undefined,
offset: undefined
offset : undefined
};

if (this._materialProperty instanceof ColorMaterialProperty) {
Expand Down Expand Up @@ -194,9 +195,14 @@ import Property from './Property.js';
return !entity.position.isConstant || //
!Property.isConstant(entity.orientation) || //
!ellipsoid.radii.isConstant || //
!Property.isConstant(ellipsoid.innerRadii) || //
!Property.isConstant(ellipsoid.stackPartitions) || //
!Property.isConstant(ellipsoid.slicePartitions) || //
!Property.isConstant(ellipsoid.outlineWidth) || //
!Property.isConstant(ellipsoid.minimumClock) || //
!Property.isConstant(ellipsoid.maximumClock) || //
!Property.isConstant(ellipsoid.minimumCone) || //
!Property.isConstant(ellipsoid.maximumCone) || //
!Property.isConstant(ellipsoid.subdivisions);
};

Expand Down Expand Up @@ -282,6 +288,11 @@ import Property from './Property.js';
var material = MaterialProperty.getValue(time, defaultValue(ellipsoid.material, defaultMaterial), this._material);

// Check properties that could trigger a primitive rebuild.
var innerRadii = Property.getValueOrUndefined(ellipsoid.innerRadii, time, innerRadiiScratch);
var minimumClock = Property.getValueOrUndefined(ellipsoid.minimumClock, time);
var maximumClock = Property.getValueOrUndefined(ellipsoid.maximumClock, time);
var minimumCone = Property.getValueOrUndefined(ellipsoid.minimumCone, time);
var maximumCone = Property.getValueOrUndefined(ellipsoid.maximumCone, time);
var stackPartitions = Property.getValueOrUndefined(ellipsoid.stackPartitions, time);
var slicePartitions = Property.getValueOrUndefined(ellipsoid.slicePartitions, time);
var subdivisions = Property.getValueOrUndefined(ellipsoid.subdivisions, time);
Expand All @@ -307,7 +318,10 @@ import Property from './Property.js';
//For the radii, we use unit sphere and then deform it with a scale matrix.
var rebuildPrimitives = !in3D || this._lastSceneMode !== sceneMode || !defined(this._primitive) || //
options.stackPartitions !== stackPartitions || options.slicePartitions !== slicePartitions || //
options.subdivisions !== subdivisions || this._lastOutlineWidth !== outlineWidth || options.offsetAttribute !== offsetAttribute;
defined(innerRadii) && !Cartesian3.equals(options.innerRadii !== innerRadii) || options.minimumClock !== minimumClock || //
options.maximumClock !== maximumClock || options.minimumCone !== minimumCone || //
options.maximumCone !== maximumCone || options.subdivisions !== subdivisions || //
this._lastOutlineWidth !== outlineWidth || options.offsetAttribute !== offsetAttribute;

if (rebuildPrimitives) {
var primitives = this._primitives;
Expand All @@ -322,19 +336,21 @@ import Property from './Property.js';
options.slicePartitions = slicePartitions;
options.subdivisions = subdivisions;
options.offsetAttribute = offsetAttribute;
options.radii = in3D ? unitSphere : radii;
var innerRadii = Property.getValueOrDefault(ellipsoid.innerRadii, time, radii, new Cartesian3());
if (in3D) {
var mag = Cartesian3.magnitude(radii);
var innerRadiiUnit = new Cartesian3(innerRadii.x/mag, innerRadii.y/mag, innerRadii.z/mag);
options.innerRadii = innerRadiiUnit;
options.radii = Cartesian3.clone(in3D ? unitSphere : radii, options.radii);
if (defined(innerRadii)) {
if (in3D) {
var mag = Cartesian3.magnitude(radii);
options.innerRadii = Cartesian3.fromElements(innerRadii.x / mag, innerRadii.y / mag, innerRadii.z / mag, options.innerRadii);
} else {
options.innerRadii = Cartesian3.clone(innerRadii, options.innerRadii);
}
} else {
options.innerRadii = innerRadii;
options.innerRadii = undefined;
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
}
options.minimumClock = Property.getValueOrUndefined(ellipsoid.minimumClock, time);
options.maximumClock = Property.getValueOrUndefined(ellipsoid.maximumClock, time);
options.minimumCone = Property.getValueOrUndefined(ellipsoid.minimumCone, time);
options.maximumCone = Property.getValueOrUndefined(ellipsoid.maximumCone, time);
options.minimumClock = minimumClock;
options.maximumClock = maximumClock;
options.minimumCone = minimumCone;
options.maximumCone = maximumCone;

var appearance = new MaterialAppearance({
material : material,
Expand Down Expand Up @@ -415,7 +431,7 @@ import Property from './Property.js';

if (!Cartesian3.equals(offset, this._lastOffset)) {
attributes.offset = OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);
outlineAttributes.offset = OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);
outlineAttributes.offset = OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);
Cartesian3.clone(offset, this._lastOffset);
}
}
Expand Down
50 changes: 50 additions & 0 deletions Specs/DataSources/EllipsoidGeometryUpdaterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,56 @@ describe('DataSources/EllipsoidGeometryUpdater', function() {
expect(updater.isDynamic).toBe(true);
});

it('A time-varying innerRadii causes geometry to be dynamic', function() {
var entity = createBasicEllipsoid();
var updater = new EllipsoidGeometryUpdater(entity, scene);
entity.ellipsoid.innerRadii = new SampledProperty(Cartesian3);
entity.ellipsoid.innerRadii.addSample(time, new Cartesian3(1, 2, 3));
updater._onEntityPropertyChanged(entity, 'ellipsoid');

expect(updater.isDynamic).toBe(true);
});

it('A time-varying minimumClock causes geometry to be dynamic', function() {
var entity = createBasicEllipsoid();
var updater = new EllipsoidGeometryUpdater(entity, scene);
entity.ellipsoid.minimumClock = new SampledProperty(Number);
entity.ellipsoid.minimumClock.addSample(time, 1);
updater._onEntityPropertyChanged(entity, 'ellipsoid');

expect(updater.isDynamic).toBe(true);
});

it('A time-varying maximumClock causes geometry to be dynamic', function() {
var entity = createBasicEllipsoid();
var updater = new EllipsoidGeometryUpdater(entity, scene);
entity.ellipsoid.maximumClock = new SampledProperty(Number);
entity.ellipsoid.maximumClock.addSample(time, 1);
updater._onEntityPropertyChanged(entity, 'ellipsoid');

expect(updater.isDynamic).toBe(true);
});

it('A time-varying minimumCone causes geometry to be dynamic', function() {
var entity = createBasicEllipsoid();
var updater = new EllipsoidGeometryUpdater(entity, scene);
entity.ellipsoid.minimumCone = new SampledProperty(Number);
entity.ellipsoid.minimumCone.addSample(time, 1);
updater._onEntityPropertyChanged(entity, 'ellipsoid');

expect(updater.isDynamic).toBe(true);
});

it('A time-varying maximumCone causes geometry to be dynamic', function() {
var entity = createBasicEllipsoid();
var updater = new EllipsoidGeometryUpdater(entity, scene);
entity.ellipsoid.maximumCone = new SampledProperty(Number);
entity.ellipsoid.maximumCone.addSample(time, 1);
updater._onEntityPropertyChanged(entity, 'ellipsoid');

expect(updater.isDynamic).toBe(true);
});

it('Creates geometry with expected properties', function() {
var options = {
radii : new Cartesian3(1, 2, 3),
Expand Down