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
    }));

createModel具体使用讲解

  1. modelMatrix:
  scene.primitives.removeAll(); // Remove previous model
  model = scene.primitives.add(
    Cesium.Model.fromGltf({
      url: url,
      modelMatrix: modelMatrix,
      minimumPixelSize: 128,
    })
  );

modelMatrix:飞机在空间的姿态

  1. Cesium.Transforms.headingPitchRollToFixedFrame:
  const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
    origin,
    hpr
  );

origin:三维空间的位置

  const origin = Cesium.Cartesian3.fromDegrees(
    -123.0744619,
    44.0503706,
    height
  );

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

  1. model:

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

  1. readyPromise camera.lookAt:

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

      camera.lookAt(
        center,
        new Cesium.HeadingPitchRange(heading, pitch, r * 2.0)
      );

解除绑定


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);

          <tr>
            <td>Mode</td>
            <td>
              <select data-bind="options: colorBlendModes, value: colorBlendMode"></select>
            </td>
          </tr>
  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);
  });

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,
    })
  );

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);
  });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在人间负债^

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值