Skip to content

Commit

Permalink
Option to disable georeferencing
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 7, 2023
1 parent 50680c0 commit 2e03b1b
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### v0.11.0 - 2023-10-02

* Added debug option `cesium:debug:disableGeoreferencing` to `CesiumDataPrim` to disable georeferencing and view tilesets in ECEF coordinates.
* Reduced the number of materials created when loading untextured tilesets.

### v0.10.0 - 2023-09-01
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ def _customize_props_layout(self, props):
CustomLayoutProperty("cesium:debug:materialPoolInitialCapacity")
CustomLayoutProperty("cesium:debug:texturePoolInitialCapacity")
CustomLayoutProperty("cesium:debug:randomColors")
CustomLayoutProperty("cesium:debug:disableGeoreferencing")

return frame.apply(props)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Data(pxr.Usd.Typed):
@classmethod
def CreateDebugDisableGeometryPoolAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateDebugDisableGeoreferencingAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateDebugDisableMaterialPoolAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateDebugDisableMaterialsAttr(cls, *args, **kwargs) -> Any: ...
Expand All @@ -39,6 +41,8 @@ class Data(pxr.Usd.Typed):
@classmethod
def GetDebugDisableGeometryPoolAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetDebugDisableGeoreferencingAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetDebugDisableMaterialPoolAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetDebugDisableMaterialsAttr(cls, *args, **kwargs) -> Any: ...
Expand Down Expand Up @@ -253,6 +257,8 @@ class Tokens(Boost.Python.instance):
@property
def cesiumDebugDisableGeometryPool(self) -> Any: ...
@property
def cesiumDebugDisableGeoreferencing(self) -> Any: ...
@property
def cesiumDebugDisableMaterialPool(self) -> Any: ...
@property
def cesiumDebugDisableMaterials(self) -> Any: ...
Expand Down
8 changes: 8 additions & 0 deletions exts/cesium.usd.plugins/schemas/cesium_schemas.usda
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class CesiumDataPrim "CesiumDataPrim" (
displayName = "Random Colors"
doc = "Debug option that renders tiles with random colors."
)

bool cesium:debug:disableGeoreferencing = false (
customData = {
string apiName = "debugDisableGeoreferencing"
}
displayName = "Disable Georeferencing"
doc = "Debug option to disable georeferencing. Tiles will be rendered in EPSG:4978 (ECEF) coordinates where (0, 0, 0) is the center of the globe, the X axis points towards the prime meridian, the Y axis points towards the 90th meridian east, and the Z axis points towards the North Pole."
)
}

class CesiumSessionPrim "CesiumSessionPrim" (
Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pxr::SdfPath getRootPath();
pxr::SdfPath getPathUnique(const pxr::SdfPath& parentPath, const std::string& name);
std::string getSafeName(const std::string& name);
pxr::TfToken getDynamicTextureProviderAssetPathToken(const std::string& name);
glm::dmat4 computeEcefToUsdTransform(const CesiumGeospatial::Cartographic& origin);
glm::dmat4 computeEcefToUsdTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath);
glm::dmat4 computeUsdToEcefTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath);
Cesium3DTilesSelection::ViewState
Expand Down
4 changes: 1 addition & 3 deletions src/core/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ void Context::onUpdateFrame(const std::vector<Viewport>& viewports) {
processUsdNotifications();

const auto georeferenceOrigin = Context::instance().getGeoreferenceOrigin();
const auto ecefToUsdTransform =
GeospatialUtil::getCoordinateSystem(georeferenceOrigin, UsdUtil::getUsdMetersPerUnit())
.getEcefToLocalTransformation();
const auto ecefToUsdTransform = UsdUtil::computeEcefToUsdTransform(georeferenceOrigin);

// Check if the ecefToUsd transform has changed and update CesiumSession
if (ecefToUsdTransform != _ecefToUsdTransform) {
Expand Down
16 changes: 14 additions & 2 deletions src/core/src/UsdUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,22 @@ pxr::TfToken getDynamicTextureProviderAssetPathToken(const std::string& name) {
pxr::SdfAssetPath(fmt::format("{}{}", rtx::resourcemanager::kDynamicTexturePrefix, name)).GetAssetPath());
}

glm::dmat4 computeEcefToUsdTransform(const CesiumGeospatial::Cartographic& origin) {
const auto cesiumDataUsd = UsdUtil::getOrCreateCesiumData();
bool disableGeoreferencing;
cesiumDataUsd.GetDebugDisableGeoreferencingAttr().Get(&disableGeoreferencing);

if (disableGeoreferencing) {
const auto scale = 1.0 / getUsdMetersPerUnit();
return glm::scale(glm::dmat4(1.0), glm::dvec3(scale));
}

return GeospatialUtil::getCoordinateSystem(origin, getUsdMetersPerUnit()).getEcefToLocalTransformation();
}

glm::dmat4
computeEcefToUsdTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath) {
const auto ecefToUsdTransform =
GeospatialUtil::getCoordinateSystem(origin, getUsdMetersPerUnit()).getEcefToLocalTransformation();
const auto ecefToUsdTransform = computeEcefToUsdTransform(origin);
const auto primInverseUsdWorldTransform = computeUsdWorldTransform(primPath);
const auto primEcefToUsdTransform = primInverseUsdWorldTransform * ecefToUsdTransform;
return primEcefToUsdTransform;
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/CesiumUsdSchemas/generatedSchema.usda.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class CesiumDataPrim "CesiumDataPrim" (
displayName = "Disable Geometry Pool"
doc = "Debug option that disables geometry pooling."
)
bool cesium:debug:disableGeoreferencing = 0 (
displayName = "Disable Georeferencing"
doc = "Debug option to disable georeferencing. Tiles will be rendered in EPSG:4978 (ECEF) coordinates where (0, 0, 0) is the center of the globe, the X axis points towards the prime meridian, the Y axis points towards the 90th meridian east, and the Z axis points towards the North Pole."
)
bool cesium:debug:disableMaterialPool = 0 (
displayName = "Disable Material Pool"
doc = "Debug option that disables material pooling."
Expand Down
18 changes: 18 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,23 @@ CesiumData::CreateDebugRandomColorsAttr(VtValue const &defaultValue, bool writeS
writeSparsely);
}

UsdAttribute
CesiumData::GetDebugDisableGeoreferencingAttr() const
{
return GetPrim().GetAttribute(CesiumTokens->cesiumDebugDisableGeoreferencing);
}

UsdAttribute
CesiumData::CreateDebugDisableGeoreferencingAttr(VtValue const &defaultValue, bool writeSparsely) const
{
return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumDebugDisableGeoreferencing,
SdfValueTypeNames->Bool,
/* custom = */ false,
SdfVariabilityVarying,
defaultValue,
writeSparsely);
}

namespace {
static inline TfTokenVector
_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right)
Expand Down Expand Up @@ -295,6 +312,7 @@ CesiumData::GetSchemaAttributeNames(bool includeInherited)
CesiumTokens->cesiumDebugMaterialPoolInitialCapacity,
CesiumTokens->cesiumDebugTexturePoolInitialCapacity,
CesiumTokens->cesiumDebugRandomColors,
CesiumTokens->cesiumDebugDisableGeoreferencing,
};
static TfTokenVector allNames =
_ConcatenateAttributeNames(
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,28 @@ class CesiumData : public UsdTyped
CESIUMUSDSCHEMAS_API
UsdAttribute CreateDebugRandomColorsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;

public:
// --------------------------------------------------------------------- //
// DEBUGDISABLEGEOREFERENCING
// --------------------------------------------------------------------- //
/// Debug option to disable georeferencing. Tiles will be rendered in EPSG:4978 (ECEF) coordinates where (0, 0, 0) is the center of the globe, the X axis points towards the prime meridian, the Y axis points towards the 90th meridian east, and the Z axis points towards the North Pole.
///
/// | ||
/// | -- | -- |
/// | Declaration | `bool cesium:debug:disableGeoreferencing = 0` |
/// | C++ Type | bool |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
CESIUMUSDSCHEMAS_API
UsdAttribute GetDebugDisableGeoreferencingAttr() const;

/// See GetDebugDisableGeoreferencingAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
CESIUMUSDSCHEMAS_API
UsdAttribute CreateDebugDisableGeoreferencingAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;

public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PXR_NAMESPACE_OPEN_SCOPE
CesiumTokensType::CesiumTokensType() :
cesiumCulledScreenSpaceError("cesium:culledScreenSpaceError", TfToken::Immortal),
cesiumDebugDisableGeometryPool("cesium:debug:disableGeometryPool", TfToken::Immortal),
cesiumDebugDisableGeoreferencing("cesium:debug:disableGeoreferencing", TfToken::Immortal),
cesiumDebugDisableMaterialPool("cesium:debug:disableMaterialPool", TfToken::Immortal),
cesiumDebugDisableMaterials("cesium:debug:disableMaterials", TfToken::Immortal),
cesiumDebugDisableTexturePool("cesium:debug:disableTexturePool", TfToken::Immortal),
Expand Down Expand Up @@ -43,6 +44,7 @@ CesiumTokensType::CesiumTokensType() :
allTokens({
cesiumCulledScreenSpaceError,
cesiumDebugDisableGeometryPool,
cesiumDebugDisableGeoreferencing,
cesiumDebugDisableMaterialPool,
cesiumDebugDisableMaterials,
cesiumDebugDisableTexturePool,
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct CesiumTokensType {
///
/// CesiumData
const TfToken cesiumDebugDisableGeometryPool;
/// \brief "cesium:debug:disableGeoreferencing"
///
/// CesiumData
const TfToken cesiumDebugDisableGeoreferencing;
/// \brief "cesium:debug:disableMaterialPool"
///
/// CesiumData
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ _CreateDebugRandomColorsAttr(CesiumData &self,
return self.CreateDebugRandomColorsAttr(
UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
}

static UsdAttribute
_CreateDebugDisableGeoreferencingAttr(CesiumData &self,
object defaultVal, bool writeSparsely) {
return self.CreateDebugDisableGeoreferencingAttr(
UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
}

static std::string
_Repr(const CesiumData &self)
Expand Down Expand Up @@ -221,6 +228,13 @@ void wrapCesiumData()
&_CreateDebugRandomColorsAttr,
(arg("defaultValue")=object(),
arg("writeSparsely")=false))

.def("GetDebugDisableGeoreferencingAttr",
&This::GetDebugDisableGeoreferencingAttr)
.def("CreateDebugDisableGeoreferencingAttr",
&_CreateDebugDisableGeoreferencingAttr,
(arg("defaultValue")=object(),
arg("writeSparsely")=false))

.def("__repr__", ::_Repr)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void wrapCesiumTokens()
cls("Tokens", boost::python::no_init);
_AddToken(cls, "cesiumCulledScreenSpaceError", CesiumTokens->cesiumCulledScreenSpaceError);
_AddToken(cls, "cesiumDebugDisableGeometryPool", CesiumTokens->cesiumDebugDisableGeometryPool);
_AddToken(cls, "cesiumDebugDisableGeoreferencing", CesiumTokens->cesiumDebugDisableGeoreferencing);
_AddToken(cls, "cesiumDebugDisableMaterialPool", CesiumTokens->cesiumDebugDisableMaterialPool);
_AddToken(cls, "cesiumDebugDisableMaterials", CesiumTokens->cesiumDebugDisableMaterials);
_AddToken(cls, "cesiumDebugDisableTexturePool", CesiumTokens->cesiumDebugDisableTexturePool);
Expand Down

0 comments on commit 2e03b1b

Please sign in to comment.