How to get the center position of 3DTileset ,I want the camera to turn around when I clicked it.
Hello @zrkcode,
I’m not sure what you mean by needing to turn the camera around when you click on it, but to retrieve the center position of a tileset you need to use C++ since the coordinates will be in double precision. It’s worth noting that the position of the tileset as Unreal displays them will always be at an absolute Unreal location of (0, 0, 0), which will not be the center of the tileset. To calculate the actual center of the tileset, you first need a reference to the tileset ACesium3DTileset* tileset. Then you can do:
std::optional<Cesium3DTiles::BoundingVolume> boundingVolume =
tileset->GetBoundingVolume();
if (boundingVolume) {
glm::dvec3 ecefCenter = boundingVolume->getCenter();
/*
This is the center position of the tileset in ECEF. In order to convert it
into Unreal coordinates, use the conversion functions on the tileset's
ACesiumGeoreference actor.
*/
}
-Nithin Pranesh
Thank you for your reply,it’s very helpful to me.
But now , " tileset->GetBoundingVolume " is wrong ,so we can how to get the center position of 3DTilese 。
@Crs9charles A possible quick answer: I think that instead of tileset->getBoundingVolume() you have to use tileset->GetTileset()->getRootTile()->getBoundingVolume(). If this does not fix it, I’ll have to re-read the latest state of the code (or maybe Nithin can point you to the right solution based on the latest state)
Hello @Crs9charles,
The old function returned an optional, here you don’t need the optional anymore. So the type should just be const Cesium3DTilesSelection::BoundingVolume& now. Also note that the library name changed from Cesium3DTiles to Cesium3DTilesSelection since my code snippet above.
In order to make this safe though you will have to check that the tileset and root tile are not null. So maybe something like this:
if (!tileset->GetTileset() || !tileset->GetTileset()->getRootTile()) {
return FVector(); // Invalid
}
const Cesium3DTilesSelection::BoundingVolume& boundingVolume =
tileset->GetTileset()->getRootTile()->getBoundingVolume();
...
Thanks, it helped me, have nice day to you!
