How to use HeightReference with Primitive

As the title,I wanna use polygon primitive with terrain,but there is no HeightReference option.

hi if you want to use clampToGround option use viewer.scene.groundPrimitives,
or use geometryInstance like this

 viewer.scene.primitives.add(new Cesium.Primitive({
                geometryInstances : new Cesium.GeometryInstance({
                    geometry : new Cesium.PolygonGeometry({
                        polygonHierarchy : new Cesium.PolygonHierarchy(
                        extrudedHeight : yourHeight,
                        closeTop : true,
                        closeBottom : true,
                        vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
                    id : yourId
                appearance : yourAppearance,

I want to correct his height on the terrain, for example, I have a set of polygon coordinates representing buildings, and I want to extruded them to make them look like buildings. I want him to adjust his height based on the terrain to ensure that he doesn’t end up inside mountains or floating above caves.
Thank you very much!

about extrudedHeight…
use this code

async getTerrainHeight(lon,lat) {
let cartoLoc = Cesium.Cartographic.fromDegrees(lon,lat);
let terrHgt = 0;
try {
const updatedLocation = await Cesium.sampleTerrainMostDetailed(viewer.terrainProvider,
terrHgt = updatedLocation[0].height;
return terrHgt;
} catch (error) {
console.error(“Error sampling terrain:”, error);
return 0;

1 Like