hello,
i am trying adding a model(ground vehicle and aircraft) with enabled terrain.
but the problem is models does not shown above the terrain.
here is my code...please help.
Thanks
var terrainProvider = new Cesium.CesiumTerrainProvider({
url : ‘https://assets.agi.com/stk-terrain/world’
});
var positions = [
Cesium.Cartographic.fromDegrees(86.925145, 27.988257),
Cesium.Cartographic.fromDegrees(87.0, 28.0)
];
var promise = Cesium.sampleTerrain(terrainProvider, 11, positions);
Cesium.when(promise, function(updatedPositions) {
// positions[0].height and positions[1].height have been updated.
// updatedPositions is just a reference to positions.
});
viewer.terrainProvider = terrainProvider;
//Provide terrain.
viewer.scene.globe.depthTestAgainstTerrain = true;
var scene = viewer.scene;
var clock = viewer.clock;
var lon = 79.06666666;
var lat = 30.73388888;
function kedarnath() {
Sandcastle.declare(kedarnath);
viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees(lon, lat, 5000.0)
});
}
Sandcastle.addToolbarMenu([{
text : 'Fly Locations'
}, {
text : 'Kedarnath',
onselect : function() {
kedarnath();
Sandcastle.highlight(kedarnath);
}
}]);
Sandcastle.reset = function() {
viewer.entities.removeAll();
scene.primitives.removeAll();
scene.tweens.removeAll();
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
clock.multiplier = 1.0;
scene.globe.enableLighting = false;
};
scene.morphComplete.addEventListener(function() {
Sandcastle.reset();
});
function createModel(url, height) {
viewer.entities.removeAll();
// var heading = Cesium.Math.toRadians(135);
//var pitch = 0;
//var roll = 0;
//var orientation = Cesium.Transforms.headingPitchRollQuaternion( heading, pitch, roll);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(lon, lat, height));
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : url,
modelMatrix : modelMatrix,
minimumPixelSize : 128,
maximumScale : 20000,
model : {
uri : url,
minimumPixelSize : 128,
maximumScale : 20000
}
}));
Cesium.when(model.readyPromise).then(function(model) {
model.activeAnimations.addAll({
loop : Cesium.ModelAnimationLoop.REPEAT
});
});
// viewer.trackedEntity = entity;
}
var options = [{
text : 'Select Model'
},{
text : 'Ground vehicle',
onselect : function() {
createModel('../../SampleData/models/CesiumGround/Cesium_Ground.gltf', 500);
}
},{
text : 'Aircraft',
onselect : function() {
createModel('../../SampleData/models/CesiumAir/Cesium_Air.gltf', 1500.0);
}
}];
Sandcastle.addToolbarMenu(options);