Atlaslog
Atlaslog / Field Notes / 3D & Cesium
Field note · 3D & Cesium

Model floats above or sinks into the terrain

Quick answer

The same model.glb sits correctly without terrain but hovers about 8 metres above once world terrain is enabled, and in mountains half of it is buried. Three factors stack: the model origin is not at its base, the height is hardcoded to 0, and terrain exaggeration scales the ground.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: CesiumJS 1.121
Symptom
Checklist
  1. After load, read model.boundingSphere and subtract its centre from the entity position to get the origin offset.
  2. Do not sample height right after constructing the Viewer, because terrain tiles have not arrived yet.
  3. Use sampleTerrainMostDetailed or wait for globe.tilesLoaded to obtain the real ground height.
  4. Check terrainExaggeration, since the same coordinate sits differently under two terrain settings.
  5. Check whether heightReference is CLAMP_TO_GROUND and whether the model origin is at its base.
Fix

Either set heightReference to Cesium.HeightReference.CLAMP_TO_GROUND on the model, or compute placeHeight as groundHeight minus bottomOffset, for example ground 45 m with a bottom offset of -12.4 m, and place it through Cesium.Transforms.eastNorthUpToFixedFrame. Reset terrainExaggeration to 1.0 while calibrating.

Code
var entity = viewer.entities.add({
  position: Cesium.Cartesian3.fromDegrees(116.391, 39.907, 0),
  model: { uri: '/models/tower.glb' }
});

viewer.scene.globe.tilesLoaded = true;
entity.model.readyPromise.then(function (model) {
  var bs = model.boundingSphere;
  console.log('包围球半径', bs.radius);
  console.log('中心相对原点', Cesium.Cartesian3.subtract(
    bs.center, entity.position.getValue(viewer.clock.currentTime), new Cesium.Cartesian3()
  ));
});
var terrain = await Cesium.createWorldTerrainAsync();
var carto = Cesium.Cartographic.fromDegrees(116.391, 39.907);

var samples = await Cesium.sampleTerrainMostDetailed(terrain, [carto]);
console.log('地面高程', samples[0].height);
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Model floats above or sinks into the terrain. https://www.jingweizhi.com/en/cookbook/cesium-model-float-sink.html (accessed 2026-11-03).