diff --git a/src/core/include/cesium/omniverse/GlobeAnchorRegistry.h b/src/core/include/cesium/omniverse/GlobeAnchorRegistry.h index ace05c49d..b5d56a166 100644 --- a/src/core/include/cesium/omniverse/GlobeAnchorRegistry.h +++ b/src/core/include/cesium/omniverse/GlobeAnchorRegistry.h @@ -33,6 +33,7 @@ class GlobeAnchorRegistry { std::shared_ptr createAnchor(const pxr::SdfPath& path, const glm::dmat4& anchorToFixed); std::optional> getAnchor(const pxr::SdfPath& path) const; std::vector> getAllAnchors() const; + std::vector getAllAnchorPaths() const; bool removeAnchor(const pxr::SdfPath& path); protected: diff --git a/src/core/src/GlobeAnchorRegistry.cpp b/src/core/src/GlobeAnchorRegistry.cpp index 07dbb528f..b22dc72e8 100644 --- a/src/core/src/GlobeAnchorRegistry.cpp +++ b/src/core/src/GlobeAnchorRegistry.cpp @@ -37,7 +37,18 @@ std::vector> GlobeAnchorRegistry::getAllAnchors result.reserve(_anchors.size()); for (const auto& item : _anchors) { - result.push_back(item.second); + result.emplace_back(item.second); + } + + return result; +} + +std::vector GlobeAnchorRegistry::getAllAnchorPaths() const { + std::vector result; + result.reserve(_anchors.size()); + + for (const auto& item : _anchors) { + result.emplace_back(item.first); } return result; diff --git a/src/core/src/UsdNotificationHandler.cpp b/src/core/src/UsdNotificationHandler.cpp index 07470643d..b85a19558 100644 --- a/src/core/src/UsdNotificationHandler.cpp +++ b/src/core/src/UsdNotificationHandler.cpp @@ -168,10 +168,16 @@ void UsdNotificationHandler::onPrimRemoved(const pxr::SdfPath& primPath) { } } - const auto& type = getType(primPath); - if (type == ChangedPrimType::CESIUM_GLOBE_ANCHOR) { - _changedPrims.emplace_back(ChangedPrim{primPath, pxr::TfToken(), type, ChangeType::PRIM_REMOVED}); - CESIUM_LOG_INFO("Removed prim: {}", primPath.GetText()); + const auto& anchors = GlobeAnchorRegistry::getInstance().getAllAnchorPaths(); + for (const auto& anchorPath : anchors) { + const auto& path = pxr::SdfPath(anchorPath); + const auto& type = getType(path); + if (type == ChangedPrimType::CESIUM_GLOBE_ANCHOR) { + if (inSubtree(primPath, path)) { + _changedPrims.emplace_back(ChangedPrim{path, pxr::TfToken(), type, ChangeType::PRIM_REMOVED}); + CESIUM_LOG_INFO("Removed prim: {}", path.GetText()); + } + } } }