Skip to content

Commit fdc2cb2

Browse files
authored
Merge pull request #12905 from CesiumGS/label-clamping-performance
Reduces redundant clamping on labels
2 parents edccce4 + 7e376b6 commit fdc2cb2

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Improved performance and reduced memory usage of `Event` class. [#12896](https://github.com/CesiumGS/cesium/pull/12896)
1313
- Fixes vertical misalignment of glyphs in labels with small fonts [#8474](https://github.com/CesiumGS/cesium/issues/8474)
1414
- Prevent runtime errors for certain forms of invalid PNTS files [#12872](https://github.com/CesiumGS/cesium/issues/12872)
15+
- Improved performance of clamped labels. [#12905](https://github.com/CesiumGS/cesium/pull/12905)
1516
- Fixes issue where multiple instances of a Gaussian splat tileset would transform tile positions incorrectly and render out of position. [#12795](https://github.com/CesiumGS/cesium/issues/12795)
1617

1718
#### Additions :tada:

packages/engine/Source/Scene/Billboard.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ function Billboard(options, billboardCollection) {
227227
this._updateClamping();
228228

229229
this._splitDirection = options.splitDirection ?? SplitDirection.NONE;
230+
// Primarily used by labels to indicate that the position is derived from the parent.
231+
// and expensive operations like clamping can be skipped.
232+
this._positionFromParent = false;
230233
}
231234

232235
const SHOW_INDEX = (Billboard.SHOW_INDEX = 0);
@@ -1147,6 +1150,7 @@ Billboard._updateClamping = function (collection, owner) {
11471150

11481151
if (
11491152
owner._heightReference === HeightReference.NONE ||
1153+
owner._positionFromParent ||
11501154
!defined(owner._position)
11511155
) {
11521156
return;

packages/engine/Source/Scene/LabelCollection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ function rebindAllGlyphs(labelCollection, label) {
294294
});
295295
billboard._labelDimensions = new Cartesian2();
296296
billboard._labelTranslate = new Cartesian2();
297+
billboard._positionFromParent = true;
297298
}
298299
glyph.billboard = billboard;
299300
}

packages/engine/Specs/Scene/LabelCollectionSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,7 +2446,6 @@ describe("Scene/LabelCollection", function () {
24462446
});
24472447

24482448
expect(l._clampedPosition).toBeDefined();
2449-
expect(l._glyphs[0].billboard._clampedPosition).toBeDefined();
24502449

24512450
l.heightReference = HeightReference.NONE;
24522451
expect(l._clampedPosition).toBeUndefined();
@@ -2458,14 +2457,15 @@ describe("Scene/LabelCollection", function () {
24582457
heightReference: HeightReference.CLAMP_TO_GROUND,
24592458
text: "t",
24602459
position: Cartesian3.fromDegrees(-72.0, 40.0),
2460+
showBackground: true,
24612461
});
24622462

24632463
await pollToPromise(() => {
24642464
scene.renderForSpecs();
24652465
return labelsWithHeight.ready;
24662466
});
24672467

2468-
const billboard = l._glyphs[0].billboard;
2468+
const billboard = l._backgroundBillboard;
24692469
expect(billboard._removeCallbackFunc).toBeDefined();
24702470
const spy = spyOn(billboard, "_removeCallbackFunc");
24712471
labelsWithHeight.remove(l);

0 commit comments

Comments
 (0)