Keep Terrain's Y Pos when adjusting Georeference Scale

I want to be able to keep the map(3D Tileset: Cesium World Terrain) in the same Unity worldspace Y position (0) when adjusting the Georeference’s scale value or when moving to a location with a different elevation. Currently I have to calculate the height offset of the terrain by raycasting against the terrain collider and then calculate the distance to the Y position of 0. This method results in very choppy behavior when zooming the map(adjusting the Cesium Georeference scale value). Also things break down when zoomed in and navigating a city with large buildings (Google 3D Tiles) as the map will bounce.

Another costly, but slightly faster solution I’ve found is to get the Elevation of my location, then set that as the height on an empty object with a CesiumGlobeAnchor to arrive at a close to 0 Y Position for the Terrain.

Is there a better way to achieve this? or at the very least can the average or lowest point in the terrain be found without raycasting?

Hi @matt-eolian,

Unfortunately, raycasting is the only main method right now for sampling terrain height at a point. We have a Github issue for this functionality in Cesium Native, but I have no estimate for when it will be available.

Just to check my understanding, though, say you’re at some height Y above Cesium World Terrain. When you adjust the Georeference’s scale (therefore making CWT smaller), would like to remain at literally the same height Y above Cesium World Terrain, or proportionally the same height, i.e., Y / scale?

Hey Janine, thanks for the quick response.

It would be the same literal height in Unity world space. We’re using Cesium in the context of a tabletop map in XR, so our goal is to keep the terrain at a set “table” height when adjusting the georeference scale.

Hi @matt-eolian,

Got it, thank you for the clarification.

When adjusting the georeference scale, it scales the terrain around wherever the CesiumGeoreference is in Unity space. So if the CesiumGeoreference is at a Unity position (0, 1, 0), then everything scales as if (0, 1, 0) is the center. I haven’t prototyped this myself, but the idea is that you can set the georeferenced origin to the point you want to zoom in / out from. Then, scaling the georeference should keep that point fixed. If that point is underneath the camera, then ideally it would keep the terrain at the same relative height.

Let me know if that alternative works for you!

Hey @janine ,

This solution only works if I set the Height value of the CesiumGeoreference Origin to the elevation of the latitude and longitude I’m zooming to. This works up to the scale of .01, but then breaks down when scaling up any further. This is probably due to the elevation value I’m having to retrieve from other sources not matching up exactly with the Cesium World Terrain. This is especially evident in areas where the elevation is higher, like Colorado.

Hi @matt-eolian,

Yes, that’s what I meant and I apologize for not explaining well. If the CesiumGeoreference origin is set to the exact location on the terrain you’re zooming in / out from, then the scale will apply around that point of reference. Scaling it down will still preserve the height of your user / non-georeferenced objects above the CesiumGeoreference. But if the CesiumGeoreference origin is higher than the ground, it will zoom around that higher point, which is unwanted. If you need to find this point dynamically, you can raycast and convert the Unity position to an Earth-Centered, Earth-Fixed position to set the CesiumGeoreference origin to.

But I’m definitely concerned about the scale breaking after a certain threshold. How are you using the elevation values from other sources? For example, are you using them to place other objects?

1 Like

Hey @janine ,

Yes that’s correct, but I’m trying to avoid raycasting. If there is no other solution to this currently that’s alright, I’ll just have to wait for that functionality to be added to native as you mentioned.

And I meant breaks down as in it is no longer accurate, the terrain may be above or below where I expect it to be. So in the case, assume a table top mode where the terrain sinks below the table or up into the ceiling when surpassing a scale of .01.

1 Like

I found setting height to 0 on the GeoReference always keeps the Y at the same position but I’m not sure if there are any other negative side effects of using this hacked solution.

1 Like

@Mark_Grossnickle That would only work for locations where the elevation of the terrain is close to the WGS84 ellipsoid. Areas with higher elevation that deviate from the ellipsoid would need to have that Georeference height value adjusted.

hmm, seems to work well in our use cases. Did you try it? What issue did you see?

Hey @Mark_Grossnickle , not sure what your use case is, but I’m assuming you’re either working with a different scale or camera setup. Here is a sample that shows the terrain will not keep the same global position when adjusting scale(even with the height set to zero).


@matt-eolian you are right. I must be at a location near ellipsoid as we have added other locations with more issues.

i’m experiencing the same issues. also, the transform is shifting around. have you guys found any solution yet?

@xrdevrob We get now get DTED elevation data for the map center and apply that to the Georeference height. This works for the most part, but sometimes the DTED is slightly off though so in those cases we fall back to the raycast method mentioned at the start of this thread.

Alright, thanks so much for the info! Can I ask how you are clipping your map or what shader you used to clip it in a nice circle?