Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bounds property for tileset #345

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Runtime/Cesium3DTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,17 @@ public bool createPhysicsMeshes
}
}

/// <summary>
/// Gets the axis-aligned bounding box of the root tile of this tileset.
/// </summary>
public Bounds bounds
{
get
{
return getBounds();
}
}

private partial void SetShowCreditsOnScreen(bool value);

private partial void Start();
Expand All @@ -669,5 +680,7 @@ public bool createPhysicsMeshes
/// Zoom the Editor camera to this tileset. This method does nothing outside of the Editor.
/// </summary>
public partial void FocusTileset();

private partial Bounds getBounds();
}
}
31 changes: 31 additions & 0 deletions native~/Runtime/src/Cesium3DTilesetImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "UnityPrepareRendererResources.h"
#include "UnityTileExcluderAdaptor.h"
#include "UnityTilesetExternals.h"
#include "UnityTransforms.h"

#include <Cesium3DTilesSelection/IonRasterOverlay.h>
#include <Cesium3DTilesSelection/Tileset.h>
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions native~/Runtime/src/Cesium3DTilesetImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <DotNet/CesiumForUnity/CesiumCreditSystem.h>
#include <DotNet/CesiumForUnity/CesiumGeoreference.h>
#include <DotNet/System/Action.h>
#include <DotNet/UnityEngine/Bounds.h>

#include <memory>

Expand Down Expand Up @@ -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;

Expand Down