Hello everyone;
I’m using Google photorealistic and I want to get building heights. When I looked at Cesium’s documentation, I couldn’t find a feature, but when I did research, I learned that I could find it by raycasting with threeJS. Since the createGooglePhotorealistic3DTileset function was recently released, I could not find an article about raycasting. Can you help me, thank you in advance
If you are looking for a way to get the height value of geometry in the scene you can look at Scene.sampleHeight and Scene.sampleHeightMostDetailed. These should be able to give you the height value. You can see a example of sampleHeight in this sandcastle.
I’m also going to move this to the CesiumJS category since this is more related to the viewer and not hosting.
const cesiumViewer = new Cesium.Viewer('cesiumContainer', {
requestRenderMode: true,
geocoder: false,
navigationHelpButton: false,
animation: false,
timeline: false,
skyBox: false,
loadingOverlay: true,
fullscreenButton: false
});
var handler = new Cesium.ScreenSpaceEventHandler(cesiumViewer.scene.canvas);
var coordinatesDisplay = document.getElementById('coordinatesDisplay');
handler.setInputAction(function (movement) {
var mousePosition = movement.endPosition;
var scenePosition = cesiumViewer.scene.pickPosition(mousePosition);
if (scenePosition) {
var cartographic = Cesium.Cartographic.fromCartesian(scenePosition);
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
let height;
if (cesiumViewer.scene.sampleHeightSupported) {
height = cesiumViewer.scene.sampleHeight(cartographic, [cartographic.longitude, cartographic.latitude]);
}
if (Cesium.defined(height)) {
cartographic.height = height;
coordinatesDisplay.innerHTML = 'Mouse Coordinates: ' + 'x: ' + longitude.toFixed(4) + ' y: ' + latitude.toFixed(4) + ' z: ' + Math.abs(height).toFixed(2).toString();
} else {
cartographic.height = 0.0;
point.label.show = false;
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
<div id="coordinatesDisplay" style={{ backgroundColor: 'rgba(255, 255, 255, 1)', display: 'block', position: 'absolute', top: '85px', left: '180px', zIndex: '1000' }}></div>
Thank you