How achieve HeightReference effect with primitives

If is possible, how I can achieve effect like in that demo:

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Geometry%20Height%20Reference.html

but using primitives (instead of entities).

I want my primitives (polygons for example) be clamped to ground (but also extruded).

When I make my primitives as groundprimitives they lose their height.

The equivalent of a clamped polygon entity is a GroundPrimitive polygon. So you should be able to construct your geometry (with extrude etc) and just create it as a GroundPrimitive and it should be clamped. See:

https://cesiumjs.org/Cesium/Build/Documentation/GroundPrimitive.html?classFilter=GroundPr

You may find some of the “development” Sandcastle examples helpful, like this GroundPrimitive one:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Apps/Sandcastle/gallery/development/Ground%20Primitive.html