Skip to content

Commit

Permalink
Merge pull request #11581 from CesiumGS/tileset-get-height
Browse files Browse the repository at this point in the history
3D Tileset `getHeight`, and keeping camera above 3D Tiles
  • Loading branch information
jjhembd authored Jan 10, 2024
2 parents 0b9d7c4 + 41daf91 commit 2602d03
Show file tree
Hide file tree
Showing 25 changed files with 1,606 additions and 43 deletions.
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/3D Tiles Interior.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
const viewer = new Cesium.Viewer("cesiumContainer");

try {
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(125737);
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(125737, {
disableCollision: true,
});
viewer.scene.primitives.add(tileset);
} catch (error) {
console.log(`Error loading tileset: ${error}`);
Expand Down
146 changes: 146 additions & 0 deletions Apps/Sandcastle/gallery/development/3D Tiles Picking.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<!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="A sample BIM dataset rendered with 3D Tiles."
/>
<meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles" />
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script
type="text/javascript"
src="../../../Build/CesiumUnminified/Cesium.js"
nomodule
></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);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></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,
baseLayerPicker: false,
globe: false,
});
const scene = viewer.scene;

let tileset;
const options = [
{
text: "Google P3DT",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.createGooglePhotorealistic3DTileset();
scene.primitives.add(tileset);
} catch (error) {
console.log(error);
}
},
},
{
text: "Maxar OWT WFF 1.2",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.Cesium3DTileset.fromIonAssetId(691510, {
maximumScreenSpaceError: 4,
});
scene.primitives.add(tileset);
} catch (error) {
console.log(error);
}
},
},
{
text: "Bentley BIM Model",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402);
scene.primitives.add(tileset);
viewer.zoomTo(tileset);
} catch (error) {
console.log(error);
}
},
},
{
text: "Instanced",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.Cesium3DTileset.fromUrl(
"../../SampleData/Cesium3DTiles/Instanced/InstancedWithBatchTable/tileset.json"
);
scene.primitives.add(tileset);
viewer.zoomTo(tileset);
} catch (error) {
console.log(error);
}
},
},
];

Sandcastle.addDefaultToolbarMenu(options);

const scratchCartesian = new Cesium.Cartesian3();
const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (movement) {
const pickedPositionResult = scene.pickPosition(movement.position);
if (Cesium.defined(pickedPositionResult)) {
viewer.entities.add({
position: pickedPositionResult,
point: {
pixelSize: 10,
color: Cesium.Color.RED,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});
}

const ray = scene.camera.getPickRay(movement.position);
const picked = tileset.pick(ray, scene.frameState, scratchCartesian);

if (Cesium.defined(picked)) {
viewer.entities.add({
position: picked,
point: {
pixelSize: 10,
color: Cesium.Color.YELLOW,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); //Sandcastle_End
};
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
window.startup(Cesium).catch((error) => {
"use strict";
console.error(error);
});
Sandcastle.finishedLoading();
}
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

##### Breaking Changes :mega:

- By default, the screen space camera controller will no longer go inside or under instances of `Cesium3DTileset`. [#11581](https://github.com/CesiumGS/cesium/pull/11581)
- This behavior can be disabled by setting `Cesium3DTileset.disableCollision` to true.
- This feature is enabled by default only for WebGL 2 and above, but can be enabled for WebGL 1 by setting the `enablePick` option to true when creating the `Cesium3DTileset`.

##### Additions :tada:

- Added `Cesium3DTileset.getHeight` to sample height values of the loaded tiles. If using WebGL 1, the `enablePick` option must be set to true to use this function. [#11581](https://github.com/CesiumGS/cesium/pull/11581)
- Added `Cesium3DTileset.disableCollision` to allow the camera from to go inside or below a 3D tileset, for instance, to be used with 3D Tiles interiors. [#11581](https://github.com/CesiumGS/cesium/pull/11581)
- The `Cesium3DTileset.dynamicScreenSpaceError` optimization is now enabled by default, as this improves performance for street-level horizon views. Furthermore, the default settings of this feature were tuned for improved performance. `Cesium3DTileset.dynamicScreenSpaceErrorDensity` was changed from 0.00278 to 0.0002. `Cesium3DTileset.dynamicScreenSpaceErrorFactor` was changed from 4 to 24. [#11718](https://github.com/CesiumGS/cesium/pull/11718)

##### Fixes :wrench:
Expand Down
39 changes: 24 additions & 15 deletions packages/engine/Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,21 +1045,30 @@ Transforms.basisTo2D = function (projection, matrix, result) {
const rtcCenter = Matrix4.getTranslation(matrix, scratchCenter);
const ellipsoid = projection.ellipsoid;

// Get the 2D Center
const cartographic = ellipsoid.cartesianToCartographic(
rtcCenter,
scratchCartographic
);
const projectedPosition = projection.project(
cartographic,
scratchCartesian3Projection
);
Cartesian3.fromElements(
projectedPosition.z,
projectedPosition.x,
projectedPosition.y,
projectedPosition
);
let projectedPosition;
if (Cartesian3.equals(rtcCenter, Cartesian3.ZERO)) {
projectedPosition = Cartesian3.clone(
Cartesian3.ZERO,
scratchCartesian3Projection
);
} else {
// Get the 2D Center
const cartographic = ellipsoid.cartesianToCartographic(
rtcCenter,
scratchCartographic
);

projectedPosition = projection.project(
cartographic,
scratchCartesian3Projection
);
Cartesian3.fromElements(
projectedPosition.z,
projectedPosition.x,
projectedPosition.y,
projectedPosition
);
}

// Assuming the instance are positioned in WGS84, invert the WGS84 transform to get the local transform and then convert to 2D
const fromENU = Transforms.eastNorthUpToFixedFrame(
Expand Down
14 changes: 14 additions & 0 deletions packages/engine/Source/Scene/Cesium3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@ Cesium3DTileContent.prototype.update = function (tileset, frameState) {
DeveloperError.throwInstantiationError();
};

/**
* Find an intersection between a ray and the tile content surface that was rendered. The ray must be given in world coordinates.
*
* @param {Ray} ray The ray to test for intersection.
* @param {FrameState} frameState The frame state.
* @param {Cartesian3|undefined} [result] The intersection or <code>undefined</code> if none was found.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
*
* @private
*/
Cesium3DTileContent.prototype.pick = function (ray, frameState, result) {
DeveloperError.throwInstantiationError();
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
Expand Down
Loading

0 comments on commit 2602d03

Please sign in to comment.