如何在地形底部裁剪实体或几何体
How do I clip an entity or geometry against underside of terrain
我正在使用 Cesium.Globe 裁剪平面来提取正方形地理部分。但一个问题是地形背面没有渲染,这使得当用户选择较浅的视角时看起来很奇怪。
我认为隐藏它的一种方法是将 "soil" 渲染为地形下方的盒子或墙,但我需要盒子或墙的顶部来确认地形几何形状(红线).
我想我可以通过使用 WallGeometry around the culled terrain instead of a box, and set the height of each section based on the result of a sampleTerrain 调用来实现。
但我想知道 Cesium 是否提供了一种更简单、更简洁的方法来做到这一点。 (比如一些布尔联合函数或其他东西)
var viewer = new Cesium.Viewer('cesiumContainer', {
skyAtmosphere: false,
shouldAnimate : true,
terrainProvider: Cesium.createWorldTerrain()
});
var globe = viewer.scene.globe;
var position = Cesium.Cartographic.toCartesian(new Cesium.Cartographic.fromDegrees(-113.2665534, 36.0939345, 100));
var distance = 3000.0;
globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
modelMatrix : Cesium.Transforms.eastNorthUpToFixedFrame(position),
planes : [
new Cesium.ClippingPlane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), distance),
new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), distance),
new Cesium.ClippingPlane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), distance),
new Cesium.ClippingPlane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), distance)
],
unionClippingRegions : true,
edgeWidth:3,
edgeColor: Cesium.Color.RED,
enabled : true
});
var rockBox = viewer.entities.add({
name : 'RockBox',
position: Cesium.Cartesian3.fromDegrees(-113.2665534, 36.0939345, 900),
box : {
dimensions : new Cesium.Cartesian3(distance*2, distance*2,800.0),
material : Cesium.Color.GRAY.withAlpha(0.4),
outline : true,
outlineColor : Cesium.Color.GRAY
}
});
var waterTable = viewer.entities.add({
name : 'WaterTable',
position: Cesium.Cartesian3.fromDegrees(-113.2665534, 36.0939345, 440),
box : {
dimensions : new Cesium.Cartesian3(distance*2, distance*2, 160.0),
material : Cesium.Color.BLUE.withAlpha(0.9),
outline : true,
outlineColor : Cesium.Color.BLUE
}
});
viewer.zoomTo(viewer.entities);
在更新的 CesiumGS 版本(当前为 1.72)中,我们通过 public API 显示地形背面,如下所示:
viewer.scene.globe.backFaceCulling = false;
我正在使用 Cesium.Globe 裁剪平面来提取正方形地理部分。但一个问题是地形背面没有渲染,这使得当用户选择较浅的视角时看起来很奇怪。
我认为隐藏它的一种方法是将 "soil" 渲染为地形下方的盒子或墙,但我需要盒子或墙的顶部来确认地形几何形状(红线). 我想我可以通过使用 WallGeometry around the culled terrain instead of a box, and set the height of each section based on the result of a sampleTerrain 调用来实现。
但我想知道 Cesium 是否提供了一种更简单、更简洁的方法来做到这一点。 (比如一些布尔联合函数或其他东西)
var viewer = new Cesium.Viewer('cesiumContainer', {
skyAtmosphere: false,
shouldAnimate : true,
terrainProvider: Cesium.createWorldTerrain()
});
var globe = viewer.scene.globe;
var position = Cesium.Cartographic.toCartesian(new Cesium.Cartographic.fromDegrees(-113.2665534, 36.0939345, 100));
var distance = 3000.0;
globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
modelMatrix : Cesium.Transforms.eastNorthUpToFixedFrame(position),
planes : [
new Cesium.ClippingPlane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), distance),
new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), distance),
new Cesium.ClippingPlane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), distance),
new Cesium.ClippingPlane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), distance)
],
unionClippingRegions : true,
edgeWidth:3,
edgeColor: Cesium.Color.RED,
enabled : true
});
var rockBox = viewer.entities.add({
name : 'RockBox',
position: Cesium.Cartesian3.fromDegrees(-113.2665534, 36.0939345, 900),
box : {
dimensions : new Cesium.Cartesian3(distance*2, distance*2,800.0),
material : Cesium.Color.GRAY.withAlpha(0.4),
outline : true,
outlineColor : Cesium.Color.GRAY
}
});
var waterTable = viewer.entities.add({
name : 'WaterTable',
position: Cesium.Cartesian3.fromDegrees(-113.2665534, 36.0939345, 440),
box : {
dimensions : new Cesium.Cartesian3(distance*2, distance*2, 160.0),
material : Cesium.Color.BLUE.withAlpha(0.9),
outline : true,
outlineColor : Cesium.Color.BLUE
}
});
viewer.zoomTo(viewer.entities);
在更新的 CesiumGS 版本(当前为 1.72)中,我们通过 public API 显示地形背面,如下所示:
viewer.scene.globe.backFaceCulling = false;