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 scene.updateHeight #12134

Open
wants to merge 4 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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### 1.121 - 2024-09-01

##### Fixes :wrench:

- Fixed a performance issue where `Scene.updateHeight` would be called too many times.

#### @cesium/engine

##### Additions :tada:
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,7 @@ function processUpdateHeight(tileset, tile, frameState) {
Cartesian3.distance(position, boundingSphere.center) <=
boundingSphere.radius
) {
callbackData.invoked = true;
frameState.afterRender.push(() => {
// Callback can be removed before it actually invoked at the end of the frame
if (defined(callbackData.callback)) {
Expand Down
11 changes: 11 additions & 0 deletions packages/engine/Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -3746,7 +3746,17 @@ Scene.prototype.updateHeight = function (
Check.typeOf.func("callback", callback);
//>>includeEnd('debug');

let callbackWrapperCalledForFrameState = -1;
let removed = false;

const callbackWrapper = () => {
if (
removed ||
this.frameState.frameNumber <= callbackWrapperCalledForFrameState
) {
return;
}
callbackWrapperCalledForFrameState = this.frameState.frameNumber;
Cartographic.clone(cartographic, updateHeightScratchCartographic);

const height = this.getHeight(cartographic, heightReference);
Expand Down Expand Up @@ -3822,6 +3832,7 @@ Scene.prototype.updateHeight = function (
tilesetRemoveCallbacks = {};
removeAddedListener();
removeRemovedListener();
removed = true;
};

return removeCallback;
Expand Down
1 change: 1 addition & 0 deletions packages/engine/Specs/Scene/Model/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,7 @@ describe(
describe("height reference", function () {
beforeEach(() => {
scene.globe = new Globe();
scene.frameState.frameNumber = 0; // ensure we call updateHeight callbacks
});

afterEach(() => {
Expand Down