Cesium地形开挖(仅限凸多边形)

var points = [
      Cesium.Cartesian3.fromDegrees(116.5,40.8),
      Cesium.Cartesian3.fromDegrees(116.9,40.8),
      Cesium.Cartesian3.fromDegrees(116.9,41.5)
];
      
var pointsLength = points.length;
var clippingPlanes = []; // 存储ClippingPlane集合
for (var i = 0; i < pointsLength; ++i) {
      var nextIndex = (i + 1) % pointsLength;
      var midpoint = Cesium.Cartesian3.add(points[i], points[nextIndex], new Cesium.Cartesian3());
      midpoint = Cesium.Cartesian3.multiplyByScalar(midpoint, 0.5, midpoint);
 
      var up = Cesium.Cartesian3.normalize(midpoint, new Cesium.Cartesian3());
      var right = Cesium.Cartesian3.subtract(points[nextIndex], midpoint, new Cesium.Cartesian3());
      right = Cesium.Cartesian3.normalize(right, right);
 
      var normal = Cesium.Cartesian3.cross(right, up, new Cesium.Cartesian3());
      normal = Cesium.Cartesian3.normalize(normal, normal);
 
      var originCenteredPlane = new Cesium.Plane(normal, 0.0);
      var distance = Cesium.Plane.getPointDistance(originCenteredPlane, midpoint);
 
      clippingPlanes.push(new Cesium.ClippingPlane(normal, distance));
      }
viewer.scene.globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
      planes:clippingPlanes,
      edgeWidth: 1.0,
      edgeColor: Cesium.Color.YELLOW
      });

待解决

posted @ 2019-12-07 14:56  敏敏酱  阅读(2157)  评论(1编辑  收藏  举报