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

Billboard clamping #12482

Open
wants to merge 7 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
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 error when there are duplicated points in polygon/polyline geometries with `ArcType.RHUMB` [#12460](https://github.com/CesiumGS/cesium/pull/12460)
- Fixed ground atmosphere shaders in 3D orthographic mode [#12484](https://github.com/CesiumGS/cesium/pull/12484)
- Fixed zoom in 3D orthographic mode [#12483](https://github.com/CesiumGS/cesium/pull/12483)
- Fixed issue with billboards not clamping properly when nested inside a PrimitiveCollection [#12482](https://github.com/CesiumGS/cesium/pull/12482)

## 1.126 - 2025-02-03

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Parth Petkar](https://github.com/parthpetkar)
- [Yutao Liu](https://github.com/liuyutao)
- [Andrew Dassonville](https://github.com/andrewda)
- [Cody Butler](https://github.com/CodyBu)
54 changes: 39 additions & 15 deletions packages/engine/Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -3805,6 +3805,38 @@ function getGlobeHeight(scene) {
return scene.getHeight(cartographic);
}

function getMaxPrimitiveHeight(primitive, cartographic, scene) {
let maxHeight = Number.NEGATIVE_INFINITY;

if (defined(primitive.length)) {
// If it's a PrimitiveCollection, iterate through its children
const length = primitive.length;
for (let i = 0; i < length; ++i) {
const subPrimitive = primitive.get(i);
const subHeight = getMaxPrimitiveHeight(
subPrimitive,
cartographic,
scene,
);
if (defined(subHeight) && subHeight > maxHeight) {
maxHeight = subHeight;
}
}
} else if (
primitive.isCesium3DTileset &&
primitive.show &&
primitive.enableCollision
) {
// If it's an individual primitive, check its height
const result = primitive.getHeight(cartographic, scene);
if (defined(result) && result > maxHeight) {
return result;
}
}

return maxHeight;
}

/**
* Gets the height of the loaded surface at the cartographic position.
* @param {Cartographic} cartographic The cartographic position.
Expand All @@ -3831,21 +3863,13 @@ Scene.prototype.getHeight = function (cartographic, heightReference) {
let maxHeight = Number.NEGATIVE_INFINITY;

if (!ignore3dTiles) {
const length = this.primitives.length;
for (let i = 0; i < length; ++i) {
const primitive = this.primitives.get(i);
if (
!primitive.isCesium3DTileset ||
!primitive.show ||
!primitive.enableCollision
) {
continue;
}

const result = primitive.getHeight(cartographic, this);
if (defined(result) && result > maxHeight) {
maxHeight = result;
}
const maxPrimitiveHeight = getMaxPrimitiveHeight(
this.primitives,
cartographic,
this,
);
if (defined(maxPrimitiveHeight) && maxPrimitiveHeight > maxHeight) {
maxHeight = maxPrimitiveHeight;
}
}

Expand Down
32 changes: 32 additions & 0 deletions packages/engine/Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
PerInstanceColorAppearance,
ColorGeometryInstanceAttribute,
Resource,
HeightReference,
} from "../../index.js";

import createCanvas from "../../../../Specs/createCanvas.js";
Expand Down Expand Up @@ -2944,6 +2945,37 @@ describe(

expect(mockTileset.updateHeight).toHaveBeenCalled();
});

it("adds nested primitive collection to scene", function () {
const expectedHeight = 100;

const mockTileset = new TilesetMockPrimitive();
mockTileset.enableCollision = true;
mockTileset.getHeight = function () {
return expectedHeight;
};
mockTileset.heightReference = HeightReference.CLAMP_TO_GROUND;

const mockTileset2 = new TilesetMockPrimitive();
mockTileset2.enableCollision = true;
mockTileset2.getHeight = function () {
return 80;
};
mockTileset2.heightReference = HeightReference.CLAMP_TO_GROUND;

const nestedCollection = new PrimitiveCollection();
nestedCollection.add(mockTileset);
nestedCollection.add(mockTileset2);

scene.primitives.add(nestedCollection);

const actualHeight = scene.getHeight(
scene.camera.positionCartographic,
HeightReference.CLAMP_TO_GROUND,
);

expect(actualHeight).toEqual(expectedHeight);
});
},

describe("pickMetadata", () => {
Expand Down
Loading