Skip to content

Commit

Permalink
10957 zoom to entities without globe fix (#11226)
Browse files Browse the repository at this point in the history
* fixed modelvisualizer.js

* updated contributors file

* added test case and refactored based on feedback

* updated CHANGES.md

* updated test case

* updated test case

* updated test case

* updated test case

* updated test case

* updated test case

* updated test case

* updated test case

* updated test case

* refactored test case

* Move createViewer, move zoomTo test

* defined

---------

Co-authored-by: Gabby Getz <[email protected]>
  • Loading branch information
fullstacc and ggetz authored Apr 18, 2023
1 parent 8c82397 commit 002002c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed an issue when zooming in an orthographic frustum. [#11206](https://github.com/CesiumGS/cesium/pull/11206)
- Fixed atmosphere rendering performance issue. [10510](https://github.com/CesiumGS/cesium/issues/10510)
- Fixed model rendering when emissiveTexture is defined and emissiveFactor is not. [#11215](https://github.com/CesiumGS/cesium/pull/11215)
- Fixed crashing when zooming to an entity without globe present. [#10957](https://github.com/CesiumGS/cesium/pull/11226)

#### @cesium/widgets

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Michael Cabana](https://github.com/mikecabana)
- [Joseph Stanton](https://github.com/romejoe)
- [Zehua Hu](https://github.com/lanvada)
- [Jason Summercamp](https://github.com/fullstacc)
8 changes: 5 additions & 3 deletions packages/engine/Source/DataSources/ModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function ModelVisualizer(scene, entityCollection) {
this._entityCollection = entityCollection;
this._modelHash = {};
this._entitiesToVisualize = new AssociativeArray();

this._onCollectionChanged(entityCollection, entityCollection.values, [], []);
}

Expand Down Expand Up @@ -444,11 +445,12 @@ ModelVisualizer.prototype.getBoundingSphere = function (entity, result) {

const scene = this._scene;
const globe = scene.globe;
const ellipsoid = globe.ellipsoid;
const terrainProvider = globe.terrainProvider;

// cannot access a terrain provider if there is no globe; formally set to undefined
const terrainProvider = defined(globe) ? globe.terrainProvider : undefined;
const hasHeightReference = model.heightReference !== HeightReference.NONE;
if (hasHeightReference) {
if (defined(globe) && hasHeightReference) {
const ellipsoid = globe.ellipsoid;
// We cannot query the availability of the terrain provider till its ready, so the
// bounding sphere state will remain pending till the terrain provider is ready.
// ready is deprecated. This is here for backwards compatibility
Expand Down
43 changes: 39 additions & 4 deletions packages/engine/Specs/DataSources/ModelVisualizerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,20 @@ describe(
let scene;
let entityCollection;
let visualizer;
let originalTerrainProvider;

beforeAll(function () {
scene = createScene();
scene.globe = new Globe();
originalTerrainProvider = scene.globe.terrainProvider;
});

beforeEach(function () {
scene.globe = new Globe();
entityCollection = new EntityCollection();
visualizer = new ModelVisualizer(scene, entityCollection);
});

afterEach(function () {
visualizer = visualizer && visualizer.destroy();
entityCollection.removeAll();
scene.globe.terrainProvider = originalTerrainProvider;
});

afterAll(function () {
Expand Down Expand Up @@ -648,6 +645,44 @@ describe(
});
});

it("computes bounding sphere where globe is undefined", async function () {
scene.globe = undefined;

const time = JulianDate.now();
const testObject = entityCollection.getOrCreateEntity("test");
const model = new ModelGraphics();
testObject.model = model;

testObject.position = new ConstantProperty(
new Cartesian3(5678, 1234, 1101112)
);
model.uri = new ConstantProperty(boxUrl);
visualizer.update(time);

let primitive;
await pollToPromise(function () {
primitive = scene.primitives.get(0);
return defined(primitive);
});

const result = new BoundingSphere();
let state = visualizer.getBoundingSphere(testObject, result);
expect(state).toBe(BoundingSphereState.PENDING);

await pollToPromise(function () {
scene.render();
visualizer.update(time);
state = visualizer.getBoundingSphere(testObject, result);
return state !== BoundingSphereState.PENDING;
});
expect(state).toBe(BoundingSphereState.DONE);
const expected = BoundingSphere.clone(
primitive.boundingSphere,
new BoundingSphere()
);
expect(result).toEqual(expected);
});

it("fails bounding sphere for entity without ModelGraphics", function () {
const testObject = entityCollection.getOrCreateEntity("test");
visualizer.update(JulianDate.now());
Expand Down
30 changes: 29 additions & 1 deletion packages/widgets/Specs/Viewer/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
Timeline,
} from "../../index.js";

import createViewer from "../../../../Specs/createViewer.js";
import createViewer from "../createViewer.js";
import DomEventSimulator from "../../../../Specs/DomEventSimulator.js";
import MockDataSource from "../../../../Specs/MockDataSource.js";
import pollToPromise from "../../../../Specs/pollToPromise.js";
Expand Down Expand Up @@ -1551,6 +1551,34 @@ describe(
});
});

it("zoomTo zooms to entity when globe is disabled", async function () {
// Create viewer with globe disabled
const viewer = createViewer(container, {
globe: false,
infoBox: false,
selectionIndicator: false,
shadows: true,
shouldAnimate: true,
});

// Create position variable
const position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 1000.0);

// Add entity to viewer
const entity = viewer.entities.add({
position: position,
model: {
uri: "../SampleData/models/CesiumAir/Cesium_Air.glb",
},
});

await viewer.zoomTo(entity);

// Verify that no errors occurred
expect(viewer.scene).toBeDefined();
expect(viewer.scene.errorEvent).toBeUndefined();
});

it("flyTo throws if target is not defined", function () {
viewer = createViewer(container);

Expand Down
2 changes: 1 addition & 1 deletion packages/widgets/Specs/Viewer/viewerDragDropMixinSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defined, TimeInterval } from "@cesium/engine";

import { viewerDragDropMixin } from "../../index.js";

import createViewer from "../../../../Specs/createViewer.js";
import createViewer from "../createViewer.js";
import DomEventSimulator from "../../../../Specs/DomEventSimulator.js";
import pollToPromise from "../../../../Specs/pollToPromise.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
PerformanceWatchdog,
viewerPerformanceWatchdogMixin,
} from "../../index.js";
import createViewer from "../../../../Specs/createViewer.js";
import createViewer from "../createViewer.js";

describe(
"Widgets/Viewer/viewerPerformanceWatchdogMixin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defaultValue } from "@cesium/engine";
import { Viewer } from "@cesium/widgets";
import { Viewer } from "../index.js";

import getWebGLStub from "./getWebGLStub.js";
import getWebGLStub from "../../../Specs/getWebGLStub.js";

function createViewer(container, options) {
options = defaultValue(options, {});
Expand Down

0 comments on commit 002002c

Please sign in to comment.