question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

depthFailMaterial for dynamic polylines

See original GitHub issue

The new depthFailMaterial property currently only works for static polyline entities. This is because the PolylineGeometryUpdater uses a PolylineGeometry for static polylines and a PolylineCollection for dynamic ones. We’ll need to add depth fail material support to the PolylineCollection

var viewer = new Cesium.Viewer('cesiumContainer');
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
    url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
    requestWaterMask : true,
    requestVertexNormals : true
});
viewer.terrainProvider = cesiumTerrainProviderMeshes;
viewer.scene.globe.depthTestAgainstTerrain = true;

var length = 1000;

var startLon = Cesium.Math.toRadians(86.953793);
var endLon = Cesium.Math.toRadians(86.896497);

var lat = Cesium.Math.toRadians(27.988257);

var terrainSamplePositions = [];
for (var i = 0; i < length; ++i) {
    var lon = Cesium.Math.lerp(endLon, startLon, i / (length - 1));
    var position = new Cesium.Cartographic(lon, lat);
    terrainSamplePositions.push(position);
}

var positions = [];
function getPositions() {
    return positions;
}
viewer.entities.add({
    polyline : {
        positions : new Cesium.CallbackProperty(getPositions, false),
        followSurface : false,
        width : 5,
        material : new Cesium.PolylineOutlineMaterialProperty({
            color : Cesium.Color.ORANGE,
            outlineWidth : 2,
            outlineColor : Cesium.Color.BLACK
        }),
        depthFailMaterial : new Cesium.PolylineOutlineMaterialProperty({
            color : Cesium.Color.RED,
            outlineWidth : 2,
            outlineColor : Cesium.Color.BLACK
        })
    }
});

Cesium.when(Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, terrainSamplePositions), function(samples) {
    var offset = 10.0;
    for (var i = 0; i < samples.length; ++i) {
        samples[i].height += offset;
    }
    positions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(samples);

    var target = new Cesium.Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
    offset = new Cesium.Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
    viewer.camera.lookAt(target, offset);
    viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
hailengccommented, Aug 16, 2018

I was also trapped by this. Finally worked around by using primitive with depthTest (sub attribute of renderState) set to false. Example:

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

Then the update process is a remove-if-exists-then-add process:

if (!_.isEmpty(this._candidateLinePrimitive)) {
    this.scene.primitives.remove(this._candidateLinePrimitive);
}

//code aforementioned

If you want to update this primitive immediately (which happens to be my case), you should also set asynchronous to false.

0reactions
ggetzcommented, Mar 7, 2022

Hi @WilliamLiu-1997, there aren’t any plans to work on this presently. But we’d be happy to review a pull request if you’d be interested in adding the feature yourself!

Read more comments on GitHub >

github_iconTop Results From Across the Web

depthFailMaterial for dynamic polylines · Issue #5333 - GitHub
The new depthFailMaterial property currently only works for static polyline entities. This is because the PolylineGeometryUpdater uses a ...
Read more >
Disable Depth Test For Polylines and Polygons
Hi Omar,. Unfortunately we are using dynamic polylines which depthFailMaterial does not support. I can see an open issue on GitHub #5333 so...
Read more >
How to make polylines always visible - Cesium Community
Im drawing a polyline and it's not visible through building or terrain, is there a way to force it to always show no...
Read more >
cesium/CHANGES.md - UNPKG
666, - Fixed a bug where dynamic polylines did not use the given arcType. ... for polyline entities with a dynamic color for...
Read more >
Best and most performant implementation of dynamic shapes ...
I also tried using primitives. It worked great for polylines, I would simply remove the old one and add a new one with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found