Skip to content

Commit

Permalink
fix: fixes #12465
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome.fayot committed Feb 7, 2025
1 parent 82e59ed commit 29090b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
13 changes: 1 addition & 12 deletions packages/engine/Source/DataSources/EntityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function updateTransform(
ellipsoid,
) {
const mode = that.scene.mode;
let cartesian = positionProperty.getValue(time, that._lastCartesian);
const cartesian = positionProperty.getValue(time, that._lastCartesian);
if (defined(cartesian)) {
let hasBasis = false;
let invertVelocity = false;
Expand Down Expand Up @@ -216,10 +216,6 @@ function updateTransform(
}
}

if (defined(that.boundingSphere)) {
cartesian = that.boundingSphere.center;
}

let position;
let direction;
let up;
Expand Down Expand Up @@ -346,12 +342,6 @@ function EntityView(entity, scene, ellipsoid) {
*/
this.ellipsoid = defaultValue(ellipsoid, Ellipsoid.default);

/**
* The bounding sphere of the object.
* @type {BoundingSphere}
*/
this.boundingSphere = undefined;

// Shadow copies of the objects so we can detect changes.
this._lastEntity = undefined;
this._mode = undefined;
Expand Down Expand Up @@ -445,7 +435,6 @@ EntityView.prototype.update = function (time, boundingSphere) {
}

camera.viewBoundingSphere(boundingSphere, scratchHeadingPitchRange);
this.boundingSphere = boundingSphere;
updateLookAt = false;
saveCamera = false;
} else if (
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,
boundingSphereScratch,
);
if (trackedState === BoundingSphereState.DONE) {
entityView.update(time, entityView.boundingSphere);
entityView.update(time, boundingSphereScratch);
}
}
};
Expand Down
39 changes: 13 additions & 26 deletions packages/engine/Specs/DataSources/EntityViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,30 @@ 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);
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),
);
expect(view.scene.camera.position).toEqualEpsilon(sampleOffset, 1e-10);
view.update(JulianDate.now(), bs);
expect(scene.camera.positionWC).toEqualEpsilon(positionWC, 1e-10);
});

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

0 comments on commit 29090b3

Please sign in to comment.