• Cesium快速上手2-Model图元使用讲解


    1. Model示例讲解

    http://localhost:8080/Apps/Sandcastle/index.html?src=development%2F3D%20Models.html&label=Development

    在这里插入图片描述

    scene.primitives.add增加一个图元

       model = scene.primitives.add(Cesium.Model.fromGltf({
            url : url,
            modelMatrix : modelMatrix,
            minimumPixelSize : 128
        }));
    
    • 1
    • 2
    • 3
    • 4
    • 5

    createModel具体使用讲解

    1. modelMatrix:
      scene.primitives.removeAll(); // Remove previous model
      model = scene.primitives.add(
        Cesium.Model.fromGltf({
          url: url,
          modelMatrix: modelMatrix,
          minimumPixelSize: 128,
        })
      );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    modelMatrix:飞机在空间的姿态

    1. Cesium.Transforms.headingPitchRollToFixedFrame:
      const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
        origin,
        hpr
      );
    
    • 1
    • 2
    • 3
    • 4

    origin:三维空间的位置

      const origin = Cesium.Cartesian3.fromDegrees(
        -123.0744619,
        44.0503706,
        height
      );
    
    • 1
    • 2
    • 3
    • 4
    • 5

    -123.0744619:西经
    44.0503706:北纬
    height:高度

    1. model:

    这里可以对模型进行一些设置(颜色、阴影 … )
    在这里插入图片描述
    在这里插入图片描述

    1. readyPromise camera.lookAt:

    看模型的视角
    cesium是将视角将模型的中心点进行绑定

          camera.lookAt(
            center,
            new Cesium.HeadingPitchRange(heading, pitch, r * 2.0)
          );
    
    • 1
    • 2
    • 3
    • 4

    解除绑定

    
    
    • 1

    Sandcastle使用讲解

    1. Cesium.knockout
    // The viewModel tracks the state of our mini application.
    const viewModel = {
      color: "White",
      colors: ["White", "Red", "Green", "Blue", "Yellow", "Gray"],
      alpha: 1.0,
      colorBlendMode: "Highlight",
      colorBlendModes: ["Highlight", "Replace", "Mix"],
      colorBlendAmount: 0.5,
      colorBlendAmountEnabled: false,
    };
    
    // Convert the viewModel members into knockout observables.
    Cesium.knockout.track(viewModel);
    
    // Bind the viewModel to the DOM elements of the UI that call for it.
    const toolbar = document.getElementById("toolbar");
    Cesium.knockout.applyBindings(viewModel, toolbar);
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
              <tr>
                <td>Modetd>
                <td>
                  <select data-bind="options: colorBlendModes, value: colorBlendMode">select>
                td>
              tr>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    1. Cesium.knockout.track(viewModel) Cesium.knockout.applyBindings(viewModel, toolbar)
    
    Cesium.knockout
      .getObservable(viewModel, "color")
      .subscribe(function (newValue) {
        model.color = Cesium.Color.fromAlpha(
          getColor(newValue),
          Number(viewModel.alpha)
        );
      });
    
    Cesium.knockout
      .getObservable(viewModel, "alpha")
      .subscribe(function (newValue) {
        model.color = Cesium.Color.fromAlpha(
          getColor(viewModel.color),
          Number(newValue)
        );
      });
    
    Cesium.knockout
      .getObservable(viewModel, "colorBlendMode")
      .subscribe(function (newValue) {
        const colorBlendMode = getColorBlendMode(newValue);
        model.colorBlendMode = colorBlendMode;
        viewModel.colorBlendAmountEnabled =
          colorBlendMode === Cesium.ColorBlendMode.MIX;
      });
    
    Cesium.knockout
      .getObservable(viewModel, "colorBlendAmount")
      .subscribe(function (newValue) {
        model.colorBlendAmount = Number(newValue);
      });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    2. ModelInstance示例讲解

    http://localhost:8080/Apps/Sandcastle/index.html?src=development%2F3D%20Models%20Instancing.html&label=Development
    在这里插入图片描述
    Cesium.ModelInstanceCollection

    function createCollection(instances) {
      const collection = scene.primitives.add(
        new Cesium.ModelInstanceCollection({
          url: url,
          instances: instances,
        })
      );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3. Model子节点控制

    http://localhost:8080/Apps/Sandcastle/index.html?src=development%2F3D%20Models%20Node%20Explorer.html&label=Development
    在这里插入图片描述

        // respond to viewmodel changes by applying the computed matrix
        Cesium.knockout
          .getObservable(viewModel, "matrix")
          .subscribe(function (newValue) {
            const node = model.getNode(viewModel.nodeName);
            if (!Cesium.defined(node.originalMatrix)) {
              node.originalMatrix = node.matrix.clone();
            }
            node.matrix = Cesium.Matrix4.multiply(
              node.originalMatrix,
              newValue,
              new Cesium.Matrix4()
            );
          });
      })
      .catch(function (error) {
        window.alert(error);
      });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
  • 相关阅读:
    【离散数学】第三章 测试
    Hazelcast系列(八):数据结构
    英语六级-day8
    前端-vue基础52-组件化开发开始
    软件工程毕业设计课题(84)微信小程序毕业设计PHP物业维修报修小程序系统设计与实现
    Java中枚举类(enum)的实用小技巧
    portraiture中文版下载切换教程v3.5.6版本
    光模块在5G网络中的使用
    一文了解大模型工作原理——以ChatGPT为例
    LuatOS-SOC接口文档(air780E)-- fskv - kv数据库,掉电不丢数据
  • 原文地址:https://blog.csdn.net/qq_52354698/article/details/126215571