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

Fixes issue #12465 (Entity Tracking broken) #12467

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 1.128 - 2025-04-01

### @cesium/engine

#### Fixes :wrench:

- Fixed broken Entity Tracking [sandcastle](https://sandcastle.cesium.com/?src=Entity%20tracking.html). [#12467](https://github.com/CesiumGS/cesium/pull/12467)

## 1.127 - 2025-03-03

### @cesium/engine
Expand Down
8 changes: 5 additions & 3 deletions packages/engine/Source/Widget/CesiumWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,8 @@ CesiumWidget.prototype._updateCanAnimate = function (isUpdated) {
this._clock.canAnimate = isUpdated;
};

const boundingSphereScratch = new BoundingSphere();

/**
* @private
*/
Expand All @@ -1146,15 +1148,15 @@ CesiumWidget.prototype._onTick = function (clock) {
}

const entityView = this._entityView;
if (defined(entityView) && defined(entityView.boundingSphere)) {
if (defined(entityView)) {
const trackedEntity = this._trackedEntity;
const trackedState = this._dataSourceDisplay.getBoundingSphere(
trackedEntity,
false,
entityView.boundingSphere,
entityView.boundingSphere ?? boundingSphereScratch,
);
if (trackedState === BoundingSphereState.DONE) {
entityView.update(time, entityView.boundingSphere);
entityView.update(time);
}
}
};
Expand Down
81 changes: 56 additions & 25 deletions packages/engine/Specs/DataSources/EntityViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,74 @@ describe(
expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10);
});

it("uses entity bounding sphere", function () {
const sampleOffset = new Cartesian3(
-1.3322676295501878e-15,
-7.348469228349534,
7.3484692283495345,
);
it("uses provided bounding sphere", function () {
const bs = new BoundingSphere(new Cartesian3(3, 4, 5), 6);
Comment on lines +92 to +93
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test that modifies the bounding sphere to prove that the camera will follow it on future calls to update?

(I didn't check all the other specs so if it already exists just lmk)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jjspace, done! This should be ready for another review

scene.camera.viewBoundingSphere(bs);
const positionWC = scene.camera.positionWC.clone();

const entity = new Entity();
entity.position = new ConstantPositionProperty(
Cartesian3.fromDegrees(0.0, 0.0),
);
const view = new EntityView(entity, scene, undefined);
view.update(
JulianDate.now(),
new BoundingSphere(new Cartesian3(3, 4, 5), 6),
);
expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10);
view.update(JulianDate.now(), bs);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC, 1e-10);

entity.trackingReferenceFrame = TrackingReferenceFrame.INERTIAL;
view.update(
JulianDate.now(),
new BoundingSphere(new Cartesian3(3, 4, 5), 6),
);
expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10);
view.update(JulianDate.now(), bs);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC, 1e-10);

entity.trackingReferenceFrame = TrackingReferenceFrame.VELOCITY;
view.update(
JulianDate.now(),
new BoundingSphere(new Cartesian3(3, 4, 5), 6),
);
expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10);
view.update(JulianDate.now(), bs);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC, 1e-10);

entity.trackingReferenceFrame = TrackingReferenceFrame.ENU;
view.update(
JulianDate.now(),
new BoundingSphere(new Cartesian3(3, 4, 5), 6),
view.update(JulianDate.now(), bs);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC, 1e-10);
});

it("jumps to updated bounding sphere", function () {
const bs1 = new BoundingSphere(new Cartesian3(1, 2, 3), 4);
scene.camera.viewBoundingSphere(bs1);
const positionWC1 = scene.camera.positionWC.clone();

const bs2 = new BoundingSphere(new Cartesian3(3, 4, 5), 4);
scene.camera.viewBoundingSphere(bs2);
const positionWC2 = scene.camera.positionWC.clone();

const entity = new Entity();
entity.position = new ConstantPositionProperty(
Cartesian3.fromDegrees(0.0, 0.0),
);
expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10);
const view = new EntityView(entity, scene, undefined);
view.update(JulianDate.now(), bs1);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC1, 1e-10);

view.boundingSphere.center = bs2.center;
view.update(JulianDate.now());
expect(scene.camera.positionWC).toEqualEpsilon(positionWC2, 1e-10);
});

it("jumps to new bounding sphere", function () {
const bs1 = new BoundingSphere(new Cartesian3(1, 2, 3), 4);
scene.camera.viewBoundingSphere(bs1);
const positionWC1 = scene.camera.positionWC.clone();

const bs2 = new BoundingSphere(new Cartesian3(3, 4, 5), 4);
scene.camera.viewBoundingSphere(bs2);
const positionWC2 = scene.camera.positionWC.clone();

const entity = new Entity();
entity.position = new ConstantPositionProperty(
Cartesian3.fromDegrees(0.0, 0.0),
);
const view = new EntityView(entity, scene, undefined);
view.update(JulianDate.now(), bs1);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC1, 1e-10);

view.boundingSphere = bs2;
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is valuable to make sure changing EntityView.boundingSphere works but doesn't mimic the behavior of changing the actual bounding sphere it was set up with originally like calling getBoundingSphere does. Maybe another that replaces this line with bs1.center = new Cartesian3(3, 4, 5); would also be valuable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch @jjspace. Added new test. Should be ready for a final (hopefully 😅) review!

view.update(JulianDate.now());
expect(scene.camera.positionWC).toEqualEpsilon(positionWC2, 1e-10);
});

it("uses entity viewFrom if available and boundingsphere is supplied", function () {
Expand Down