CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
879 stars 285 forks source link

Add functions to get the approximate location of a tileset during runtime #1458

Open arbertrary opened 2 weeks ago

arbertrary commented 2 weeks ago

As discussed in the following Cesium community forum thread, there is no API-level support to get the world location of a tileset during runtime from UE blueprints.

https://community.cesium.com/t/get-coordinates-of-cesium3dtileset-spawned-at-unknown-location/33087/4

As suggested by @kring I had a look at the ACesium3DTileset::OnFocusEditorViewportOnThis() function. With this pull request I added two functions that return an approximate location (Unreal and ECEF) of the tileset calculated using the rootTile.

Disclaimer:

arbertrary commented 2 weeks ago

If there is no root tile returned by this->_pTileset->getRootTile() this currently returns the Zerovector without warning which results in obviously incorrect coordinates.

I'm not sure what causes a tileset to not have a root tile but it seems to be the case for some tilesets.

ACesium3DTileset::OnFocusEditorViewportOnThis() also simply returns if it encounters a nonexisting root tile so I'm not sure how to best handle this here 🤔

kring commented 2 weeks ago

Thanks for the PR @arbertrary!

The root tile is part of the tileset.json, which is download when the tileset is first loaded. Until that download / parse completes, we don't know anything about the tileset, not even where it's located.

There's nothing for it other than to give the function a way to return "I don't know yet" as the answer.

arbertrary commented 2 weeks ago

I have added a warning and a boolean out value to the function so that this gets propagated and can be checked in blueprints.

Unfortunately this wasn't actually the problem. For some tilesets the function returns 0,0,0 even if the root tile is available. The !prootTile condition was actually never entered.

Tilesets where that was the case:

Tilesets where the code does work for me as expected are for example

arbertrary commented 1 week ago

Unfortunately this wasn't actually the problem. For some tilesets the function returns 0,0,0 even if the root tile is available. The !prootTile condition was actually never entered.

Checking whether the initial load of the tileset is complete by confirming that LoadProgress equals 100.0 before calling getApproximateLocation doesn't change this as well.