Skip to content

Commit

Permalink
Merge branch 'main' into multiple-raster-overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse authored Oct 17, 2023
2 parents 040df58 + 64d268e commit 9b8998d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ void setGeoreferenceForTileset(const pxr::SdfPath& tilesetPath, const pxr::SdfPa

void addOrUpdateTransformOpForAnchor(const pxr::SdfPath& path, const glm::dmat4& transform);
std::optional<pxr::GfMatrix4d> getCesiumTransformOpValueForPathIfExists(const pxr::SdfPath& path);
std::optional<pxr::SdfPath> getAnchorGeoreferencePath(const pxr::SdfPath& path);
std::optional<CesiumGeospatial::Cartographic> getCartographicOriginForAnchor(const pxr::SdfPath& path);

}; // namespace cesium::omniverse::UsdUtil
46 changes: 26 additions & 20 deletions src/core/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ void Context::reloadStage() {
AssetRegistry::getInstance().addTileset(path, UsdUtil::GEOREFERENCE_PATH);
} else if (UsdUtil::isCesiumImagery(path)) {
AssetRegistry::getInstance().addImagery(path);
} else if (UsdUtil::hasCesiumGlobeAnchor(path)) {
auto origin = UsdUtil::getCartographicOriginForAnchor(path);

// We probably need to do something else other than crash, but there really isn't more we can do in this case.
assert(origin.has_value());

auto anchorToFixed = UsdUtil::computeUsdLocalToEcefTransformForPrim(origin.value(), path);
GlobeAnchorRegistry::getInstance().createAnchor(path, anchorToFixed);
}
}
}
Expand Down Expand Up @@ -314,53 +322,50 @@ void Context::processCesiumGeoreferenceChanged(const cesium::omniverse::ChangedP
for (const auto& globeAnchor : anchors) {
auto anchorApi = UsdUtil::getCesiumGlobeAnchor(globeAnchor->getPrimPath());

pxr::SdfPathVector targets;
if (!anchorApi.GetGeoreferenceBindingRel().GetForwardedTargets(&targets)) {
return;
}

// We only want to update an anchor if we are updating it's related Georeference Prim.
if (path != targets[0]) {
if (path !=
UsdUtil::getAnchorGeoreferencePath(globeAnchor->getPrimPath()).value_or(pxr::SdfPath::EmptyPath())) {
continue;
}

auto georeferenceOrigin = UsdUtil::getCesiumGeoreference(targets[0]);
auto origin = GeospatialUtil::convertGeoreferenceToCartographic(georeferenceOrigin);
auto origin = UsdUtil::getCartographicOriginForAnchor(globeAnchor->getPrimPath());
if (!origin.has_value()) {
continue;
}

GeospatialUtil::updateAnchorOrigin(origin, anchorApi, globeAnchor);
GeospatialUtil::updateAnchorOrigin(origin.value(), anchorApi, globeAnchor);
}
}

void Context::processCesiumGlobeAnchorChanged(const cesium::omniverse::ChangedPrim& changedPrim) {
const auto& [path, name, primType, changeType] = changedPrim;

auto globeAnchor = UsdUtil::getCesiumGlobeAnchor(path);
pxr::SdfPathVector targets;
if (!globeAnchor.GetGeoreferenceBindingRel().GetForwardedTargets(&targets)) {
auto origin = UsdUtil::getCartographicOriginForAnchor(path);

if (!origin.has_value()) {
return;
}
auto georeferenceOrigin = UsdUtil::getCesiumGeoreference(targets[0]);
auto cartographicOrigin = GeospatialUtil::convertGeoreferenceToCartographic(georeferenceOrigin);

bool detectTransformChanges;
globeAnchor.GetDetectTransformChangesAttr().Get(&detectTransformChanges);

if (detectTransformChanges && (name == pxr::CesiumTokens->cesiumAnchorDetectTransformChanges ||
name == pxr::UsdTokens->xformOp_transform_cesium)) {
GeospatialUtil::updateAnchorByUsdTransform(cartographicOrigin, globeAnchor);
GeospatialUtil::updateAnchorByUsdTransform(origin.value(), globeAnchor);

return;
}

if (name == pxr::CesiumTokens->cesiumAnchorGeographicCoordinates) {
GeospatialUtil::updateAnchorByLatLongHeight(cartographicOrigin, globeAnchor);
GeospatialUtil::updateAnchorByLatLongHeight(origin.value(), globeAnchor);

return;
}

if (name == pxr::CesiumTokens->cesiumAnchorPosition || name == pxr::CesiumTokens->cesiumAnchorRotation ||
name == pxr::CesiumTokens->cesiumAnchorScale) {
GeospatialUtil::updateAnchorByFixedTransform(cartographicOrigin, globeAnchor);
GeospatialUtil::updateAnchorByFixedTransform(origin.value(), globeAnchor);

return;
}
Expand Down Expand Up @@ -403,6 +408,11 @@ void Context::processPrimAdded(const ChangedPrim& changedPrim) {
const auto tilesetPath = changedPrim.path.GetParentPath();
AssetRegistry::getInstance().addImagery(imageryPath);
reloadTileset(tilesetPath);
} else if (changedPrim.primType == ChangedPrimType::CESIUM_GLOBE_ANCHOR) {
auto anchorApi = UsdUtil::getCesiumGlobeAnchor(changedPrim.path);
auto origin = UsdUtil::getCartographicOriginForAnchor(changedPrim.path);
assert(origin.has_value());
GeospatialUtil::updateAnchorByUsdTransform(origin.value(), anchorApi);
}
}

Expand Down Expand Up @@ -845,10 +855,6 @@ void Context::addGlobeAnchorToPrim(const pxr::SdfPath& path) {
// Until we support multiple georeference points, we should just use the default georeference object.
auto georeferenceOrigin = UsdUtil::getOrCreateCesiumGeoreference();
globeAnchor.GetGeoreferenceBindingRel().AddTarget(georeferenceOrigin.GetPath());

const auto cartographicOrigin = GeospatialUtil::convertGeoreferenceToCartographic(georeferenceOrigin);

GeospatialUtil::updateAnchorByUsdTransform(cartographicOrigin, globeAnchor);
}

} // namespace cesium::omniverse
2 changes: 1 addition & 1 deletion src/core/src/UsdNotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void UsdNotificationHandler::onObjectsChanged(const pxr::UsdNotice::ObjectsChang

void UsdNotificationHandler::onPrimAdded(const pxr::SdfPath& primPath) {
const auto type = getType(primPath);
if (type != ChangedPrimType::OTHER && type != ChangedPrimType::CESIUM_GLOBE_ANCHOR) {
if (type != ChangedPrimType::OTHER) {
_changedPrims.emplace_back(ChangedPrim{primPath, pxr::TfToken(), type, ChangeType::PRIM_ADDED});
CESIUM_LOG_INFO("Added prim: {}", primPath.GetText());
}
Expand Down
25 changes: 25 additions & 0 deletions src/core/src/UsdUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,29 @@ std::optional<pxr::GfMatrix4d> getCesiumTransformOpValueForPathIfExists(const px
return std::nullopt;
}

std::optional<pxr::SdfPath> getAnchorGeoreferencePath(const pxr::SdfPath& path) {
if (!hasCesiumGlobeAnchor(path)) {
return std::nullopt;
}

auto globeAnchor = getCesiumGlobeAnchor(path);
pxr::SdfPathVector targets;
if (!globeAnchor.GetGeoreferenceBindingRel().GetForwardedTargets(&targets)) {
return std::nullopt;
}

return targets[0];
}

std::optional<CesiumGeospatial::Cartographic> getCartographicOriginForAnchor(const pxr::SdfPath& path) {
auto anchorGeoreferencePath = getAnchorGeoreferencePath(path);

if (!anchorGeoreferencePath.has_value()) {
return std::nullopt;
}

auto georeferenceOrigin = UsdUtil::getCesiumGeoreference(anchorGeoreferencePath.value());
return GeospatialUtil::convertGeoreferenceToCartographic(georeferenceOrigin);
}

} // namespace cesium::omniverse::UsdUtil

0 comments on commit 9b8998d

Please sign in to comment.