Skip to content

Commit

Permalink
Exaggerate 3D Tiles bounding boxes and spheres
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeshurun Hembd committed Nov 29, 2023
1 parent fa1d943 commit ce217d4
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions packages/engine/Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,10 @@ function createSphere(sphere, transform, result) {
return new TileBoundingSphere(center, radius);
}

const scratchBoundingSphere = new BoundingSphere();
const scratchExaggeratedBox = new Array(OrientedBoundingBox.packedLength);
const scratchExaggeratedSphere = new Array(BoundingSphere.packedLength);

/**
* Create a bounding volume from the tile's bounding volume header.
*
Expand Down Expand Up @@ -1793,7 +1797,29 @@ Cesium3DTile.prototype.createBoundingVolume = function (

const { box, region, sphere } = boundingVolumeHeader;
if (defined(box)) {
return createBox(box, transform, result);
const exaggeratedCorners = OrientedBoundingBox.unpack(
box,
0,
scratchOrientedBoundingBox
)
.computeCorners()
.map((corner) =>
VerticalExaggeration.getPosition(
corner,
Ellipsoid.WGS84,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
corner
)
);
const exaggeratedBox = OrientedBoundingBox.pack(
OrientedBoundingBox.fromPoints(
exaggeratedCorners,
scratchOrientedBoundingBox
),
scratchExaggeratedBox
);
return createBox(exaggeratedBox, transform, result);
}
if (defined(region)) {
const exaggeratedRegion = region.slice();
Expand All @@ -1815,7 +1841,24 @@ Cesium3DTile.prototype.createBoundingVolume = function (
);
}
if (defined(sphere)) {
return createSphere(sphere, transform, result);
const boundingSphere = BoundingSphere.unpack(
sphere,
0,
scratchBoundingSphere
);
boundingSphere.center = VerticalExaggeration.getPosition(
boundingSphere.center,
Ellipsoid.WGS84,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
boundingSphere.center
);
boundingSphere.radius *= this._verticalExaggeration;
const exaggeratedSphere = BoundingSphere.pack(
boundingSphere,
scratchExaggeratedSphere
);
return createSphere(exaggeratedSphere, transform, result);
}
throw new RuntimeError(
"boundingVolume must contain a sphere, region, or box"
Expand Down

0 comments on commit ce217d4

Please sign in to comment.