Jitter when clamping to ground
Noticed while reviewing #3903. Here's a sandcastle example which creates a circular flight with altitude of 0 and then clamps to terrain. There is really jerky camera or entity motion as it animates.
var viewer = new Cesium.Viewer('cesiumContainer', {
shouldAnimate: true,
terrainProviderViewModels : [], //Disable terrain changing
infoBox : false //Disable InfoBox widget
});
//Enable lighting based on sun/moon positions
viewer.terrainProvider = Cesium.createWorldTerrain();
//Use STK World Terrain
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url : 'https://assets.agi.com/stk-terrain/world',
requestWaterMask : true,
requestVertexNormals : true
});
//Enable depth testing so things behind the terrain disappear.
viewer.scene.globe.depthTestAgainstTerrain = true;
//Set the random number seed for consistent results.
Cesium.Math.setRandomNumberSeed(3);
//Set bounds of our simulation time
var start = Cesium.JulianDate.fromDate(new Date(2015, 2, 25, 16));
var stop = Cesium.JulianDate.addSeconds(start, 360, new Cesium.JulianDate());
//Make sure viewer is at the desired time.
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();
viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; //Loop at the end
viewer.clock.multiplier = 1;
//Set timeline to simulation bounds
viewer.timeline.zoomTo(start, stop);
//Generate a random circular pattern with varying heights.
function computeCirclularFlight(lon, lat, radius) {
var property = new Cesium.SampledPositionProperty();
for (var i = 0; i <= 360; i += 45) {
var radians = Cesium.Math.toRadians(i);
var time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());
var position = Cesium.Cartesian3.fromDegrees(lon + (radius * 1.5 * Math.cos(radians)), lat + (radius * Math.sin(radians)), 0);
property.addSample(time, position);
//Also create a point for each sample we generate.
viewer.entities.add({
position : position,
point : {
pixelSize : 8,
color : Cesium.Color.TRANSPARENT,
outlineColor : Cesium.Color.YELLOW,
outlineWidth : 3
}
});
}
return property;
}
//Compute the entity position property.
var position = computeCirclularFlight(-112.110693, 36.0994841, 0.03);
//Actually create the entity
var entity = viewer.entities.add({
//Set the entity availability to the same interval as the simulation time.
availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start : start,
stop : stop
})]),
//Use our computed positions
position : position,
//Automatically compute orientation based on position movement.
orientation : new Cesium.VelocityOrientationProperty(position),
//Load the Cesium plane model to represent the entity
model : {
uri : '../../SampleData/models/CesiumAir/Cesium_Air.gltf',
minimumPixelSize : 64,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
}
});
viewer.trackedEntity = entity;
Looks like this happens on the first terrain height request of a new tile. To see it more clearly:
- Zoom out a bit so lower LOD tiles are loaded
- Make the animation speed something like 0.5x
- Use the Cesium inspector to turn on
Terrain -> Show tile coordinates
viewer.extend(Cesium.viewerCesiumInspectorMixin);
Looks like this happens on the first terrain height request of a new tile. To see it more clearly:
- Zoom out a bit so lower LOD tiles are loaded
- Make the animation speed something like 0.5x
- Use the Cesium inspector to turn on
Terrain -> Show tile coordinatesviewer.extend(Cesium.viewerCesiumInspectorMixin);
The amount of jitter seems to be reduced if "Suspend LOD update" is checked. However, there's still some larger jitter at the end of this clip:

It looks like it's the camera that jitters rather than the model, as the motion appears smooth when the camera isn't tracking the entity.
Looks like this is fixed for me in recent versions of Cesium (1.129)