Cesium 動態Polyline繪製

Cesium 用Entity繪製polyline,如果使用CallbackProperty方法進行動態繪製,depthFailMaterial屬性將失效。
從官方github上的issue找了替代的方法。

動態Primitive線的繪製

// 繪製方法
this._candidateLinePrimitive = this.scene.primitives.add(
  new Cesium.Primitive({
    geometryInstances: new Cesium.GeometryInstance({
      geometry: new Cesium.PolylineGeometry({
        positions: this._candidateLinePositions,
        width: this.defaultLineWidth,
        vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT
      })
    }),
    appearance: new Cesium.PolylineMaterialAppearance({
      material: new Cesium.Material({
        fabric: {
          type: "PolylineDash",
          uniforms: {
            color: (() => {
              let c = this.lineMaterial.color.getValue();
              return new Cesium.Color(c.red, c.green, c.blue, 1.0);
            })()
          }
        }
      }),
      renderState: {
        depthTest: {
          enabled: false  // shut off depth test
        }
      }
    }),
    asynchronous: false   // block or not
  })
);
// 動態刷新,remove 再 add
if (!_.isEmpty(this._candidateLinePrimitive)) {
    this.scene.primitives.remove(this._candidateLinePrimitive);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章