cesiumjs

How to render only the parts of entities above the ground in Cesium?


When I add a cylindrical solid to the scene, I notice that the part below the ground is still visible. Is there any way to display only the portion above the ground?enter link description here enter image description here

const viewer = new Cesium.Viewer("cesiumContainer", { 
  infoBox: false 
});

const entity = viewer.entities.add({
  name: "entity",
  position: new Cesium.Cartesian3.fromDegrees(119.999, 30, 0),
  cylinder: {
    topRadius:4e6,
    bottomRadius:4e6,
    length:8e6,
    slices:100,
    material: Cesium.Color.RED.withAlpha(0.5),
  },
});

Solution

  • You should enable "Depth Test".

    So all you have to do is just to add one line.

    viewer.scene.globe.depthTestAgainstTerrain = true;