Clamping To Terrain on Lunar globe

1. A concise explanation of the problem you're experiencing.

Not ideal behavior when attempting to attach features to terrain on lunar surface.

There's notes in the sandbox link below but i'll summarize here:

- polyline clampToGround does not seem to work at all
- point and label features work but have some behaviors that seem to deviate from what I see in the sandbox Clamp to Terrain example. Seem to be partially hidden more often, also disappear if i zoom in too far on them.
- polygon seems like it tries to clamp to terrain, but ends up mostly hidden
- all features seem to disappear as i tilt the camera to look as is from the crater surface

I understand Clamp to Terrain is a work in progress! Hope this is helpful and happy to contribute just not super familiar with the internals so any guidance as to where the problem areas might be is appreciated.

Thanks in advance

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

The below is a map using lunar terrain tiles with some features drawn on it near Tycho crater

https://cesiumjs.org/releases/1.54/Apps/Sandcastle/index.html#c=zVdtb9s2EP4rRL7Y7hzKsp3ESbNuSZqmxtwkaNwWxTwEtHS2uFCkQNJ23SH/fUdRtizba74M2IwAiu6Nx7vnXjRnmoAQPDOKx+RnImFBrsDwWUqvV+R6eNI56bZaza1n4/VIjuS2NP1y89Droqm1WRSb4zEpy+61+hMiy5WsHnUDaqpZlvColKiv9f05zsRUqDFsqTpSVTaXoiZRixutZjK+sKkyWQLaqU6YMPCaBAEaicAYppdkojSxXIAhVhGnR7gkUslDYNom5UVWpmPIbDIEYy+mjEtjh6A1/oPWrZ5BcV3riXihOY9BV732j2FVpP7XSBL8zbQ4I7XE2sycBcHEOUZZZKfMAo1UGhSWAzGTTD9ORRy2WrWm1137erbp9nMZQpVZg74UR1VyclZ9LSzmVz7zj4K0dbWzbUIhZp6WZejPfOSbzg/HxAS8R1kyk2UePvULRRDehb6MecSs0qW244+ZgQFbgr7n0RNsMS1PQXAJVeoUVKTibVkuJ+pSfasSTQQSPqDwPutM8pT5YOVkT8UIrwM857DYTvfnnFavRfnrlZIWowW61szT4ZLjtWh+Np2oKQXJxgLiNWK9cTx8CnqZX96lsVCrkFG08k5ZHPc9YY20Dd++wPgDyx5Az3kE23IlIskGJBcwRqRQo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GqK7R+L/XNd76o9N6q05/K1wP8L6H9I1EzguARXW5krgxypxu2pJSgXzA2bMQ5ft/sDw0EscYj6CWry4YxVmVeCsv+XCpgqub8AEo5e6ShZ7mf/OzVS1kqHhp3jo64f3q2T3lGv+SPxNj3tnXTbvrSOT3rtoxfEw+Pj3rEX7522wpes41dsJyw2iePj0x9b3/V9v/QfjT3Y/HEhbsH70zVdcJtciCxh9RY9ehHYBQrc+jdU9S1MNF4fNA/OjV0KeOM1f+VpprR1e32dUvygxFUQnTHBeIafPJZGJv8oOQ9WSucxnxMe/zw62PqEGR24UWEMcia4hLmVaXTw5hxn2ryiJhRzU/EOpzx+ITiRJHwz8ERK6XmAr7tauMaKMa6lpcW/AQ

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

Showing labels and lines and shapes on the moon!

4. The Cesium version you're using, your operating system and browser.

Cesium 1.54, Ubuntu, latest Chrome

Thanks you so much for the detailed and well-written Sandcastle example! You must be the first person to try clamping polylines on the moon, congrats!

I looked into the polyline issue specifically. It looks like the reason it’s off is because it’s using the built-in known terrain heights for the Earth. I opened an issue with more details here that includes how to turn on debug bounding volumes to see this for yourself:

https://github.com/AnalyticalGraphicsInc/cesium/issues/7552

It would absolutely be awesome to get a contribution to fix this! I posted what I think a suggestion to fix it could look like. Feel free to post more thoughts/questions there and the rest of the developer can chime in, particularly Gary who I believe originally wrote the GroundPolylines.

I think there’s a similar reason why the clamping is broken for polygons. You can turn on debugShowBoundingVolume and debugShowShadowVolume in Source/Scene/GroundPrimitive.js to see this. If you manually edit the max/min terrain height in that class it might prove that this is indeed the issue.

Hope this gives you something to go on, please update me with any findings here or in the GitHub issue, and thanks for bringing this up and looking it!

Thanks again for your help earlier this year Omar!

I just want to follow up on where we left off. With yours and other cesium team members help you were able to pin down the issue where the polyline was being set to the incorrect height.

So now things render close to the ground which is an improvement but the issue remains (whether polyline, polygon, or label) that they're not *quite* draped over the terrain correctly. The features seem to be hidden underneath the terrain in many places.

An updated sandcastle link is here: https://c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/8C

Working off your suggestions for resolving the previous issue I did attempt generating my own approximateTerrainHeights json using lunar terrain data and patching that in to a local build but it didn't seem to make much of a difference... Are there other locations with earth-centric values I may want to play around with?

Would it be helpful if I compiled a github issue with some examples and a more formal write up?

Having a Sandcastle example (https://sandcastle.cesium.com/index.html?) reproducing the issue (or one for each issue if there’s multiple) would certainly help move this along faster! Feel free to open a GitHub issue (https://github.com/CesiumGS/cesium) if you’ve isolated it to a CesiumJS bug.