Skip to content

Commit

Permalink
Merge pull request #11655 from CesiumGS/z-exaggeration
Browse files Browse the repository at this point in the history
Vertical exaggeration for 3D Tiles
  • Loading branch information
ptrgags authored Dec 22, 2023
2 parents 22658a5 + 631641b commit 7ea4b84
Show file tree
Hide file tree
Showing 43 changed files with 1,495 additions and 182 deletions.
154 changes: 154 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles Vertical Exaggeration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<meta
name="description"
content="Apply Vertical Exaggeration to 3D Tiles"
/>
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases" />
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="module" src="../load-cesium-es6.js"></script>
</head>
<body
class="sandcastle-loading"
data-sandcastle-bucket="bucket-requirejs.html"
>
<style>
@import url(../templates/bucket.css);

#toolbar {
background: rgba(42, 42, 42, 0.8);
padding: 4px;
border-radius: 4px;
}

#toolbar input {
vertical-align: middle;
padding-top: 2px;
padding-bottom: 2px;
}

#toolbar .header {
font-weight: bold;
}
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay">
<h1>Loading...</h1>
</div>
<div id="toolbar">
<table>
<tbody>
<tr>
<td>Exaggeration</td>
<td>
<input
type="range"
min="1"
max="5"
step="0.01"
data-bind="value: exaggeration, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: exaggeration" />
</td>
</tr>
<tr>
<td>Relative Height</td>
<td>
<input
type="range"
min="-1000"
max="9000"
step="1"
data-bind="value: relativeHeight, valueUpdate: 'input'"
/>
<input type="text" size="5" data-bind="value: relativeHeight" />
</td>
</tr>
</tbody>
</table>
</div>
<script id="cesium_sandcastle_script">
window.startup = async function (Cesium) {
"use strict";
//Sandcastle_Begin
const viewer = new Cesium.Viewer("cesiumContainer", {
timeline: false,
animation: false,
sceneModePicker: false,
baseLayerPicker: false,
// The globe does not need to be displayed,
// since the Photorealistic 3D Tiles include terrain
globe: false,
});

const { scene, camera } = viewer;
scene.verticalExaggeration = 3.0;

camera.setView({
destination: new Cesium.Cartesian3(
-2710292.813384663,
-4360657.061518585,
3793571.786860543
),
orientation: new Cesium.HeadingPitchRoll(
5.794062761901799,
-0.30293409742984756,
0.0009187098191985044
),
});

// Enable rendering the sky
scene.skyAtmosphere.show = true;

// Add Photorealistic 3D Tiles
try {
const tileset = await Cesium.createGooglePhotorealistic3DTileset();
scene.primitives.add(tileset);
} catch (error) {
console.log(`Error loading Photorealistic 3D Tiles tileset.
${error}`);
}

const viewModel = {
exaggeration: scene.verticalExaggeration,
relativeHeight: scene.verticalExaggerationRelativeHeight,
};

function updateExaggeration() {
scene.verticalExaggeration = Number(viewModel.exaggeration);
scene.verticalExaggerationRelativeHeight = Number(
viewModel.relativeHeight
);
}

Cesium.knockout.track(viewModel);
const toolbar = document.getElementById("toolbar");
Cesium.knockout.applyBindings(viewModel, toolbar);
for (const name in viewModel) {
if (viewModel.hasOwnProperty(name)) {
Cesium.knockout
.getObservable(viewModel, name)
.subscribe(updateExaggeration);
}
}
//Sandcastle_End
Sandcastle.finishedLoading();
};
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
window.startup(Cesium).catch((error) => {
"use strict";
console.error(error);
});
}
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions Apps/Sandcastle/gallery/Terrain Exaggeration.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@

const scene = viewer.scene;
const globe = scene.globe;
globe.terrainExaggeration = 2.0;
globe.terrainExaggerationRelativeHeight = 2400.0;
scene.verticalExaggeration = 2.0;
scene.verticalExaggerationRelativeHeight = 2400.0;

scene.camera.setView({
destination: new Cesium.Cartesian3(
Expand Down Expand Up @@ -115,8 +115,8 @@

function updateMaterial() {
if (visualizeRelativeHeight) {
const height = globe.terrainExaggerationRelativeHeight;
const exaggeration = globe.terrainExaggeration;
const height = scene.verticalExaggerationRelativeHeight;
const exaggeration = scene.verticalExaggeration;
const alpha = Math.min(1.0, exaggeration * 0.25);
const layer = {
extendUpwards: true,
Expand Down Expand Up @@ -155,13 +155,13 @@
updateMaterial();

const viewModel = {
exaggeration: globe.terrainExaggeration,
relativeHeight: globe.terrainExaggerationRelativeHeight,
exaggeration: scene.verticalExaggeration,
relativeHeight: scene.verticalExaggerationRelativeHeight,
};

function updateExaggeration() {
globe.terrainExaggeration = Number(viewModel.exaggeration);
globe.terrainExaggerationRelativeHeight = Number(
scene.verticalExaggeration = Number(viewModel.exaggeration);
scene.verticalExaggerationRelativeHeight = Number(
viewModel.relativeHeight
);
updateMaterial();
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

#### @cesium/engine

##### Additions :tada:

- Vertical exaggeration can now be applied to a `Cesium3DTileset`. Exaggeration of `Terrain` and `Cesium3DTileset` can be controlled simultaneously via the new `Scene` properties `Scene.verticalExaggeration` and `Scene.verticalExaggerationRelativeHeight`. [#11655](https://github.com/CesiumGS/cesium/pull/11655)

##### Fixes :wrench:

- Changes the default `RequestScheduler.maximumRequestsPerServer` from 6 to 18. This should improve performance on HTTP/2 servers and above [#11627](https://github.com/CesiumGS/cesium/issues/11627)
- Corrected JSDoc and Typescript definitions that marked optional arguments as required in `ImageryProvider` constructor [#11625](https://github.com/CesiumGS/cesium/issues/11625)
- The `Quaternion.computeAxis` function created an axis that was `(0,0,0)` for the unit quaternion, and an axis that was `(NaN,NaN,NaN)` for the quaternion `(0,0,0,-1)` (which describes a rotation about 360 degrees). Now, it returns the x-axis `(1,0,0)` in both of these cases.

##### Deprecated :hourglass_flowing_sand:

- `Globe.terrainExaggeration` and `Globe.terrainExaggerationRelativeHeight` have been deprecated in CesiumJS 1.113. They will be removed in 1.116. Use `Scene.verticalExaggeration` and `Scene.verticalExaggerationRelativeHeight` instead. [#11655](https://github.com/CesiumGS/cesium/pull/11655)

### 1.112 - 2023-12-01

#### @cesium/engine
Expand Down
4 changes: 2 additions & 2 deletions Specs/createFrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function createFrameState(context, camera, frameNumber, time) {
camera.up
);

frameState.terrainExaggeration = 1.0;
frameState.terrainExaggerationRelativeHeight = 0.0;
frameState.verticalExaggeration = 1.0;
frameState.verticalExaggerationRelativeHeight = 0.0;

frameState.passes.render = true;
frameState.passes.pick = false;
Expand Down
45 changes: 45 additions & 0 deletions packages/engine/Source/Core/Ellipsoid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Cartesian2 from "./Cartesian2.js";
import Cartesian3 from "./Cartesian3.js";
import Cartographic from "./Cartographic.js";
import Check from "./Check.js";
Expand Down Expand Up @@ -694,6 +695,50 @@ Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function (
return result;
};

const scratchEndpoint = new Cartesian3();

/**
* Computes the ellipsoid curvatures at a given position on the surface.
*
* @param {Cartesian3} surfacePosition The position on the ellipsoid surface where curvatures will be calculated.
* @param {Cartesian2} [result] The cartesian to which to copy the result, or undefined to create and return a new instance.
* @returns {Cartesian2} The local curvature of the ellipsoid surface at the provided position, in east and north directions.
*
* @exception {DeveloperError} position is required.
*/
Ellipsoid.prototype.getLocalCurvature = function (surfacePosition, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("surfacePosition", surfacePosition);
//>>includeEnd('debug');

if (!defined(result)) {
result = new Cartesian2();
}

const primeVerticalEndpoint = this.getSurfaceNormalIntersectionWithZAxis(
surfacePosition,
0.0,
scratchEndpoint
);
const primeVerticalRadius = Cartesian3.distance(
surfacePosition,
primeVerticalEndpoint
);
// meridional radius = (1 - e^2) * primeVerticalRadius^3 / a^2
// where 1 - e^2 = b^2 / a^2,
// so meridional = b^2 * primeVerticalRadius^3 / a^4
// = (b * primeVerticalRadius / a^2)^2 * primeVertical
const radiusRatio =
(this.minimumRadius * primeVerticalRadius) / this.maximumRadius ** 2;
const meridionalRadius = primeVerticalRadius * radiusRatio ** 2;

return Cartesian2.fromElements(
1.0 / primeVerticalRadius,
1.0 / meridionalRadius,
result
);
};

const abscissas = [
0.14887433898163,
0.43339539412925,
Expand Down
6 changes: 2 additions & 4 deletions packages/engine/Source/Core/RectangleOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ function constructRectangle(geometry, computedOptions) {
}

function constructExtrudedRectangle(rectangleGeometry, computedOptions) {
const surfaceHeight = rectangleGeometry._surfaceHeight;
const extrudedHeight = rectangleGeometry._extrudedHeight;
const maxHeight = rectangleGeometry._surfaceHeight;
const minHeight = rectangleGeometry._extrudedHeight;
const ellipsoid = rectangleGeometry._ellipsoid;
const minHeight = extrudedHeight;
const maxHeight = surfaceHeight;
const geo = constructRectangle(rectangleGeometry, computedOptions);

const height = computedOptions.height;
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/Source/Core/TerrainEncoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import defaultValue from "./defaultValue.js";
import defined from "./defined.js";
import CesiumMath from "./Math.js";
import Matrix4 from "./Matrix4.js";
import TerrainExaggeration from "./TerrainExaggeration.js";
import VerticalExaggeration from "./VerticalExaggeration.js";
import TerrainQuantization from "./TerrainQuantization.js";

const cartesian3Scratch = new Cartesian3();
Expand Down Expand Up @@ -386,7 +386,7 @@ TerrainEncoding.prototype.getExaggeratedPosition = function (
);
const rawHeight = this.decodeHeight(buffer, index);
const heightDifference =
TerrainExaggeration.getHeight(
VerticalExaggeration.getHeight(
rawHeight,
exaggeration,
exaggerationRelativeHeight
Expand Down
49 changes: 0 additions & 49 deletions packages/engine/Source/Core/TerrainExaggeration.js

This file was deleted.

Loading

0 comments on commit 7ea4b84

Please sign in to comment.