Skip to content

Commit

Permalink
Merge pull request #732 from CesiumGS/ellipsoid-2
Browse files Browse the repository at this point in the history
Pass custom ellipsoid to tileset and raster overlays
  • Loading branch information
corybarr authored Sep 25, 2024
2 parents aaf0696 + c592aee commit 52300c2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

### v0.23.0 - 2024-10-01

* Fixed bug where tilesets and raster overlays were not being passed the correct custom ellipsoid.

### v0.22.0 - 2024-09-03

* Cesium for Omniverse now supports using non-WGS84 ellipsoids.
Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/OmniRasterOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OmniRasterOverlay {
pxr::SdfPath _path;

private:
[[nodiscard]] const CesiumGeospatial::Ellipsoid* getEllipsoid() const;
void setRasterOverlayOptionsFromUsd(CesiumRasterOverlays::RasterOverlayOptions& options) const;
};
} // namespace cesium::omniverse
5 changes: 5 additions & 0 deletions src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace CesiumRasterOverlays {
class RasterOverlay;
}

namespace CesiumGeospatial {
class Ellipsoid;
}

namespace CesiumGltf {
struct Model;
}
Expand Down Expand Up @@ -50,6 +54,7 @@ class OmniTileset {
[[nodiscard]] const pxr::SdfPath& getPath() const;
[[nodiscard]] int64_t getTilesetId() const;
[[nodiscard]] TilesetStatistics getStatistics() const;
[[nodiscard]] const CesiumGeospatial::Ellipsoid* getEllipsoid() const;

[[nodiscard]] TilesetSourceType getSourceType() const;
[[nodiscard]] std::string getUrl() const;
Expand Down
27 changes: 27 additions & 0 deletions src/core/src/OmniRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cesium/omniverse/OmniIonServer.h"
#include "cesium/omniverse/UsdUtil.h"

#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumIonClient/Token.h>
#include <CesiumUsdSchemas/rasterOverlay.h>

Expand Down Expand Up @@ -116,6 +117,13 @@ CesiumRasterOverlays::RasterOverlayOptions OmniRasterOverlay::createRasterOverla
CesiumRasterOverlays::RasterOverlayOptions options;
options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets();
setRasterOverlayOptionsFromUsd(options);

const auto pEllipsoid = getEllipsoid();

if (pEllipsoid) {
options.ellipsoid = *pEllipsoid;
}

return options;
}

Expand All @@ -126,6 +134,25 @@ void OmniRasterOverlay::updateRasterOverlayOptions() const {
}
}

const CesiumGeospatial::Ellipsoid* OmniRasterOverlay::getEllipsoid() const {
std::optional<const CesiumGeospatial::Ellipsoid*> maybeEllipsoid;

const auto& tilesets = _pContext->getAssetRegistry().getTilesets();
for (const auto& pTileset : tilesets) {
if (CppUtil::contains(pTileset->getRasterOverlayPaths(), _path)) {
const auto pEllipsoid = pTileset->getEllipsoid();
if (!maybeEllipsoid) {
maybeEllipsoid = pEllipsoid;
} else if (*maybeEllipsoid != pEllipsoid) {
// If not all tilesets that reference this raster overlay use the same ellipsoid then set it to nullptr
return nullptr;
}
}
}

return maybeEllipsoid.value_or(nullptr);
}

void OmniRasterOverlay::setRasterOverlayOptionsFromUsd(CesiumRasterOverlays::RasterOverlayOptions& options) const {
options.showCreditsOnScreen = getShowCreditsOnScreen();
options.maximumScreenSpaceError = getMaximumScreenSpaceError();
Expand Down
21 changes: 21 additions & 0 deletions src/core/src/OmniTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <Cesium3DTilesSelection/Tileset.h>
#include <Cesium3DTilesSelection/ViewState.h>
#include <Cesium3DTilesSelection/ViewUpdateResult.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumUsdSchemas/rasterOverlay.h>
#include <CesiumUsdSchemas/tileset.h>
#include <pxr/usd/usd/prim.h>
Expand Down Expand Up @@ -106,6 +107,20 @@ TilesetStatistics OmniTileset::getStatistics() const {
return statistics;
}

const CesiumGeospatial::Ellipsoid* OmniTileset::getEllipsoid() const {
const auto georeferencePath = getResolvedGeoreferencePath();
if (georeferencePath.IsEmpty()) {
return nullptr;
}

const auto pGeoreference = _pContext->getAssetRegistry().getGeoreference(georeferencePath);
if (!pGeoreference) {
return nullptr;
}

return &pGeoreference->getEllipsoid();
}

TilesetSourceType OmniTileset::getSourceType() const {
const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumTileset)) {
Expand Down Expand Up @@ -550,6 +565,12 @@ void OmniTileset::reload() {
options.mainThreadLoadingTimeLimit = getMainThreadLoadingTimeLimit();
options.showCreditsOnScreen = getShowCreditsOnScreen();

const auto pEllipsoid = getEllipsoid();

if (pEllipsoid) {
options.ellipsoid = *pEllipsoid;
}

options.loadErrorCallback =
[this, tilesetPath, ionAssetId, name](const Cesium3DTilesSelection::TilesetLoadFailureDetails& error) {
// Check for a 401 connecting to Cesium ion, which means the token is invalid
Expand Down
27 changes: 20 additions & 7 deletions src/core/src/UsdNotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ void updateGlobeAnchorBindings(const Context& context, const pxr::SdfPath& globe
}
}

void updateGeoreferenceBindings(const Context& context) {
// Don't need to update tilesets. Georeference changes are handled automatically in the update loop.
void updateGeoreferenceBindings(const Context& context, bool reloadTilesets) {
// reloadTilesets is only true if the ellipsoid changed (or may have changed).
// Other georeference changes are handled automatically in the update loop.
if (reloadTilesets) {
// Update all tilesets. Some tilesets may have referenced this georeference implicitly.
const auto& tilesets = context.getAssetRegistry().getTilesets();
for (const auto& pTileset : tilesets) {
pTileset->reload();
}
}

// Update all globe anchors. Some globe anchors may have referenced this georeference implicitly.
const auto& globeAnchors = context.getAssetRegistry().getGlobeAnchors();
Expand All @@ -118,7 +126,7 @@ void updateEllipsoidBindings(const Context& context, const pxr::SdfPath& ellipso
for (const auto& pGeoreference : georeferences) {
if (pGeoreference->getEllipsoidPath() == ellipsoidPath) {
pGeoreference->update();
updateGeoreferenceBindings(context);
updateGeoreferenceBindings(context, true);
}
}
}
Expand Down Expand Up @@ -164,7 +172,7 @@ bool isFirstData(const Context& context, const pxr::SdfPath& dataPath) {
}

if (updateGeoreference) {
updateGeoreferenceBindings(context);
updateGeoreferenceBindings(context, true);
}

return reloadStage;
Expand Down Expand Up @@ -577,6 +585,7 @@ void processCesiumGeoreferenceChanged(

auto updateGeoreference = false;
auto updateBindings = false;
auto reloadTilesets = false;

// clang-format off
for (const auto& property : properties) {
Expand All @@ -585,6 +594,10 @@ void processCesiumGeoreferenceChanged(
property == pxr::CesiumTokens->cesiumGeoreferenceOriginHeight) {
updateGeoreference = true;
updateBindings = true;
} else if (property == pxr::CesiumTokens->cesiumEllipsoidBinding) {
updateGeoreference = true;
updateBindings = true;
reloadTilesets = true;
}
}
// clang-format on
Expand All @@ -594,7 +607,7 @@ void processCesiumGeoreferenceChanged(
}

if (updateBindings) {
updateGeoreferenceBindings(context);
updateGeoreferenceBindings(context, reloadTilesets);
}
}

Expand Down Expand Up @@ -761,7 +774,7 @@ void processCesiumWebMapTileServiceRasterOverlayRemoved(

void processCesiumGeoreferenceRemoved(Context& context, const pxr::SdfPath& georeferencePath) {
context.getAssetRegistry().removeGeoreference(georeferencePath);
updateGeoreferenceBindings(context);
updateGeoreferenceBindings(context, true);
}

void processCesiumGlobeAnchorRemoved(Context& context, const pxr::SdfPath& globeAnchorPath) {
Expand Down Expand Up @@ -876,7 +889,7 @@ void processCesiumGeoreferenceAdded(Context& context, const pxr::SdfPath& georef
}

context.getAssetRegistry().addGeoreference(georeferencePath);
updateGeoreferenceBindings(context);
updateGeoreferenceBindings(context, true);
}

void processCesiumIonServerAdded(Context& context, const pxr::SdfPath& ionServerPath) {
Expand Down

0 comments on commit 52300c2

Please sign in to comment.