diff --git a/Runtime/Cesium3DTileset.cs b/Runtime/Cesium3DTileset.cs index 4475dd07..e2c472f1 100644 --- a/Runtime/Cesium3DTileset.cs +++ b/Runtime/Cesium3DTileset.cs @@ -650,6 +650,17 @@ public bool createPhysicsMeshes } } + /// + /// Gets the axis-aligned bounding box of the root tile of this tileset. + /// + public Bounds bounds + { + get + { + return getBounds(); + } + } + private partial void SetShowCreditsOnScreen(bool value); private partial void Start(); @@ -669,5 +680,7 @@ public bool createPhysicsMeshes /// Zoom the Editor camera to this tileset. This method does nothing outside of the Editor. /// public partial void FocusTileset(); + + private partial Bounds getBounds(); } } diff --git a/native~/Runtime/src/Cesium3DTilesetImpl.cpp b/native~/Runtime/src/Cesium3DTilesetImpl.cpp index ac95577d..76b5a50b 100644 --- a/native~/Runtime/src/Cesium3DTilesetImpl.cpp +++ b/native~/Runtime/src/Cesium3DTilesetImpl.cpp @@ -4,6 +4,7 @@ #include "UnityPrepareRendererResources.h" #include "UnityTileExcluderAdaptor.h" #include "UnityTilesetExternals.h" +#include "UnityTransforms.h" #include #include @@ -326,6 +327,36 @@ void Cesium3DTilesetImpl::FocusTileset( #endif } +DotNet::UnityEngine::Bounds Cesium3DTilesetImpl::getBounds( + const DotNet::CesiumForUnity::Cesium3DTileset& tileset) { + + // Tileset may not be loaded yet + if (this->_pTileset.get() == nullptr) { + return DotNet::UnityEngine::Bounds::Construct( + DotNet::UnityEngine::Vector3{0, 0, 0}, + DotNet::UnityEngine::Vector3{0, 0, 0}); + } + + // root tile may not be loaded yet + Tile* rootTile = this->_pTileset->getRootTile(); + if (rootTile == nullptr) { + return DotNet::UnityEngine::Bounds::Construct( + DotNet::UnityEngine::Vector3{ 0, 0, 0 }, + DotNet::UnityEngine::Vector3{ 0, 0, 0 }); + } + + const BoundingVolume& bv = rootTile->getBoundingVolume(); + CesiumGeometry::OrientedBoundingBox obb = + getOrientedBoundingBoxFromBoundingVolume(bv); + CesiumGeometry::AxisAlignedBox aabb = obb.toAxisAligned(); + return DotNet::UnityEngine::Bounds::Construct( + UnityTransforms::toUnity(aabb.center), + DotNet::UnityEngine::Vector3{ + float(aabb.lengthX), + float(aabb.lengthY), + float(aabb.lengthZ)}); +} + Tileset* Cesium3DTilesetImpl::getTileset() { return this->_pTileset.get(); } const Tileset* Cesium3DTilesetImpl::getTileset() const { diff --git a/native~/Runtime/src/Cesium3DTilesetImpl.h b/native~/Runtime/src/Cesium3DTilesetImpl.h index 8e0a1d52..67d08db5 100644 --- a/native~/Runtime/src/Cesium3DTilesetImpl.h +++ b/native~/Runtime/src/Cesium3DTilesetImpl.h @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -40,6 +41,9 @@ class Cesium3DTilesetImpl { void RecreateTileset(const DotNet::CesiumForUnity::Cesium3DTileset& tileset); void FocusTileset(const DotNet::CesiumForUnity::Cesium3DTileset& tileset); + DotNet::UnityEngine::Bounds getBounds( + const DotNet::CesiumForUnity::Cesium3DTileset& tileset); + Cesium3DTilesSelection::Tileset* getTileset(); const Cesium3DTilesSelection::Tileset* getTileset() const;