Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroundPolylinePrimitive has incorrect height with custom ellipsoid #7552

Closed
OmarShehata opened this issue Feb 8, 2019 · 5 comments
Closed

Comments

@OmarShehata
Copy link
Contributor

OmarShehata commented Feb 8, 2019

This is part of several issues that came up when clamping to terrain with custom terrain and a custom ellipsoid on the forum: https://groups.google.com/d/msg/cesium-dev/LxJDKmIDu8I/S-j10RcLFQAJ

This Sandcastle code will create a polyline somewhere on the earth using a smaller ellipsoid (to represent the moon):

var ellipsoid = new Cesium.Ellipsoid(1737400,1737400,1737400);

Cesium.Ellipsoid.WGS84 = ellipsoid;
var mapProjection = new Cesium.GeographicProjection(ellipsoid);

var globe = new Cesium.Globe(ellipsoid);
globe.showGroundAtmosphere = false;

var viewer = new Cesium.Viewer('cesiumContainer', {
    mapProjection: mapProjection,
    globe: globe
});

viewer.entities.add({
    polyline : {
        positions : Cesium.Cartesian3.fromDegreesArray([
        -12.86401, -42.43998,
        -9.47402, -44.37729
        ], ellipsoid),
        //clampToGround : true,
        width : 5,
        material : new Cesium.PolylineOutlineMaterialProperty({
            color : Cesium.Color.ORANGE,
            outlineWidth : 2,
            outlineColor : Cesium.Color.BLACK
        })
    }
});

viewer.zoomTo(viewer.entities);

Live link.

Everything looks fine, but then uncomment //clampToGround: true and you'll see that the polyline disappears into space. If you apply the following monkey patch to turn on debug bounding volumes for the GroundPolylinePrimitive (or just set it to true when running this locally in GroundPolylinePrimitive.js.

setTimeout(function(){
    viewer.scene.groundPrimitives._primitives[0]._primitives[0]._collections[0]._primitives[0].debugShowBoundingVolume = true
}, 1000);

You can see that the bounding volume is way high, I'm guessing hardcoded to the Earth's ellipsoid height?

zoom-out

My best guess is that this is because GroundPolylinePrimitive uses the ApproximateTerrainHeights which is all the Earth's terrain heights?

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/GroundPolylinePrimitive.js#L359-L368

Maybe we should allow overriding a min/max terrain height when creating polylines on non-earth ellipsoids? There's a similar problem that can be seen for the shadow volumes for groundprimitives that I can open a separate issue for.

@malaretv
Copy link
Contributor

Hey @OmarShehata thanks for all your help on this issue!

After playing around with ApproximateTerrainHeights for a bit, it seems that the issue was actually in the GroundPolylineGeometry constructor not accepting an ellipsoid option to override the WGS84 default.

Re: the initial lunar example posted in the forums: While the above pull request means the line is now drawn near the surface, it tends to be hidden beneath terrain when moving the camera from anything but a straight top-down view. Initial experiments with a custom approximateTerrainHeights.json file and modifying the default min / max in ApproximateTerrainHeights have definitely been promising but not perfect! Will open another issue with some examples when I have some time.

@cesium-concierge
Copy link

Congratulations on closing the issue! I found these Cesium forum links in the comments above:

https://groups.google.com/d/msg/cesium-dev/LxJDKmIDu8I/S-j10RcLFQAJ

If this issue affects any of these threads, please post a comment like the following:

The issue at #7552 has just been closed and may resolve your issue. Look for the change in the next stable release of Cesium or get it now in the master branch on GitHub https://github.com/AnalyticalGraphicsInc/cesium.

@hpinkos
Copy link
Contributor

hpinkos commented Feb 12, 2019

Thanks for reporting this @malaretv! A fix was added in #7566 and will be included in the CesiumJS 1.55 release available March 1st

@OmarShehata
Copy link
Contributor Author

@malaretv just followed up, same forum thread. Here's a Sandcastle with a polyline on a lunar crater.

Notice that tilting the camera causes the polyline to get occluded/culled somehow? @likangning93 is this a separate issue, do you think?

@likangning93
Copy link
Contributor

This is an approximateTerrainHeights thing. We can probably add an override so volumes for things on terrain will always use an override min/max instead of sampling from approximateTerrainHeights.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants