Skip to content

Commit

Permalink
Merge pull request #714 from CesiumGS/georeference-ecef-to-usd-transform
Browse files Browse the repository at this point in the history
Added `ecefToUsdTransform` to `CesiumGeoreferencePrim`
  • Loading branch information
r-veenstra authored May 13, 2024
2 parents d471aa3 + 84c6ae9 commit 2ec6838
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 552 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

### v0.21.0 - 2024-06-03

* Added read-only attribute `ecefToUsdTransform` to `CesiumGeoreferencePrim`. Previously this was stored in `/CesiumSession` which has since been removed.
* Fixed crash when updating globe anchor when georeferencing is disabled.

### v0.20.0 - 2024-05-01

* Fix missing button for adding imagery from Asset UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class Georeference(pxr.Usd.Typed):
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def CreateEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateGeoreferenceOriginHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateGeoreferenceOriginLatitudeAttr(cls, *args, **kwargs) -> Any: ...
Expand All @@ -82,6 +84,8 @@ class Georeference(pxr.Usd.Typed):
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginLatitudeAttr(cls, *args, **kwargs) -> Any: ...
Expand Down Expand Up @@ -222,6 +226,8 @@ class PolygonRasterOverlay(RasterOverlay):
@classmethod
def CreateCesiumOverlayRenderMethodAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateExcludeSelectedTilesAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateInvertSelectionAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
Expand All @@ -232,6 +238,8 @@ class PolygonRasterOverlay(RasterOverlay):
@classmethod
def GetCesiumOverlayRenderMethodAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetExcludeSelectedTilesAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetInvertSelectionAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
Expand Down Expand Up @@ -285,27 +293,6 @@ class RasterOverlay(pxr.Usd.Typed):
@classmethod
def __reduce__(cls) -> Any: ...

class Session(pxr.Usd.Typed):
__instance_size__: ClassVar[int] = ...
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def CreateEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

class TileMapServiceRasterOverlay(RasterOverlay):
__instance_size__: ClassVar[int] = ...
@classmethod
Expand Down Expand Up @@ -504,6 +491,8 @@ class Tokens(Boost.Python.instance):
@property
def cesiumEnforceCulledScreenSpaceError(self) -> Any: ...
@property
def cesiumExcludeSelectedTiles(self) -> Any: ...
@property
def cesiumForbidHoles(self) -> Any: ...
@property
def cesiumFormat(self) -> Any: ...
Expand Down
24 changes: 8 additions & 16 deletions exts/cesium.usd.plugins/schemas/cesium_schemas.usda
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,6 @@ class CesiumDataPrim "CesiumDataPrim" (
)
}

class CesiumSessionPrim "CesiumSessionPrim" (
doc = """Stores session layer state for Cesium for Omniverse/USD."""
inherits = </Typed>
customData = {
string className = "Session"
}
) {
matrix4d cesium:ecefToUsdTransform (
customData = {
string apiName = "ecefToUsdTransform"
}
displayName = "ECEF to USD Transform"
doc = "The 4x4 transformation matrix (row major) from global ECEF coordinates to USD stage coordinates based on the georeference origin."
)
}

class CesiumIonServerPrim "CesiumIonServerPrim" (
doc = """Stores metadata related to Cesium ion server connections for tilesets."""
inherits = </Typed>
Expand Down Expand Up @@ -217,6 +201,14 @@ class CesiumGeoreferencePrim "CesiumGeoreferencePrim" (
displayName = "Georeference Origin Height"
doc = "The height of the origin in meters above the WGS84 ellipsoid. Do not confuse this with a geoid height or height above mean sea level, which can be tens of meters higher or lower depending on where in the world the origin is located."
)

matrix4d cesium:ecefToUsdTransform (
customData = {
string apiName = "ecefToUsdTransform"
}
displayName = "ECEF to USD Transform (read only)"
doc = "The 4x4 transformation matrix (row major) from global ECEF coordinates to USD stage coordinates based on the georeference origin (read only)."
)
}

class CesiumTilesetPrim "CesiumTilesetPrim" (
Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/OmniGeoreference.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class OmniGeoreference {
[[nodiscard]] CesiumGeospatial::Cartographic getOrigin() const;
[[nodiscard]] const CesiumGeospatial::Ellipsoid& getEllipsoid() const;
[[nodiscard]] CesiumGeospatial::LocalHorizontalCoordinateSystem getLocalCoordinateSystem() const;
void update();

private:
Context* _pContext;
Expand Down
7 changes: 2 additions & 5 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CesiumRasterOverlay;
class CesiumIonRasterOverlay;
class CesiumIonServer;
class CesiumPolygonRasterOverlay;
class CesiumSession;
class CesiumTileset;
class CesiumWebMapServiceRasterOverlay;
class CesiumTileMapServiceRasterOverlay;
Expand Down Expand Up @@ -116,7 +115,6 @@ defineCesiumPolygonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::
pxr::CesiumGeoreference defineCesiumGeoreference(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumIonServer defineCesiumIonServer(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumGlobeAnchorAPI applyCesiumGlobeAnchor(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumSession defineCesiumSession(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);

pxr::CesiumData getCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumTileset getCesiumTileset(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
Expand All @@ -137,8 +135,6 @@ pxr::UsdGeomBasisCurves getCesiumCartographicPolygon(const pxr::UsdStageWeakPtr&
pxr::UsdShadeShader getUsdShader(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::UsdGeomBasisCurves getUsdBasisCurves(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);

pxr::CesiumSession getOrCreateCesiumSession(const pxr::UsdStageWeakPtr& pStage);

bool isCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isCesiumTileset(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isCesiumRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
Expand All @@ -150,7 +146,6 @@ bool isCesiumWebMapTileServiceRasterOverlay(const pxr::UsdStageWeakPtr& pStage,
bool isCesiumGeoreference(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isCesiumIonServer(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isCesiumSession(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool hasCesiumGlobeAnchor(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isUsdShader(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isUsdMaterial(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
Expand All @@ -173,4 +168,6 @@ struct TranslateRotateScaleOps {

std::optional<TranslateRotateScaleOps> getOrCreateTranslateRotateScaleOps(const pxr::UsdGeomXformable& xformable);

bool getDebugDisableGeoreferencing(const Context& context);

}; // namespace cesium::omniverse::UsdUtil
15 changes: 14 additions & 1 deletion src/core/src/OmniGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace cesium::omniverse {
OmniGeoreference::OmniGeoreference(Context* pContext, const pxr::SdfPath& path)
: _pContext(pContext)
, _path(path)
, _ellipsoid(CesiumGeospatial::Ellipsoid::WGS84) {}
, _ellipsoid(CesiumGeospatial::Ellipsoid::WGS84) {
update();
}

const pxr::SdfPath& OmniGeoreference::getPath() const {
return _path;
Expand Down Expand Up @@ -68,4 +70,15 @@ CesiumGeospatial::LocalHorizontalCoordinateSystem OmniGeoreference::getLocalCoor
};
}

void OmniGeoreference::update() {
const auto cesiumGeoreference = UsdUtil::getCesiumGeoreference(_pContext->getUsdStage(), _path);
if (!UsdUtil::isSchemaValid(cesiumGeoreference)) {
return;
}

const auto ecefToUsdTransform = getLocalCoordinateSystem().getEcefToLocalTransformation();

cesiumGeoreference.GetEcefToUsdTransformAttr().Set(UsdUtil::glmToUsdMatrix(ecefToUsdTransform));
}

} // namespace cesium::omniverse
5 changes: 4 additions & 1 deletion src/core/src/OmniGlobeAnchor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <CesiumUsdSchemas/globeAnchorAPI.h>
#include <CesiumUsdSchemas/ionServer.h>
#include <CesiumUsdSchemas/rasterOverlay.h>
#include <CesiumUsdSchemas/session.h>
#include <CesiumUsdSchemas/tileset.h>
#include <CesiumUsdSchemas/tokens.h>
#include <CesiumUtility/Math.h>
Expand Down Expand Up @@ -236,6 +235,10 @@ bool OmniGlobeAnchor::isAnchorValid() const {
return false;
}

if (UsdUtil::getDebugDisableGeoreferencing(*_pContext)) {
return false;
}

return true;
}

Expand Down
17 changes: 15 additions & 2 deletions src/core/src/UsdNotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,33 @@ void processCesiumWebMapTileServiceRasterOverlayChanged(
}
}

void processCesiumGeoreferenceChanged(const Context& context, const std::vector<pxr::TfToken>& properties) {
void processCesiumGeoreferenceChanged(
const Context& context,
const pxr::SdfPath& georeferencePath,
const std::vector<pxr::TfToken>& properties) {
const auto pGeoreference = context.getAssetRegistry().getGeoreference(georeferencePath);
if (!pGeoreference) {
return;
}

auto updateGeoreference = false;
auto updateBindings = false;

// clang-format off
for (const auto& property : properties) {
if (property == pxr::CesiumTokens->cesiumGeoreferenceOriginLongitude ||
property == pxr::CesiumTokens->cesiumGeoreferenceOriginLatitude ||
property == pxr::CesiumTokens->cesiumGeoreferenceOriginHeight) {
updateGeoreference = true;
updateBindings = true;
}
}
// clang-format on

if (updateGeoreference) {
pGeoreference->update();
}

if (updateBindings) {
updateGeoreferenceBindings(context);
}
Expand Down Expand Up @@ -945,7 +958,7 @@ bool UsdNotificationHandler::processChangedPrim(const ChangedPrim& changedPrim)
*_pContext, changedPrim.primPath, changedPrim.properties);
break;
case ChangedPrimType::CESIUM_GEOREFERENCE:
processCesiumGeoreferenceChanged(*_pContext, changedPrim.properties);
processCesiumGeoreferenceChanged(*_pContext, changedPrim.primPath, changedPrim.properties);
break;
case ChangedPrimType::CESIUM_GLOBE_ANCHOR:
processCesiumGlobeAnchorChanged(*_pContext, changedPrim.primPath, changedPrim.properties);
Expand Down
55 changes: 9 additions & 46 deletions src/core/src/UsdUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <CesiumUsdSchemas/ionRasterOverlay.h>
#include <CesiumUsdSchemas/ionServer.h>
#include <CesiumUsdSchemas/polygonRasterOverlay.h>
#include <CesiumUsdSchemas/session.h>
#include <CesiumUsdSchemas/tileMapServiceRasterOverlay.h>
#include <CesiumUsdSchemas/tileset.h>
#include <CesiumUsdSchemas/webMapServiceRasterOverlay.h>
Expand All @@ -51,19 +50,6 @@

namespace cesium::omniverse::UsdUtil {

namespace {

bool getDebugDisableGeoreferencing(const Context& context) {
const auto pData = context.getAssetRegistry().getFirstData();
if (!pData) {
return false;
}

return pData->getDebugDisableGeoreferencing();
}

} // namespace

glm::dvec3 usdToGlmVector(const pxr::GfVec3d& vector) {
return {vector[0], vector[1], vector[2]};
}
Expand Down Expand Up @@ -356,10 +342,6 @@ pxr::CesiumGlobeAnchorAPI applyCesiumGlobeAnchor(const pxr::UsdStageWeakPtr& pSt
return pxr::CesiumGlobeAnchorAPI::Apply(prim);
}

pxr::CesiumSession defineCesiumSession(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
return pxr::CesiumSession::Define(pStage, path);
}

pxr::CesiumData getCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
return pxr::CesiumData::Get(pStage, path);
}
Expand Down Expand Up @@ -422,25 +404,6 @@ pxr::UsdGeomBasisCurves getUsdBasisCurves(const pxr::UsdStageWeakPtr& pStage, co
return pxr::UsdGeomBasisCurves::Get(pStage, path);
}

pxr::CesiumSession getOrCreateCesiumSession(const pxr::UsdStageWeakPtr& pStage) {
static const auto CesiumSessionPath = pxr::SdfPath("/CesiumSession");

if (isCesiumSession(pStage, CesiumSessionPath)) {
return pxr::CesiumSession::Get(pStage, CesiumSessionPath);
}

// Ensures that CesiumSession is created in the session layer
const UsdScopedEdit scopedEdit(pStage);

// Create the CesiumSession
const auto cesiumSession = defineCesiumSession(pStage, CesiumSessionPath);

// Prevent CesiumSession from being traversed and composed into the stage
cesiumSession.GetPrim().SetActive(false);

return cesiumSession;
}

bool isCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
const auto prim = pStage->GetPrimAtPath(path);
if (!prim.IsValid()) {
Expand Down Expand Up @@ -542,15 +505,6 @@ bool isCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::
return prim.HasAPI<pxr::CesiumGlobeAnchorAPI>();
}

bool isCesiumSession(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
const auto prim = pStage->GetPrimAtPath(path);
if (!prim.IsValid()) {
return false;
}

return prim.IsA<pxr::CesiumSession>();
}

bool hasCesiumGlobeAnchor(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
const auto prim = pStage->GetPrimAtPath(path);
if (!prim.IsValid()) {
Expand Down Expand Up @@ -836,4 +790,13 @@ std::optional<TranslateRotateScaleOps> getOrCreateTranslateRotateScaleOps(const
return TranslateRotateScaleOps{translateOp, rotateOp, scaleOp, eulerAngleOrder};
}

bool getDebugDisableGeoreferencing(const Context& context) {
const auto pData = context.getAssetRegistry().getFirstData();
if (!pData) {
return false;
}

return pData->getDebugDisableGeoreferencing();
}

} // namespace cesium::omniverse::UsdUtil
2 changes: 0 additions & 2 deletions src/plugins/CesiumUsdSchemas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(SOURCES
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/rasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/ionRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/polygonRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/session.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/tileMapServiceRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/tileset.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/tokens.cpp"
Expand All @@ -25,7 +24,6 @@ set(PY_BINDING_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapIonRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapPolygonRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapSession.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapTileMapServiceRasterOverlay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapTileset.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapTokens.cpp"
Expand Down
14 changes: 4 additions & 10 deletions src/plugins/CesiumUsdSchemas/generatedSchema.usda.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ class CesiumDataPrim "CesiumDataPrim" (
)
}

class CesiumSessionPrim "CesiumSessionPrim" (
doc = "Stores session layer state for Cesium for Omniverse/USD."
)
{
matrix4d cesium:ecefToUsdTransform (
displayName = "ECEF to USD Transform"
doc = "The 4x4 transformation matrix (row major) from global ECEF coordinates to USD stage coordinates based on the georeference origin."
)
}

class CesiumIonServerPrim "CesiumIonServerPrim" (
doc = "Stores metadata related to Cesium ion server connections for tilesets."
)
Expand Down Expand Up @@ -97,6 +87,10 @@ class CesiumGeoreferencePrim "CesiumGeoreferencePrim" (
doc = "Stores Georeference data for Cesium for Omniverse. Every stage should have at least one of these."
)
{
matrix4d cesium:ecefToUsdTransform (
displayName = "ECEF to USD Transform (read only)"
doc = "The 4x4 transformation matrix (row major) from global ECEF coordinates to USD stage coordinates based on the georeference origin (read only)."
)
double cesium:georeferenceOrigin:height = 2250 (
displayName = "Georeference Origin Height"
doc = "The height of the origin in meters above the WGS84 ellipsoid. Do not confuse this with a geoid height or height above mean sea level, which can be tens of meters higher or lower depending on where in the world the origin is located."
Expand Down
Loading

0 comments on commit 2ec6838

Please sign in to comment.