How do I find the height information given x and z of the Cesium Map

Hi, I want to spawn prefabs using a C# scripts at a specific location on the map. I have the x and z World coordinate but I need to figure out the height (World y coordinate). I tried using Raycasting to no avail. Is there a built-in Cesium function (Return Height) for this?

Thanks

Call it via a web component using a web service that will echo back the altitude for that location.

Could you provide the exact reference of the function of the Cesium API?

Thanks.

https://cesium.com/learn/cesiumjs/ref-doc/HeightReference.html

I don’t think you can get this value inside Cesium for Unity. You will therefore have to call it via a third party (https://www.geonames.org/) webservice and then use that value for your spawned objects’ altitude. However, you will have to calibrate an offset in relation to the actual surface.

Raycasting is the only built-in option currently. If you elaborate on “no avail” there’s a chance we might be able to help.

Calling an external web service could be a good option, too, though I can’t help you with the specifics on that.

What I tried was to shoot a ray vertically (I tried both directions: up and down) and tried to find the intersection point with the Cesium map. Assume x_center and z_center to be 0 and 0 in the world space. Assume that the Cesium map is somewhere around y= - 2000

    float x_random = Random.Range(x_center-cell_size/2, x_center+cell_size/2);
    float z_random = Random.Range(z_center-cell_size/2, z_center+cell_size/2);
    Vector3 origin = new Vector3(x_random, -1000000f, z_random); // Start the raycast from a high point
    Vector3 direction = Vector3.up;
    Ray ray = new Ray(origin, direction);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, 10000000000000))
    {
        return hit.point.y;
    }

This doesn’t yield any intersection.
Thank you for your help.

Hi @beepboop,

Just to be sure, can you confirm that you have “Create Physics Meshes” enabled on the tileset?

If that is enabled, and this still isn’t working, can you share when exactly you’re casting the ray? 3D Tiles will take a few frames to stream in, so raycasting at the beginning of the application is essentially raycasting into empty space. The tiles need to load into the scene before you can raycast against them.

I had success getting height of a specific position on the tiles if i wait for several seconds until the tiles have successfully been instantiated.
But ideally there would be a callback/event system in place that triggers after a tile has successfully landed in the scene and is ready to be used/queried/raycast against. But there doesnt seem to be anything li!e that implemented in the unity plugins
This seems like a gap and oversight. Is something like that in the backlog/planned? Or is extending such things on a custom unity plugin fork the only option?

You can subscribe to be notified when each tile is loaded:

Or you can ask for the overall load progress:

1 Like

Awesome, thanks !
→ did’nt find anything like that back when i searched for it , so i guess those are rather new ?

Introduced in v1.4.0 (early July) and v1.6.0 (early September), respectively.