Cesium绘制各种立体图形

const viewer = new Cesium.Viewer("cesiumContainer");

const redPolygon = viewer.entities.add({
  name: "Red polygon on surface",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
      -115.0,
      37.0,
      -115.0,
      32.0,
      -107.0,
      33.0,
      -102.0,
      31.0,
      -102.0,
      35.0,
    ]),
    material: Cesium.Color.RED,
  },
});

const greenPolygon = viewer.entities.add({
  name: "Green extruded polygon",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
      -108.0,
      42.0,
      -100.0,
      42.0,
      -104.0,
      40.0,
    ]),
    extrudedHeight: 500000.0,
    material: Cesium.Color.GREEN,
    closeTop: false,
    closeBottom: false,
  },
});

const texturedPolygon = viewer.entities.add({
  name:
    "Extruded textured polygon with per-position heights and custom texture coordinates",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights([
      -118.4,
      40.4,
      50000,
      -118.4,
      37,
      30000,
      -114.2,
      38.0,
      35000,
      -108.0,
      37,
      30000,
      -108.0,
      40.4,
      50000,
    ]),
    textureCoordinates: {
      positions: [
        new Cesium.Cartesian2(0, 1),
        new Cesium.Cartesian2(0, 0),
        new Cesium.Cartesian2(0.5, 0),
        new Cesium.Cartesian2(1, 0),
        new Cesium.Cartesian2(1, 1),
      ],
    },
    perPositionHeight: true,
    extrudedHeight: 0,
    material: "../images/Cesium_Logo_Color.jpg",
  },
});

const texturedPolygonWithHoles = viewer.entities.add({
  name:
    "Textured polygon with per-position heights, holes and custom texture coordinates",
  polygon: {
    hierarchy: {
      positions: Cesium.Cartesian3.fromDegreesArrayHeights([
        -130,
        40.0,
        50000,
        -130,
        36.0,
        30000,
        -125,
        37,
        35000,
        -120,
        36.0,
        30000,
        -120,
        40.0,
        50000,
      ]),
      holes: [
        {
          positions: Cesium.Cartesian3.fromDegreesArrayHeights([
            -128,
            39.2,
            46000,
            -128,
            38.6,
            42000,
            -127,
            38.6,
            42000,
            -127,
            39.2,
            46000,
          ]),
        },
      ],
    },
    textureCoordinates: {
      positions: [
        new Cesium.Cartesian2(0, 1),
        new Cesium.Cartesian2(0, 0),
        new Cesium.Cartesian2(0.5, 0),
        new Cesium.Cartesian2(1, 0),
        new Cesium.Cartesian2(1, 1),
      ],
      holes: [
        {
          positions: [
            new Cesium.Cartesian2(0.2, 0.8),
            new Cesium.Cartesian2(0.2, 0.6),
            new Cesium.Cartesian2(0.4, 0.6),
            new Cesium.Cartesian2(0.4, 0.8),
          ],
        },
      ],
    },
    perPositionHeight: true,
    material: "../images/Cesium_Logo_Color.jpg",
  },
});

const orangePolygon = viewer.entities.add({
  name: "Orange polygon with per-position heights and outline",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights([
      -108.0,
      25.0,
      100000,
      -100.0,
      25.0,
      100000,
      -100.0,
      30.0,
      100000,
      -108.0,
      30.0,
      300000,
    ]),
    extrudedHeight: 0,
    perPositionHeight: true,
    material: Cesium.Color.ORANGE.withAlpha(0.5),
    outline: true,
    outlineColor: Cesium.Color.BLACK,
  },
});

const bluePolygon = viewer.entities.add({
  name: "Blue polygon with holes",
  polygon: {
    hierarchy: {
      positions: Cesium.Cartesian3.fromDegreesArray([
        -99.0,
        30.0,
        -85.0,
        30.0,
        -85.0,
        40.0,
        -99.0,
        40.0,
      ]),
      holes: [
        {
          positions: Cesium.Cartesian3.fromDegreesArray([
            -97.0,
            31.0,
            -97.0,
            39.0,
            -87.0,
            39.0,
            -87.0,
            31.0,
          ]),
          holes: [
            {
              positions: Cesium.Cartesian3.fromDegreesArray([
                -95.0,
                33.0,
                -89.0,
                33.0,
                -89.0,
                37.0,
                -95.0,
                37.0,
              ]),
              holes: [
                {
                  positions: Cesium.Cartesian3.fromDegreesArray([
                    -93.0,
                    34.0,
                    -91.0,
                    34.0,
                    -91.0,
                    36.0,
                    -93.0,
                    36.0,
                  ]),
                },
              ],
            },
          ],
        },
      ],
    },
    material: Cesium.Color.BLUE.withAlpha(0.5),
    height: 0,
    outline: true, // height is required for outline to display
  },
});

const cyanPolygon = viewer.entities.add({
  name: "Cyan vertical polygon with per-position heights and outline",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights([
      -90.0,
      41.0,
      0.0,
      -85.0,
      41.0,
      500000.0,
      -80.0,
      41.0,
      0.0,
    ]),
    perPositionHeight: true,
    material: Cesium.Color.CYAN.withAlpha(0.5),
    outline: true,
    outlineColor: Cesium.Color.BLACK,
  },
});

const purplePolygonUsingRhumbLines = viewer.entities.add({
  name: "Purple polygon using rhumb lines with outline",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
      -120.0,
      45.0,
      -80.0,
      45.0,
      -80.0,
      55.0,
      -120.0,
      55.0,
    ]),
    extrudedHeight: 50000,
    material: Cesium.Color.PURPLE,
    outline: true,
    outlineColor: Cesium.Color.MAGENTA,
    arcType: Cesium.ArcType.RHUMB,
  },
});

viewer.zoomTo(viewer.entities); 

绘制各种立体图形

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cesium是一个开源的JavaScript库,用于创建3D地球和地球上的场景。可以使用Cesium绘制立体扫描,具体步骤如下: 1. 安装Cesium库并创建一个Cesium场景。 2. 使用Cesium的Entity API创建一个立方体来表示扫描区域。 3. 使用Cesium的Polyline API创建一条线表示扫描路径。 4. 将立方体和线添加到场景中。 5. 使用Cesium的Animation API和SampledPositionProperty API在指定时间内将立方体沿着路径移动,以模拟扫描过程。 示例代码如下: ```javascript // 创建Cesium场景 var viewer = new Cesium.Viewer('cesiumContainer'); // 创建立方体 var cube = viewer.entities.add({ name: 'Cube', position: Cesium.Cartesian3.fromDegrees(-74.0707383, 40.7117244, 0), box: { dimensions: new Cesium.Cartesian3(1000.0, 1000.0, 1000.0), material: Cesium.Color.RED.withAlpha(0.5) } }); // 创建路径 var path = viewer.entities.add({ name: 'Path', polyline: { positions: Cesium.Cartesian3.fromDegreesArray([ -74.0707383, 40.7117244, -74.0711283, 40.7120244, -74.0715283, 40.7123244, -74.0719283, 40.7126244, -74.0723283, 40.7129244 ]), width: 5, material: Cesium.Color.BLUE } }); // 创建SampledPositionProperty,表示立方体的位置随时间变化的属性 var position = new Cesium.SampledPositionProperty(); position.addSample(Cesium.JulianDate.now(), cube.position.getValue()); position.addSample(Cesium.JulianDate.addSeconds(Cesium.JulianDate.now(), 5, new Cesium.JulianDate()), Cesium.Cartesian3.fromDegrees(-74.0723283, 40.7129244, 0)); // 使用Animation API,在5秒内将立方体沿着路径移动 viewer.clock.onTick.addEventListener(function(clock) { position.getValue(clock.currentTime, cube.position); }); viewer.clock.startTime = Cesium.JulianDate.now(); viewer.clock.stopTime = Cesium.JulianDate.addSeconds(viewer.clock.startTime, 5, new Cesium.JulianDate()); viewer.clock.currentTime = viewer.clock.startTime; viewer.clock.multiplier = 1; viewer.clock.shouldAnimate = true; ``` 这段代码将在场景中创建一个立方体和一条路径,并在5秒内将立方体沿着路径移动。可以根据需要调整立方体和路径的位置、大小和样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值