I have a similar problem; but instead of 3DTile I am using a simpe box.
On WGS84 Ellipsoid the box is clipped to the ground; when on WorldTerrain the box is partwise beneath the surface.
You can confirm this:
- setting to WGS84-Ellipsoid
- Click "onEllipsoid"
--> the box is clipped to ground
- click "magnitude 10"
- click "up"
--> the box is "flying" over the surface
- setting to Cesium World Terrain
- click "onTerrain"
--> part of the box is beneath surface:
- click "magnitude 10"
- click "up"
--> the box is comimg more up but still partwise under surface
This is the code:
var viewer = new Cesium.Viewer('cesiumContainer');
var CC3 = Cesium.Cartesian3;
var magnitude = 1;
var box_height = 30;
var thebox = viewer.entities.add({
name : 'building',
position: Cesium.Cartesian3.fromDegrees(-90.1922703175, 38.6286636758, box_height/2),
box : {
dimensions : new Cesium.Cartesian3(40, 30, box_height),
material : Cesium.Color.RED,
outline : true,
outlineColor : Cesium.Color.BLACK
}
});
viewer.zoomTo(viewer.entities);
//var terrainProvider = new Cesium.CesiumTerrainProvider({
// url : '//assets.agi.com/stk-terrain/world',
requestVertexNormals : true
//});
var terrainProvider = Cesium.createWorldTerrain();
function getVector(name)
{
var GD_full_transform = Cesium.Transforms.eastNorthUpToFixedFrame(thebox._position._value, viewer.scene.globe.ellipsoid, new Cesium.Matrix4());
var GD_rot_transform = Cesium.Matrix4.getRotation(GD_full_transform,new Cesium.Matrix3());
if(name=="east"){return Cesium.Matrix3.getColumn(GD_rot_transform,0,new CC3());}
if(name=="north"){return Cesium.Matrix3.getColumn(GD_rot_transform,1,new CC3());}
if(name=="up"){return Cesium.Matrix3.getColumn(GD_rot_transform,2,new CC3());}
}
function move(scalar,unitVector)
{
var mycarte = thebox._position._value;
var relMove = CC3.multiplyByScalar(unitVector,scalar,new CC3());
CC3.add(mycarte,relMove,mycarte);
thebox.position = mycarte;
var mycarto = new Cesium.Cartographic();
mycarto = viewer.scene.globe.ellipsoid.cartesianToCartographic(thebox._position._value);
console.log("lon "+mycarto.longitude/Math.PI*180);
console.log("lat "+mycarto.latitude/Math.PI*180);
console.log("alt "+mycarto.height);
}
function setOnTerrain()
{
var mycarte = thebox._position._value;
thebox.position = mycarte;
var mycarto = new Cesium.Cartographic();
mycarto = viewer.scene.globe.ellipsoid.cartesianToCartographic(thebox._position._value);
//takes the terrain, a precision value and the point of interest
Cesium.sampleTerrain(terrainProvider, 11, [mycarto]).then(function(){
console.log("setting to terrain height: "+(mycarto.height));
mycarto.height += box_height/2;
thebox.position = viewer.scene.globe.ellipsoid.cartographicToCartesian(mycarto);
});
}
function setOnEllipsoid()
{
var mycarte = thebox._position._value;
thebox.position = mycarte;
var mycarto = new Cesium.Cartographic();
mycarto = viewer.scene.globe.ellipsoid.cartesianToCartographic(thebox._position._value);
mycarto.height = box_height/2;
console.log("setting to ellipsoid height: "+(mycarto.height));
thebox.position = viewer.scene.globe.ellipsoid.cartographicToCartesian(mycarto);
}
Sandcastle.addToolbarButton('magnitude 1', function()
{magnitude=1;});
Sandcastle.addToolbarButton('magnitude 10', function()
{magnitude=10;});
Sandcastle.addToolbarButton('east', function()
{move(magnitude,getVector("east"));});
Sandcastle.addToolbarButton('west', function()
{move(-magnitude,getVector("east"));});
Sandcastle.addToolbarButton('north', function()
{move(magnitude,getVector("north"));});
Sandcastle.addToolbarButton('south', function()
{move(-magnitude,getVector("north"));});
Sandcastle.addToolbarButton('up', function()
{move(magnitude,getVector("up"));});
Sandcastle.addToolbarButton('down', function()
{move(-magnitude,getVector("up"));});
Sandcastle.addToolbarButton('onTerrain', function()
{setOnTerrain();});
Sandcastle.addToolbarButton('onEllipsoid', function()
{setOnEllipsoid();});
What is wrong?