diff --git a/CHANGES.md b/CHANGES.md index 11cee649..4fb4331e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ * Fixed crash when updating tilesets shader inputs. * Fixed crash when setting certain `/Cesium` debug options at runtime. * Fixed crash when disabling and re-enabling the extension. +* Fixed crash when removing USD prims in certain order. +* Fixed issue where Cesium ion session would not resume on reload. * The movie capture tool now waits for tilesets to complete loading before it captures a frame. ### v0.17.0 - 2024-02-01 diff --git a/src/core/include/cesium/omniverse/UsdUtil.h b/src/core/include/cesium/omniverse/UsdUtil.h index f3fb55ed..3e9c5c71 100644 --- a/src/core/include/cesium/omniverse/UsdUtil.h +++ b/src/core/include/cesium/omniverse/UsdUtil.h @@ -91,6 +91,8 @@ Cesium3DTilesSelection::ViewState computeViewState( const Viewport& viewport); bool primExists(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); +bool isSchemaValid(const pxr::UsdSchemaBase& schema); + bool isPrimVisible(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); const std::string& getName(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); diff --git a/src/core/src/OmniCartographicPolygon.cpp b/src/core/src/OmniCartographicPolygon.cpp index 7bc692de..16978dfd 100644 --- a/src/core/src/OmniCartographicPolygon.cpp +++ b/src/core/src/OmniCartographicPolygon.cpp @@ -38,6 +38,9 @@ std::vector OmniCartographicPolygon::getCartogra } const auto cesiumCartographicPolygon = UsdUtil::getCesiumCartographicPolygon(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumCartographicPolygon)) { + return {}; + } pxr::VtArray points; cesiumCartographicPolygon.GetPointsAttr().Get(&points); diff --git a/src/core/src/OmniData.cpp b/src/core/src/OmniData.cpp index 02bc5941..6954a554 100644 --- a/src/core/src/OmniData.cpp +++ b/src/core/src/OmniData.cpp @@ -17,6 +17,9 @@ const pxr::SdfPath& OmniData::getPath() const { pxr::SdfPath OmniData::getSelectedIonServerPath() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return {}; + } pxr::SdfPathVector targets; cesiumData.GetSelectedIonServerRel().GetForwardedTargets(&targets); @@ -30,6 +33,9 @@ pxr::SdfPath OmniData::getSelectedIonServerPath() const { bool OmniData::getDebugDisableMaterials() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool disableMaterials; cesiumData.GetDebugDisableMaterialsAttr().Get(&disableMaterials); @@ -39,6 +45,9 @@ bool OmniData::getDebugDisableMaterials() const { bool OmniData::getDebugDisableTextures() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool disableTextures; cesiumData.GetDebugDisableTexturesAttr().Get(&disableTextures); @@ -48,6 +57,9 @@ bool OmniData::getDebugDisableTextures() const { bool OmniData::getDebugDisableGeometryPool() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool disableGeometryPool; cesiumData.GetDebugDisableGeometryPoolAttr().Get(&disableGeometryPool); @@ -57,6 +69,9 @@ bool OmniData::getDebugDisableGeometryPool() const { bool OmniData::getDebugDisableMaterialPool() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool disableMaterialPool; cesiumData.GetDebugDisableMaterialPoolAttr().Get(&disableMaterialPool); @@ -66,6 +81,9 @@ bool OmniData::getDebugDisableMaterialPool() const { bool OmniData::getDebugDisableTexturePool() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool disableTexturePool; cesiumData.GetDebugDisableTexturePoolAttr().Get(&disableTexturePool); @@ -75,6 +93,9 @@ bool OmniData::getDebugDisableTexturePool() const { uint64_t OmniData::getDebugGeometryPoolInitialCapacity() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return 2048; + } uint64_t geometryPoolInitialCapacity; cesiumData.GetDebugGeometryPoolInitialCapacityAttr().Get(&geometryPoolInitialCapacity); @@ -84,6 +105,9 @@ uint64_t OmniData::getDebugGeometryPoolInitialCapacity() const { uint64_t OmniData::getDebugMaterialPoolInitialCapacity() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return 2048; + } uint64_t materialPoolInitialCapacity; cesiumData.GetDebugMaterialPoolInitialCapacityAttr().Get(&materialPoolInitialCapacity); @@ -93,6 +117,9 @@ uint64_t OmniData::getDebugMaterialPoolInitialCapacity() const { uint64_t OmniData::getDebugTexturePoolInitialCapacity() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return 2048; + } uint64_t texturePoolInitialCapacity; cesiumData.GetDebugTexturePoolInitialCapacityAttr().Get(&texturePoolInitialCapacity); @@ -102,6 +129,9 @@ uint64_t OmniData::getDebugTexturePoolInitialCapacity() const { bool OmniData::getDebugRandomColors() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool debugRandomColors; cesiumData.GetDebugRandomColorsAttr().Get(&debugRandomColors); @@ -111,6 +141,9 @@ bool OmniData::getDebugRandomColors() const { bool OmniData::getDebugDisableGeoreferencing() const { const auto cesiumData = UsdUtil::getCesiumData(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumData)) { + return false; + } bool debugDisableGeoreferencing; cesiumData.GetDebugDisableGeoreferencingAttr().Get(&debugDisableGeoreferencing); diff --git a/src/core/src/OmniGeoreference.cpp b/src/core/src/OmniGeoreference.cpp index 32ef5c6e..a539c62e 100644 --- a/src/core/src/OmniGeoreference.cpp +++ b/src/core/src/OmniGeoreference.cpp @@ -22,6 +22,9 @@ const pxr::SdfPath& OmniGeoreference::getPath() const { CesiumGeospatial::Cartographic OmniGeoreference::getOrigin() const { const auto cesiumGeoreference = UsdUtil::getCesiumGeoreference(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGeoreference)) { + return {0.0, 0.0, 0.0}; + } double longitude; double latitude; diff --git a/src/core/src/OmniGlobeAnchor.cpp b/src/core/src/OmniGlobeAnchor.cpp index c9337196..4b11f3c5 100644 --- a/src/core/src/OmniGlobeAnchor.cpp +++ b/src/core/src/OmniGlobeAnchor.cpp @@ -49,6 +49,9 @@ const pxr::SdfPath& OmniGlobeAnchor::getPath() const { bool OmniGlobeAnchor::getDetectTransformChanges() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return true; + } bool detectTransformChanges; cesiumGlobeAnchor.GetDetectTransformChangesAttr().Get(&detectTransformChanges); @@ -58,6 +61,9 @@ bool OmniGlobeAnchor::getDetectTransformChanges() const { bool OmniGlobeAnchor::getAdjustOrientation() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return true; + } bool adjustOrientation; cesiumGlobeAnchor.GetAdjustOrientationForGlobeWhenMovingAttr().Get(&adjustOrientation); @@ -67,6 +73,9 @@ bool OmniGlobeAnchor::getAdjustOrientation() const { pxr::SdfPath OmniGlobeAnchor::getResolvedGeoreferencePath() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return {}; + } pxr::SdfPathVector targets; cesiumGlobeAnchor.GetGeoreferenceBindingRel().GetForwardedTargets(&targets); @@ -158,7 +167,7 @@ void OmniGlobeAnchor::updateByPrimLocalTransform(bool resetOrientation) { } const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable); const auto eulerAngleOrder = xformOps->eulerAngleOrder; @@ -202,7 +211,11 @@ bool OmniGlobeAnchor::isAnchorValid() const { } const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); + if (!UsdUtil::isSchemaValid(xformable)) { + return false; + } + const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable); if (!xformOps) { @@ -229,7 +242,10 @@ void OmniGlobeAnchor::initialize() { // when using globe anchors. const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); + if (!UsdUtil::isSchemaValid(xformable)) { + return; + } bool resetsXformStack; const auto originalXformOps = xformable.GetOrderedXformOps(&resetsXformStack); @@ -268,6 +284,9 @@ void OmniGlobeAnchor::finalize() { glm::dvec3 OmniGlobeAnchor::getPrimLocalToEcefTranslation() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return {0.0, 0.0, 0.0}; + } pxr::GfVec3d primLocalToEcefTranslation; cesiumGlobeAnchor.GetPositionAttr().Get(&primLocalToEcefTranslation); @@ -277,6 +296,9 @@ glm::dvec3 OmniGlobeAnchor::getPrimLocalToEcefTranslation() const { CesiumGeospatial::Cartographic OmniGlobeAnchor::getGeographicCoordinates() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return {0.0, 0.0, 0.0}; + } double longitude; double latitude; @@ -291,36 +313,57 @@ CesiumGeospatial::Cartographic OmniGlobeAnchor::getGeographicCoordinates() const glm::dvec3 OmniGlobeAnchor::getPrimLocalTranslation() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); + if (!UsdUtil::isSchemaValid(xformable)) { + return {0.0, 0.0, 0.0}; + } + const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable); return UsdUtil::getTranslate(xformOps.value().translateOp); } glm::dvec3 OmniGlobeAnchor::getPrimLocalRotation() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); + if (!UsdUtil::isSchemaValid(xformable)) { + return {0.0, 0.0, 0.0}; + } + const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable); return glm::radians(UsdUtil::getRotate(xformOps.value().rotateOp)); } glm::dvec3 OmniGlobeAnchor::getPrimLocalScale() const { const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); + if (!UsdUtil::isSchemaValid(xformable)) { + return {1.0, 1.0, 1.0}; + } + const auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable); return UsdUtil::getScale(xformOps.value().scaleOp); } void OmniGlobeAnchor::savePrimLocalToEcefTranslation() { + const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return; + } + const auto& primLocalToEcefTransform = _pAnchor->getAnchorToFixedTransform(); const auto primLocalToEcefTranslation = glm::dvec3(primLocalToEcefTransform[3]); _cachedPrimLocalToEcefTranslation = primLocalToEcefTranslation; - const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); cesiumGlobeAnchor.GetPositionAttr().Set(UsdUtil::glmToUsdVector(primLocalToEcefTranslation)); } void OmniGlobeAnchor::saveGeographicCoordinates() { + const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumGlobeAnchor)) { + return; + } + const auto pGeoreference = _pContext->getAssetRegistry().getGeoreference(getResolvedGeoreferencePath()); const auto& primLocalToEcefTransform = _pAnchor->getAnchorToFixedTransform(); const auto primLocalToEcefTranslation = glm::dvec3(primLocalToEcefTransform[3]); @@ -332,7 +375,6 @@ void OmniGlobeAnchor::saveGeographicCoordinates() { _cachedGeographicCoordinates = *cartographic; - const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); cesiumGlobeAnchor.GetAnchorLongitudeAttr().Set(glm::degrees(cartographic->longitude)); cesiumGlobeAnchor.GetAnchorLatitudeAttr().Set(glm::degrees(cartographic->latitude)); cesiumGlobeAnchor.GetAnchorHeightAttr().Set(cartographic->height); @@ -343,7 +385,11 @@ void OmniGlobeAnchor::savePrimLocalTransform() { // work when rotation and scale properties are double precision, which is common in Omniverse. const auto cesiumGlobeAnchor = UsdUtil::getCesiumGlobeAnchor(_pContext->getUsdStage(), _path); - const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor.GetPrim()); + const auto xformable = pxr::UsdGeomXformable(cesiumGlobeAnchor); + if (!UsdUtil::isSchemaValid(xformable)) { + return; + } + auto xformOps = UsdUtil::getOrCreateTranslateRotateScaleOps(xformable); auto& [translateOp, rotateOp, scaleOp, eulerAngleOrder] = xformOps.value(); diff --git a/src/core/src/OmniIonRasterOverlay.cpp b/src/core/src/OmniIonRasterOverlay.cpp index ef8564f8..14e18e5f 100644 --- a/src/core/src/OmniIonRasterOverlay.cpp +++ b/src/core/src/OmniIonRasterOverlay.cpp @@ -25,6 +25,9 @@ OmniIonRasterOverlay::OmniIonRasterOverlay(Context* pContext, const pxr::SdfPath int64_t OmniIonRasterOverlay::getIonAssetId() const { const auto cesiumIonRasterOverlay = UsdUtil::getCesiumIonRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonRasterOverlay)) { + return 0; + } int64_t ionAssetId; cesiumIonRasterOverlay.GetIonAssetIdAttr().Get(&ionAssetId); @@ -34,6 +37,9 @@ int64_t OmniIonRasterOverlay::getIonAssetId() const { CesiumIonClient::Token OmniIonRasterOverlay::getIonAccessToken() const { const auto cesiumIonRasterOverlay = UsdUtil::getCesiumIonRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonRasterOverlay)) { + return {}; + } std::string ionAccessToken; cesiumIonRasterOverlay.GetIonAccessTokenAttr().Get(&ionAccessToken); @@ -77,6 +83,9 @@ std::string OmniIonRasterOverlay::getIonApiUrl() const { pxr::SdfPath OmniIonRasterOverlay::getResolvedIonServerPath() const { const auto cesiumIonRasterOverlay = UsdUtil::getCesiumIonRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonRasterOverlay)) { + return {}; + } pxr::SdfPathVector targets; cesiumIonRasterOverlay.GetIonServerBindingRel().GetForwardedTargets(&targets); diff --git a/src/core/src/OmniIonServer.cpp b/src/core/src/OmniIonServer.cpp index 47a4b06a..44db3533 100644 --- a/src/core/src/OmniIonServer.cpp +++ b/src/core/src/OmniIonServer.cpp @@ -17,7 +17,9 @@ OmniIonServer::OmniIonServer(Context* pContext, const pxr::SdfPath& path) pContext->getHttpAssetAccessor(), getIonServerUrl(), getIonServerApiUrl(), - getIonServerApplicationId())) {} + getIonServerApplicationId())) { + _session->resume(); +} const pxr::SdfPath& OmniIonServer::getPath() const { return _path; @@ -29,6 +31,9 @@ std::shared_ptr OmniIonServer::getSession() const { std::string OmniIonServer::getIonServerUrl() const { const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonServer)) { + return ""; + } std::string ionServerUrl; cesiumIonServer.GetIonServerUrlAttr().Get(&ionServerUrl); @@ -38,6 +43,9 @@ std::string OmniIonServer::getIonServerUrl() const { std::string OmniIonServer::getIonServerApiUrl() const { const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonServer)) { + return ""; + } std::string ionServerApiUrl; cesiumIonServer.GetIonServerApiUrlAttr().Get(&ionServerApiUrl); @@ -47,6 +55,9 @@ std::string OmniIonServer::getIonServerApiUrl() const { int64_t OmniIonServer::getIonServerApplicationId() const { const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonServer)) { + return 0; + } int64_t ionServerApplicationId; cesiumIonServer.GetIonServerApplicationIdAttr().Get(&ionServerApplicationId); @@ -56,6 +67,9 @@ int64_t OmniIonServer::getIonServerApplicationId() const { CesiumIonClient::Token OmniIonServer::getToken() const { const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonServer)) { + return {}; + } std::string projectDefaultIonAccessToken; std::string projectDefaultIonAccessTokenId; @@ -72,6 +86,9 @@ CesiumIonClient::Token OmniIonServer::getToken() const { void OmniIonServer::setToken(const CesiumIonClient::Token& token) { const auto cesiumIonServer = UsdUtil::getCesiumIonServer(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumIonServer)) { + return; + } cesiumIonServer.GetProjectDefaultIonAccessTokenAttr().Set(token.token); cesiumIonServer.GetProjectDefaultIonAccessTokenIdAttr().Set(token.id); diff --git a/src/core/src/OmniPolygonRasterOverlay.cpp b/src/core/src/OmniPolygonRasterOverlay.cpp index 1b6a6de9..5454196a 100644 --- a/src/core/src/OmniPolygonRasterOverlay.cpp +++ b/src/core/src/OmniPolygonRasterOverlay.cpp @@ -20,6 +20,9 @@ OmniPolygonRasterOverlay::OmniPolygonRasterOverlay(Context* pContext, const pxr: std::vector OmniPolygonRasterOverlay::getCartographicPolygonPaths() const { const auto cesiumPolygonRasterOverlay = UsdUtil::getCesiumPolygonRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumPolygonRasterOverlay)) { + return {}; + } pxr::SdfPathVector targets; cesiumPolygonRasterOverlay.GetCartographicPolygonBindingRel().GetForwardedTargets(&targets); @@ -32,7 +35,11 @@ CesiumRasterOverlays::RasterOverlay* OmniPolygonRasterOverlay::getRasterOverlay( } bool OmniPolygonRasterOverlay::getInvertSelection() const { - auto cesiumPolygonRasterOverlay = UsdUtil::getCesiumPolygonRasterOverlay(_pContext->getUsdStage(), _path); + const auto cesiumPolygonRasterOverlay = UsdUtil::getCesiumPolygonRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumPolygonRasterOverlay)) { + return false; + } + bool invertSelection; cesiumPolygonRasterOverlay.GetInvertSelectionAttr().Get(&invertSelection); return invertSelection; diff --git a/src/core/src/OmniRasterOverlay.cpp b/src/core/src/OmniRasterOverlay.cpp index 1f88958f..84a06c05 100644 --- a/src/core/src/OmniRasterOverlay.cpp +++ b/src/core/src/OmniRasterOverlay.cpp @@ -22,6 +22,9 @@ const pxr::SdfPath& OmniRasterOverlay::getPath() const { bool OmniRasterOverlay::getShowCreditsOnScreen() const { const auto cesiumRasterOverlay = UsdUtil::getCesiumRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumRasterOverlay)) { + return false; + } bool showCreditsOnScreen; cesiumRasterOverlay.GetShowCreditsOnScreenAttr().Get(&showCreditsOnScreen); @@ -31,6 +34,9 @@ bool OmniRasterOverlay::getShowCreditsOnScreen() const { double OmniRasterOverlay::getAlpha() const { const auto cesiumRasterOverlay = UsdUtil::getCesiumRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumRasterOverlay)) { + return 1.0; + } float alpha; cesiumRasterOverlay.GetAlphaAttr().Get(&alpha); @@ -40,6 +46,9 @@ double OmniRasterOverlay::getAlpha() const { FabricOverlayRenderMethod OmniRasterOverlay::getOverlayRenderMethod() const { const auto cesiumRasterOverlay = UsdUtil::getCesiumRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumRasterOverlay)) { + return FabricOverlayRenderMethod::OVERLAY; + } pxr::TfToken overlayRenderMethod; cesiumRasterOverlay.GetOverlayRenderMethodAttr().Get(&overlayRenderMethod); diff --git a/src/core/src/OmniTileset.cpp b/src/core/src/OmniTileset.cpp index 98cf5abd..6c10d416 100644 --- a/src/core/src/OmniTileset.cpp +++ b/src/core/src/OmniTileset.cpp @@ -108,6 +108,9 @@ TilesetStatistics OmniTileset::getStatistics() const { TilesetSourceType OmniTileset::getSourceType() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return TilesetSourceType::ION; + } pxr::TfToken sourceType; cesiumTileset.GetSourceTypeAttr().Get(&sourceType); @@ -121,6 +124,9 @@ TilesetSourceType OmniTileset::getSourceType() const { std::string OmniTileset::getUrl() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return ""; + } std::string url; cesiumTileset.GetUrlAttr().Get(&url); @@ -130,6 +136,9 @@ std::string OmniTileset::getUrl() const { int64_t OmniTileset::getIonAssetId() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 0; + } int64_t ionAssetId; cesiumTileset.GetIonAssetIdAttr().Get(&ionAssetId); @@ -139,6 +148,9 @@ int64_t OmniTileset::getIonAssetId() const { CesiumIonClient::Token OmniTileset::getIonAccessToken() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return {}; + } std::string ionAccessToken; cesiumTileset.GetIonAccessTokenAttr().Get(&ionAccessToken); @@ -182,6 +194,9 @@ std::string OmniTileset::getIonApiUrl() const { pxr::SdfPath OmniTileset::getResolvedIonServerPath() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return {}; + } pxr::SdfPathVector targets; cesiumTileset.GetIonServerBindingRel().GetForwardedTargets(&targets); @@ -201,6 +216,9 @@ pxr::SdfPath OmniTileset::getResolvedIonServerPath() const { double OmniTileset::getMaximumScreenSpaceError() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 16.0; + } float maximumScreenSpaceError; cesiumTileset.GetMaximumScreenSpaceErrorAttr().Get(&maximumScreenSpaceError); @@ -210,6 +228,9 @@ double OmniTileset::getMaximumScreenSpaceError() const { bool OmniTileset::getPreloadAncestors() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return true; + } bool preloadAncestors; cesiumTileset.GetPreloadAncestorsAttr().Get(&preloadAncestors); @@ -219,6 +240,9 @@ bool OmniTileset::getPreloadAncestors() const { bool OmniTileset::getPreloadSiblings() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return true; + } bool preloadSiblings; cesiumTileset.GetPreloadSiblingsAttr().Get(&preloadSiblings); @@ -228,6 +252,9 @@ bool OmniTileset::getPreloadSiblings() const { bool OmniTileset::getForbidHoles() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return false; + } bool forbidHoles; cesiumTileset.GetForbidHolesAttr().Get(&forbidHoles); @@ -237,6 +264,9 @@ bool OmniTileset::getForbidHoles() const { uint32_t OmniTileset::getMaximumSimultaneousTileLoads() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 20; + } uint32_t maximumSimultaneousTileLoads; cesiumTileset.GetMaximumSimultaneousTileLoadsAttr().Get(&maximumSimultaneousTileLoads); @@ -246,6 +276,9 @@ uint32_t OmniTileset::getMaximumSimultaneousTileLoads() const { uint64_t OmniTileset::getMaximumCachedBytes() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 536870912; + } uint64_t maximumCachedBytes; cesiumTileset.GetMaximumCachedBytesAttr().Get(&maximumCachedBytes); @@ -255,6 +288,9 @@ uint64_t OmniTileset::getMaximumCachedBytes() const { uint32_t OmniTileset::getLoadingDescendantLimit() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 20; + } uint32_t loadingDescendantLimit; cesiumTileset.GetLoadingDescendantLimitAttr().Get(&loadingDescendantLimit); @@ -264,6 +300,9 @@ uint32_t OmniTileset::getLoadingDescendantLimit() const { bool OmniTileset::getEnableFrustumCulling() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return true; + } bool enableFrustumCulling; cesiumTileset.GetEnableFrustumCullingAttr().Get(&enableFrustumCulling); @@ -273,6 +312,9 @@ bool OmniTileset::getEnableFrustumCulling() const { bool OmniTileset::getEnableFogCulling() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return true; + } bool enableFogCulling; cesiumTileset.GetEnableFogCullingAttr().Get(&enableFogCulling); @@ -282,6 +324,9 @@ bool OmniTileset::getEnableFogCulling() const { bool OmniTileset::getEnforceCulledScreenSpaceError() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return true; + } bool enforceCulledScreenSpaceError; cesiumTileset.GetEnforceCulledScreenSpaceErrorAttr().Get(&enforceCulledScreenSpaceError); @@ -291,6 +336,9 @@ bool OmniTileset::getEnforceCulledScreenSpaceError() const { double OmniTileset::getMainThreadLoadingTimeLimit() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 0.0; + } float mainThreadLoadingTimeLimit; cesiumTileset.GetMainThreadLoadingTimeLimitAttr().Get(&mainThreadLoadingTimeLimit); @@ -300,6 +348,9 @@ double OmniTileset::getMainThreadLoadingTimeLimit() const { double OmniTileset::getCulledScreenSpaceError() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 64.0; + } float culledScreenSpaceError; cesiumTileset.GetCulledScreenSpaceErrorAttr().Get(&culledScreenSpaceError); @@ -309,6 +360,9 @@ double OmniTileset::getCulledScreenSpaceError() const { bool OmniTileset::getSuspendUpdate() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return false; + } bool suspendUpdate; cesiumTileset.GetSuspendUpdateAttr().Get(&suspendUpdate); @@ -318,6 +372,9 @@ bool OmniTileset::getSuspendUpdate() const { bool OmniTileset::getSmoothNormals() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return false; + } bool smoothNormals; cesiumTileset.GetSmoothNormalsAttr().Get(&smoothNormals); @@ -327,6 +384,9 @@ bool OmniTileset::getSmoothNormals() const { bool OmniTileset::getShowCreditsOnScreen() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return false; + } bool showCreditsOnScreen; cesiumTileset.GetShowCreditsOnScreenAttr().Get(&showCreditsOnScreen); @@ -344,6 +404,9 @@ pxr::SdfPath OmniTileset::getResolvedGeoreferencePath() const { } const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return {}; + } pxr::SdfPathVector targets; cesiumTileset.GetGeoreferenceBindingRel().GetForwardedTargets(&targets); @@ -363,8 +426,11 @@ pxr::SdfPath OmniTileset::getResolvedGeoreferencePath() const { pxr::SdfPath OmniTileset::getMaterialPath() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); - const auto materialBindingApi = pxr::UsdShadeMaterialBindingAPI(cesiumTileset); + if (!UsdUtil::isSchemaValid(materialBindingApi)) { + return {}; + } + const auto materialBinding = materialBindingApi.GetDirectBinding(); const auto& materialPath = materialBinding.GetMaterialPath(); @@ -373,6 +439,9 @@ pxr::SdfPath OmniTileset::getMaterialPath() const { glm::dvec3 OmniTileset::getDisplayColor() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return {1.0, 1.0, 1.0}; + } pxr::VtVec3fArray displayColorArray; cesiumTileset.GetDisplayColorAttr().Get(&displayColorArray); @@ -391,6 +460,9 @@ glm::dvec3 OmniTileset::getDisplayColor() const { double OmniTileset::getDisplayOpacity() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 1.0; + } pxr::VtFloatArray displayOpacityArray; cesiumTileset.GetDisplayOpacityAttr().Get(&displayOpacityArray); @@ -404,6 +476,9 @@ double OmniTileset::getDisplayOpacity() const { std::vector OmniTileset::getRasterOverlayPaths() const { const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return {}; + } pxr::SdfPathVector targets; cesiumTileset.GetRasterOverlayBindingRel().GetForwardedTargets(&targets); @@ -496,7 +571,6 @@ void OmniTileset::reload() { break; } - const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); const auto boundRasterOverlayPaths = getRasterOverlayPaths(); for (const auto& boundRasterOverlayPath : boundRasterOverlayPaths) { @@ -665,6 +739,11 @@ bool OmniTileset::updateExtent() { } const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + const auto boundable = pxr::UsdGeomBoundable(cesiumTileset); + if (!UsdUtil::isSchemaValid(boundable)) { + return false; + } + const auto& boundingVolume = pRootTile->getBoundingVolume(); const auto ecefObb = Cesium3DTilesSelection::getOrientedBoundingBoxFromBoundingVolume(boundingVolume); const auto georeferencePath = getResolvedGeoreferencePath(); @@ -680,7 +759,6 @@ bool OmniTileset::updateExtent() { UsdUtil::glmToUsdVector(glm::fvec3(topRight)), }; - const auto boundable = pxr::UsdGeomBoundable(cesiumTileset); boundable.GetExtentAttr().Set(extent); return true; } diff --git a/src/core/src/OmniWebMapServiceRasterOverlay.cpp b/src/core/src/OmniWebMapServiceRasterOverlay.cpp index 71996b48..b9b124c4 100644 --- a/src/core/src/OmniWebMapServiceRasterOverlay.cpp +++ b/src/core/src/OmniWebMapServiceRasterOverlay.cpp @@ -22,51 +22,75 @@ CesiumRasterOverlays::RasterOverlay* OmniWebMapServiceRasterOverlay::getRasterOv } std::string OmniWebMapServiceRasterOverlay::getBaseUrl() const { - auto cesiumWebMapServiceRasterOverlay = + const auto cesiumWebMapServiceRasterOverlay = UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumWebMapServiceRasterOverlay)) { + return ""; + } + std::string baseUrl; cesiumWebMapServiceRasterOverlay.GetBaseUrlAttr().Get(&baseUrl); return baseUrl; } int OmniWebMapServiceRasterOverlay::getMinimumLevel() const { - auto cesiumWebMapServiceRasterOverlay = + const auto cesiumWebMapServiceRasterOverlay = UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); - int val; - cesiumWebMapServiceRasterOverlay.GetMinimumLevelAttr().Get(&val); - return val; + if (!UsdUtil::isSchemaValid(cesiumWebMapServiceRasterOverlay)) { + return 0; + } + + int minimumLevel; + cesiumWebMapServiceRasterOverlay.GetMinimumLevelAttr().Get(&minimumLevel); + return minimumLevel; } int OmniWebMapServiceRasterOverlay::getMaximumLevel() const { - auto cesiumWebMapServiceRasterOverlay = + const auto cesiumWebMapServiceRasterOverlay = UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); - int val; - cesiumWebMapServiceRasterOverlay.GetMaximumLevelAttr().Get(&val); - return val; + if (!UsdUtil::isSchemaValid(cesiumWebMapServiceRasterOverlay)) { + return 14; + } + + int maximumLevel; + cesiumWebMapServiceRasterOverlay.GetMaximumLevelAttr().Get(&maximumLevel); + return maximumLevel; } int OmniWebMapServiceRasterOverlay::getTileWidth() const { - auto cesiumWebMapServiceRasterOverlay = + const auto cesiumWebMapServiceRasterOverlay = UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); - int val; - cesiumWebMapServiceRasterOverlay.GetTileWidthAttr().Get(&val); - return val; + if (!UsdUtil::isSchemaValid(cesiumWebMapServiceRasterOverlay)) { + return 256; + } + + int tileWidth; + cesiumWebMapServiceRasterOverlay.GetTileWidthAttr().Get(&tileWidth); + return tileWidth; } int OmniWebMapServiceRasterOverlay::getTileHeight() const { - auto cesiumWebMapServiceRasterOverlay = + const auto cesiumWebMapServiceRasterOverlay = UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); - int val; - cesiumWebMapServiceRasterOverlay.GetTileHeightAttr().Get(&val); - return val; + if (!UsdUtil::isSchemaValid(cesiumWebMapServiceRasterOverlay)) { + return 256; + } + + int tileHeight; + cesiumWebMapServiceRasterOverlay.GetTileHeightAttr().Get(&tileHeight); + return tileHeight; } std::string OmniWebMapServiceRasterOverlay::getLayers() const { - auto cesiumWebMapServiceRasterOverlay = + const auto cesiumWebMapServiceRasterOverlay = UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); - std::string val; - cesiumWebMapServiceRasterOverlay.GetLayersAttr().Get(&val); - return val; + if (!UsdUtil::isSchemaValid(cesiumWebMapServiceRasterOverlay)) { + return "1"; + } + + std::string layers; + cesiumWebMapServiceRasterOverlay.GetLayersAttr().Get(&layers); + return layers; } void OmniWebMapServiceRasterOverlay::reload() { diff --git a/src/core/src/UsdUtil.cpp b/src/core/src/UsdUtil.cpp index a454a6ab..9765e7e3 100644 --- a/src/core/src/UsdUtil.cpp +++ b/src/core/src/UsdUtil.cpp @@ -152,12 +152,12 @@ pxr::GfMatrix4d glmToUsdMatrix(const glm::dmat4& matrix) { glm::dmat4 computePrimLocalToWorldTransform(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { const auto prim = pStage->GetPrimAtPath(path); + const auto xform = pxr::UsdGeomXformable(prim); - if (!prim.IsA()) { + if (!isSchemaValid(xform)) { return glm::dmat4(1.0); } - const auto xform = pxr::UsdGeomXformable(prim); const auto time = pxr::UsdTimeCode::Default(); const auto transform = xform.ComputeLocalToWorldTransform(time); return usdToGlmMatrix(transform); @@ -245,15 +245,19 @@ bool primExists(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { return pStage->GetPrimAtPath(path).IsValid(); } +bool isSchemaValid(const pxr::UsdSchemaBase& schema) { + return schema.GetPrim().IsValid() && schema.GetSchemaKind() != pxr::UsdSchemaKind::Invalid; +} + bool isPrimVisible(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { // This is similar to isPrimVisible in kit-sdk/dev/include/omni/usd/UsdUtils.h const auto prim = pStage->GetPrimAtPath(path); + const auto imageable = pxr::UsdGeomImageable(prim); - if (!prim.IsA()) { + if (!isSchemaValid(imageable)) { return false; } - const auto imageable = pxr::UsdGeomImageable(prim); const auto time = pxr::UsdTimeCode::Default(); const auto visibility = imageable.ComputeVisibility(time); return visibility != pxr::UsdGeomTokens->invisible;