Skip to content

Commit

Permalink
Merge pull request #734 from CesiumGS/more-ellipsoid-fixes
Browse files Browse the repository at this point in the history
More custom ellipsoid fixes
  • Loading branch information
lilleyse authored Oct 1, 2024
2 parents e9a4bd0 + c0ea82e commit dab0d0d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 40 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ if(CESIUM_OMNI_ENABLE_TRACING)
endif()

set(CESIUM_OMNI_CXX_DEFINES ${CESIUM_OMNI_CXX_DEFINES} CESIUM_OMNI_VERSION="${PROJECT_VERSION}")
set(CESIUM_OMNI_CXX_DEFINES ${CESIUM_OMNI_CXX_DEFINES} CESIUM_DISABLE_DEFAULT_ELLIPSOID)

# Add a define CESIUM_OMNI_GIT_HASH_ABBREVIATED
execute_process(
Expand Down
3 changes: 2 additions & 1 deletion src/core/include/cesium/omniverse/OmniRasterOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ class OmniRasterOverlay {

protected:
[[nodiscard]] virtual CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const = 0;
[[nodiscard]] const CesiumGeospatial::Ellipsoid& getEllipsoid() const;

Context* _pContext;
pxr::SdfPath _path;

private:
[[nodiscard]] const CesiumGeospatial::Ellipsoid* getEllipsoid() const;
void setRasterOverlayOptionsFromUsd(CesiumRasterOverlays::RasterOverlayOptions& options) const;
};
} // namespace cesium::omniverse
2 changes: 1 addition & 1 deletion src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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]] const CesiumGeospatial::Ellipsoid& getEllipsoid() const;

[[nodiscard]] TilesetSourceType getSourceType() const;
[[nodiscard]] std::string getUrl() const;
Expand Down
3 changes: 2 additions & 1 deletion src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ Cesium3DTilesSelection::ViewState computeViewState(
const Context& context,
const pxr::SdfPath& georeferencePath,
const pxr::SdfPath& primPath,
const Viewport& viewport);
const Viewport& viewport,
const CesiumGeospatial::Ellipsoid& ellipsoid);

bool primExists(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isSchemaValid(const pxr::UsdSchemaBase& schema);
Expand Down
22 changes: 5 additions & 17 deletions src/core/src/OmniRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,9 @@ FabricOverlayRenderMethod OmniRasterOverlay::getOverlayRenderMethod() const {
CesiumRasterOverlays::RasterOverlayOptions OmniRasterOverlay::createRasterOverlayOptions() const {
CesiumRasterOverlays::RasterOverlayOptions options;
options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets();
options.ellipsoid = getEllipsoid();
setRasterOverlayOptionsFromUsd(options);

const auto pEllipsoid = getEllipsoid();

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

return options;
}

Expand All @@ -134,23 +129,16 @@ void OmniRasterOverlay::updateRasterOverlayOptions() const {
}
}

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

const CesiumGeospatial::Ellipsoid& OmniRasterOverlay::getEllipsoid() const {
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;
}
// Just use the first tileset's ellipsoid
return pTileset->getEllipsoid();
}
}

return maybeEllipsoid.value_or(nullptr);
return CesiumGeospatial::Ellipsoid::WGS84;
}

void OmniRasterOverlay::setRasterOverlayOptionsFromUsd(CesiumRasterOverlays::RasterOverlayOptions& options) const {
Expand Down
2 changes: 2 additions & 0 deletions src/core/src/OmniTileMapServiceRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void OmniTileMapServiceRasterOverlay::reload() {
tmsOptions.maximumLevel = getMaximumZoomLevel();
}

tmsOptions.ellipsoid = getEllipsoid();

_pTileMapServiceRasterOverlay = new CesiumRasterOverlays::TileMapServiceRasterOverlay(
rasterOverlayName, getUrl(), std::vector<CesiumAsync::IAssetAccessor::THeader>(), tmsOptions, options);
}
Expand Down
21 changes: 9 additions & 12 deletions src/core/src/OmniTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ TilesetStatistics OmniTileset::getStatistics() const {
return statistics;
}

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

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

return &pGeoreference->getEllipsoid();
return pGeoreference->getEllipsoid();
}

TilesetSourceType OmniTileset::getSourceType() const {
Expand Down Expand Up @@ -564,12 +564,7 @@ void OmniTileset::reload() {
options.culledScreenSpaceError = getCulledScreenSpaceError();
options.mainThreadLoadingTimeLimit = getMainThreadLoadingTimeLimit();
options.showCreditsOnScreen = getShowCreditsOnScreen();

const auto pEllipsoid = getEllipsoid();

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

options.loadErrorCallback =
[this, tilesetPath, ionAssetId, name](const Cesium3DTilesSelection::TilesetLoadFailureDetails& error) {
Expand Down Expand Up @@ -725,7 +720,8 @@ void OmniTileset::updateView(const gsl::span<const Viewport>& viewports, bool wa

_viewStates.clear();
for (const auto& viewport : viewports) {
_viewStates.push_back(UsdUtil::computeViewState(*_pContext, georeferencePath, _path, viewport));
_viewStates.push_back(
UsdUtil::computeViewState(*_pContext, georeferencePath, _path, viewport, getEllipsoid()));
}

if (waitForLoadingTiles) {
Expand Down Expand Up @@ -786,7 +782,8 @@ bool OmniTileset::updateExtent() {
}

const auto& boundingVolume = pRootTile->getBoundingVolume();
const auto ecefObb = Cesium3DTilesSelection::getOrientedBoundingBoxFromBoundingVolume(boundingVolume);
const auto ecefObb =
Cesium3DTilesSelection::getOrientedBoundingBoxFromBoundingVolume(boundingVolume, getEllipsoid());
const auto georeferencePath = getResolvedGeoreferencePath();
const auto ecefToStageTransform = UsdUtil::computeEcefToStageTransform(*_pContext, georeferencePath);
const auto primObb = ecefObb.transform(ecefToStageTransform);
Expand Down
1 change: 1 addition & 0 deletions src/core/src/OmniWebMapServiceRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void OmniWebMapServiceRasterOverlay::reload() {
wmsOptions.layers = layers;
wmsOptions.tileWidth = tileWidth;
wmsOptions.tileHeight = tileHeight;
wmsOptions.ellipsoid = getEllipsoid();

_pWebMapServiceRasterOverlay = new CesiumRasterOverlays::WebMapServiceRasterOverlay(
rasterOverlayName, getBaseUrl(), std::vector<CesiumAsync::IAssetAccessor::THeader>(), wmsOptions, options);
Expand Down
13 changes: 7 additions & 6 deletions src/core/src/OmniWebMapTileServiceRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,22 @@ void OmniWebMapTileServiceRasterOverlay::reload() {
wmtsOptions.maximumLevel = getMaximumZoomLevel();
}

CesiumGeospatial::Projection projection;
const auto& ellipsoid = getEllipsoid();

wmtsOptions.ellipsoid = ellipsoid;

const auto useWebMercatorProjection = getUseWebMercatorProjection();
if (useWebMercatorProjection) {
projection = CesiumGeospatial::WebMercatorProjection();
wmtsOptions.projection = projection;
wmtsOptions.projection = CesiumGeospatial::WebMercatorProjection(ellipsoid);
} else {
projection = CesiumGeospatial::GeographicProjection();
wmtsOptions.projection = projection;
wmtsOptions.projection = CesiumGeospatial::GeographicProjection(ellipsoid);
}

if (getSpecifyTilingScheme()) {
CesiumGeospatial::GlobeRectangle globeRectangle =
CesiumGeospatial::GlobeRectangle::fromDegrees(getWest(), getSouth(), getEast(), getNorth());
CesiumGeometry::Rectangle coverageRectangle =
CesiumGeospatial::projectRectangleSimple(projection, globeRectangle);
CesiumGeospatial::projectRectangleSimple(wmtsOptions.projection.value(), globeRectangle);
wmtsOptions.coverageRectangle = coverageRectangle;
const auto rootTilesX = getRootTilesX();
const auto rootTilesY = getRootTilesY();
Expand Down
5 changes: 3 additions & 2 deletions src/core/src/UsdUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ Cesium3DTilesSelection::ViewState computeViewState(
const Context& context,
const pxr::SdfPath& georeferencePath,
const pxr::SdfPath& primPath,
const Viewport& viewport) {
const Viewport& viewport,
const CesiumGeospatial::Ellipsoid& ellipsoid) {
const auto& viewMatrix = viewport.viewMatrix;
const auto& projMatrix = viewport.projMatrix;
const auto width = viewport.width;
Expand All @@ -239,7 +240,7 @@ Cesium3DTilesSelection::ViewState computeViewState(
const auto horizontalFov = 2.0 * glm::atan(glm::tan(verticalFov * 0.5) * aspect);

return Cesium3DTilesSelection::ViewState::create(
cameraPosition, cameraFwd, cameraUp, glm::dvec2(width, height), horizontalFov, verticalFov);
cameraPosition, cameraFwd, cameraUp, glm::dvec2(width, height), horizontalFov, verticalFov, ellipsoid);
}

bool primExists(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
Expand Down

0 comments on commit dab0d0d

Please sign in to comment.