'cartographic is required' while trying to use heightReference with gltf model.

using this simple piece of code I am trying to clamp a gltf object to the ground. but it throws a developer error which I cannot figure out why.

I did managed to reduce the height by another piece of code I wrote in Java, but it seems more sensible to use heightReference option.

Thanks in advance!

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var scene = viewer.scene;

var gltfModel = {

//my gltf model

} ;

function createModel3(gltfModel) {

var model = new Cesium.Model({

gltf: gltfModel,

show: true,

heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,

scene: scene

});

scene.primitives.add(model);

}

createModel3(gltfModel);

Hello,

You need to supply a model matrix to position the model. Here is an example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;

var hpr = new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0);
var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 0.0);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr);
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : ‘…/…/SampleData/models/CesiumAir/Cesium_Air.glb’,
modelMatrix : modelMatrix,
minimumPixelSize : 128,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
scene: scene
}));

``

Best,

Hannah

Hi Hanna,

So you mean that CLAMP_TO_GROUND only works for a local coordinate system and basically removes z value from Cartesian3 point of origin. right?

Because I have my models in global geocentric system, in other words my origin point of the coordinate system is the center of the earth and if I use CLAMP_TO_GROUND my models end up somewhere on the equatorial plane! :))

Did I get it right??

Yes, from looking at the code it looks like the Model is getting the globe position from the model matrix, so if your model is already in the global coordinate system it won’t work because it will think the position is in the center of the earth.

-Hannah