Skip to content

Commit

Permalink
Add support for custom ellipsoids
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Aug 30, 2024
1 parent 5ba49df commit 030ccde
Show file tree
Hide file tree
Showing 30 changed files with 822 additions and 4 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.22.0 - 2024-09-03

* Cesium for Omniverse now supports using non-WGS84 ellipsoids.
* A `CesiumEllipsoidPrim` should be specified on the `ellipsoidBinding` field of a `CesiumReferencePrim`.

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

* Added `pointSize` attribute to `CesiumTilesetPrim` for controlling the size of points.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .data_attributes_widget import CesiumDataSchemaAttributesWidget # noqa: F401
from .ellipsoid_attributes_widget import CesiumEllipsoidAttributesWidget # noqa: F401
from .georeference_attributes_widget import CesiumGeoreferenceSchemaAttributesWidget # noqa :F401
from .tileset_attributes_widget import CesiumTilesetAttributesWidget # noqa: F401
from .globe_anchor_attributes_widget import CesiumGlobeAnchorAttributesWidget # noqa: F401
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging
from omni.kit.property.usd.custom_layout_helper import CustomLayoutFrame, CustomLayoutGroup, CustomLayoutProperty
from omni.kit.property.usd.usd_property_widget import SchemaPropertiesWidget
from cesium.usd.plugins.CesiumUsdSchemas import Ellipsoid as CesiumEllipsoid


class CesiumEllipsoidAttributesWidget(SchemaPropertiesWidget):
def __init__(self):
super().__init__("Ellipsoid", CesiumEllipsoid, include_inherited=False)

self._logger = logging.getLogger(__name__)

def clean(self):
super().clean()

def _customize_props_layout(self, props):
frame = CustomLayoutFrame(hide_extra=True)

with frame:
CustomLayoutProperty("cesium:radii")

return frame.apply(props)
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
from omni.kit.property.usd.custom_layout_helper import CustomLayoutFrame, CustomLayoutGroup, CustomLayoutProperty
from omni.kit.property.usd.usd_property_widget import SchemaPropertiesWidget
from cesium.usd.plugins.CesiumUsdSchemas import Georeference as CesiumGeoreference
from cesium.usd.plugins.CesiumUsdSchemas import (
Ellipsoid as CesiumEllipsoid,
Georeference as CesiumGeoreference,
)


class CesiumGeoreferenceSchemaAttributesWidget(SchemaPropertiesWidget):
Expand All @@ -21,5 +24,18 @@ def _customize_props_layout(self, props):
CustomLayoutProperty("cesium:georeferenceOrigin:latitude", "Latitude")
CustomLayoutProperty("cesium:georeferenceOrigin:longitude", "Longitude")
CustomLayoutProperty("cesium:georeferenceOrigin:height", "Height")
with CustomLayoutGroup("Ellipsoid"):
CustomLayoutProperty("cesium:ellipsoidBinding")

return frame.apply(props)

def _filter_props_to_build(self, props):
filtered_props = super()._filter_props_to_build(props)
filtered_props.extend(prop for prop in props if prop.GetName() == "cesium:ellipsoidBinding")
return filtered_props

def get_additional_kwargs(self, ui_attr):
if ui_attr.prop_name == "cesium:ellipsoidBinding":
return None, {"target_picker_filter_type_list": [CesiumEllipsoid], "targets_limit": 1}

return None, {"targets_limit": 0}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import omni.kit.window.property
from .attributes import (
CesiumDataSchemaAttributesWidget,
CesiumEllipsoidAttributesWidget,
CesiumGeoreferenceSchemaAttributesWidget,
CesiumTilesetAttributesWidget,
CesiumGlobeAnchorAttributesWidget,
Expand All @@ -26,6 +27,7 @@ def __init__(self, _cesium_omniverse_interface: ICesiumOmniverseInterface):
self._logger = logging.getLogger(__name__)

self._register_data_attributes_widget()
self._register_ellipsoid_attributes_widget()
self._register_georeference_attributes_widget()
self._register_tileset_attributes_widget()
self._register_global_anchor_attributes_widget()
Expand All @@ -38,6 +40,7 @@ def __init__(self, _cesium_omniverse_interface: ICesiumOmniverseInterface):

def destroy(self):
self._unregister_data_attributes_widget()
self._unregister_ellipsoid_attributes_widget()
self._unregister_georeference_attributes_widget()
self._unregister_tileset_attributes_widget()
self._unregister_global_anchor_attributes_widget()
Expand All @@ -60,6 +63,18 @@ def _unregister_data_attributes_widget():
if window is not None:
window.unregister_widget("prim", "cesiumData")

@staticmethod
def _register_ellipsoid_attributes_widget():
window = omni.kit.window.property.get_window()
if window is not None:
window.register_widget("prim", "cesiumEllipsoid", CesiumEllipsoidAttributesWidget())

@staticmethod
def _unregister_ellipsoid_attributes_widget():
window = omni.kit.window.property.get_window()
if window is not None:
window.unregister_widget("prim", "cesiumEllipsoid")

@staticmethod
def _register_georeference_attributes_widget():
window = omni.kit.window.property.get_window()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,36 @@ class Data(pxr.Usd.Typed):
@classmethod
def __reduce__(cls) -> Any: ...

class Ellipsoid(pxr.Usd.Typed):
__instance_size__: ClassVar[int] = ...
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def CreateRadiiAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetRadiiAttr(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 Georeference(pxr.Usd.Typed):
__instance_size__: ClassVar[int] = ...
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def CreateEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateEllipsoidBindingRel(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateGeoreferenceOriginHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateGeoreferenceOriginLatitudeAttr(cls, *args, **kwargs) -> Any: ...
Expand All @@ -86,6 +109,8 @@ class Georeference(pxr.Usd.Typed):
@classmethod
def GetEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetEllipsoidBindingRel(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginLatitudeAttr(cls, *args, **kwargs) -> Any: ...
Expand Down Expand Up @@ -489,6 +514,8 @@ class Tokens(Boost.Python.instance):
@property
def cesiumEcefToUsdTransform(self) -> Any: ...
@property
def cesiumEllipsoidBinding(self) -> Any: ...
@property
def cesiumEnableFogCulling(self) -> Any: ...
@property
def cesiumEnableFrustumCulling(self) -> Any: ...
Expand Down Expand Up @@ -561,6 +588,8 @@ class Tokens(Boost.Python.instance):
@property
def cesiumProjectDefaultIonAccessTokenId(self) -> Any: ...
@property
def cesiumRadii(self) -> Any: ...
@property
def cesiumRasterOverlayBinding(self) -> Any: ...
@property
def cesiumRootTilesX(self) -> Any: ...
Expand Down
26 changes: 25 additions & 1 deletion exts/cesium.usd.plugins/schemas/cesium_schemas.usda
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class CesiumGeoreferencePrim "CesiumGeoreferencePrim" (
string apiName = "georeferenceOriginHeight"
}
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."
doc = "The height of the origin in meters above the 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 (
Expand All @@ -209,6 +209,14 @@ class CesiumGeoreferencePrim "CesiumGeoreferencePrim" (
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)."
)

rel cesium:ellipsoidBinding (
customData = {
string apiName = "ellipsoidBinding"
}
displayName = "Ellipsoid Binding"
doc = "The ellipsoid."
)
}

class CesiumTilesetPrim "CesiumTilesetPrim" (
Expand Down Expand Up @@ -857,3 +865,19 @@ class "CesiumGlobeAnchorSchemaAPI" (
doc = "The Georeference Origin prim used for the globe anchor calculations."
)
}

class CesiumEllipsoidPrim "CesiumEllipsoidPrim" (
doc = """An ellipsoid."""
inherits = </Typed>
customData = {
string className = "Ellipsoid"
}
) {
double3 cesium:radii = (0.0, 0.0, 0.0) (
customData = {
string apiName = "radii"
}
displayName = "Radii"
doc = "The radii of this ellipsoid. The X coordinate should be the radius of the largest axis and the Z coordinate should be the radius of the smallest axis."
)
}
8 changes: 8 additions & 0 deletions src/core/include/cesium/omniverse/AssetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace cesium::omniverse {
class Context;
class OmniCartographicPolygon;
class OmniData;
class OmniEllipsoid;
class OmniGeoreference;
class OmniGlobeAnchor;
class OmniRasterOverlay;
Expand All @@ -25,6 +26,7 @@ struct Viewport;

enum AssetType {
DATA,
ELLIPSOID,
TILESET,
ION_RASTER_OVERLAY,
POLYGON_RASTER_OVERLAY,
Expand Down Expand Up @@ -54,6 +56,11 @@ class AssetRegistry {
[[nodiscard]] OmniData* getData(const pxr::SdfPath& path) const;
[[nodiscard]] OmniData* getFirstData() const;

OmniEllipsoid& addEllipsoid(const pxr::SdfPath& path);
void removeEllipsoid(const pxr::SdfPath& path);
[[nodiscard]] OmniEllipsoid* getEllipsoid(const pxr::SdfPath& path) const;
[[nodiscard]] const std::vector<std::unique_ptr<OmniEllipsoid>>& getEllipsoids() const;

OmniTileset& addTileset(const pxr::SdfPath& path);
void removeTileset(const pxr::SdfPath& path);
[[nodiscard]] OmniTileset* getTileset(const pxr::SdfPath& path) const;
Expand Down Expand Up @@ -114,6 +121,7 @@ class AssetRegistry {
private:
Context* _pContext;
std::vector<std::unique_ptr<OmniData>> _datas;
std::vector<std::unique_ptr<OmniEllipsoid>> _ellipsoids;
std::vector<std::unique_ptr<OmniTileset>> _tilesets;
std::vector<std::unique_ptr<OmniIonRasterOverlay>> _ionRasterOverlays;
std::vector<std::unique_ptr<OmniPolygonRasterOverlay>> _polygonRasterOverlays;
Expand Down
30 changes: 30 additions & 0 deletions src/core/include/cesium/omniverse/OmniEllipsoid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <glm/glm.hpp>
#include <pxr/usd/sdf/path.h>

namespace CesiumGeospatial {
class Ellipsoid;
}

namespace cesium::omniverse {

class Context;

class OmniEllipsoid {
public:
OmniEllipsoid(Context* pContext, const pxr::SdfPath& path);
~OmniEllipsoid() = default;
OmniEllipsoid(const OmniEllipsoid&) = delete;
OmniEllipsoid& operator=(const OmniEllipsoid&) = delete;
OmniEllipsoid(OmniEllipsoid&&) noexcept = default;
OmniEllipsoid& operator=(OmniEllipsoid&&) noexcept = default;

[[nodiscard]] const pxr::SdfPath& getPath() const;
[[nodiscard]] CesiumGeospatial::Ellipsoid getEllipsoid() const;

private:
Context* _pContext;
pxr::SdfPath _path;
};
} // namespace cesium::omniverse
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 @@ -24,6 +24,7 @@ class OmniGeoreference {

[[nodiscard]] const pxr::SdfPath& getPath() const;
[[nodiscard]] CesiumGeospatial::Cartographic getOrigin() const;
[[nodiscard]] pxr::SdfPath getEllipsoidPath() const;
[[nodiscard]] const CesiumGeospatial::Ellipsoid& getEllipsoid() const;
[[nodiscard]] CesiumGeospatial::LocalHorizontalCoordinateSystem getLocalCoordinateSystem() const;
void update();
Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/UsdNotificationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UsdNotificationHandler final : public pxr::TfWeakBase {
private:
enum class ChangedPrimType {
CESIUM_DATA,
CESIUM_ELLIPSOID,
CESIUM_TILESET,
CESIUM_ION_RASTER_OVERLAY,
CESIUM_POLYGON_RASTER_OVERLAY,
Expand Down
4 changes: 4 additions & 0 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

PXR_NAMESPACE_OPEN_SCOPE
class CesiumData;
class CesiumEllipsoid;
class CesiumGeoreference;
class CesiumGlobeAnchorAPI;
class CesiumRasterOverlay;
Expand Down Expand Up @@ -108,6 +109,7 @@ std::string getSafeName(const std::string& name);
pxr::TfToken getDynamicTextureProviderAssetPathToken(const std::string_view& name);

pxr::CesiumData defineCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumEllipsoid defineCesiumEllipsoid(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumTileset defineCesiumTileset(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumIonRasterOverlay defineCesiumIonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumPolygonRasterOverlay
Expand All @@ -117,6 +119,7 @@ pxr::CesiumIonServer defineCesiumIonServer(const pxr::UsdStageWeakPtr& pStage, c
pxr::CesiumGlobeAnchorAPI applyCesiumGlobeAnchor(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);

pxr::CesiumData getCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumEllipsoid getCesiumEllipsoid(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumTileset getCesiumTileset(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumRasterOverlay getCesiumRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::CesiumIonRasterOverlay getCesiumIonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
Expand All @@ -136,6 +139,7 @@ pxr::UsdShadeShader getUsdShader(const pxr::UsdStageWeakPtr& pStage, const pxr::
pxr::UsdGeomBasisCurves getUsdBasisCurves(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);

bool isCesiumData(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
bool isCesiumEllipsoid(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);
bool isCesiumIonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
Expand Down
26 changes: 26 additions & 0 deletions src/core/src/AssetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cesium/omniverse/CppUtil.h"
#include "cesium/omniverse/OmniCartographicPolygon.h"
#include "cesium/omniverse/OmniData.h"
#include "cesium/omniverse/OmniEllipsoid.h"
#include "cesium/omniverse/OmniGeoreference.h"
#include "cesium/omniverse/OmniGlobeAnchor.h"
#include "cesium/omniverse/OmniIonRasterOverlay.h"
Expand Down Expand Up @@ -55,6 +56,28 @@ OmniData* AssetRegistry::getFirstData() const {
return _datas.front().get();
}

OmniEllipsoid& AssetRegistry::addEllipsoid(const pxr::SdfPath& path) {
return *_ellipsoids.insert(_ellipsoids.end(), std::make_unique<OmniEllipsoid>(_pContext, path))->get();
}

void AssetRegistry::removeEllipsoid(const pxr::SdfPath& path) {
CppUtil::eraseIf(_ellipsoids, [&path](const auto& pEllipsoid) { return pEllipsoid->getPath() == path; });
}

OmniEllipsoid* AssetRegistry::getEllipsoid(const pxr::SdfPath& path) const {
for (const auto& pEllipsoid : _ellipsoids) {
if (pEllipsoid->getPath() == path) {
return pEllipsoid.get();
}
}

return nullptr;
}

const std::vector<std::unique_ptr<OmniEllipsoid>>& AssetRegistry::getEllipsoids() const {
return _ellipsoids;
}

OmniTileset& AssetRegistry::addTileset(const pxr::SdfPath& path) {
return *_tilesets.insert(_tilesets.end(), std::make_unique<OmniTileset>(_pContext, path, _tilesetId++))->get();
}
Expand Down Expand Up @@ -349,6 +372,8 @@ const std::vector<std::unique_ptr<OmniCartographicPolygon>>& AssetRegistry::getC
AssetType AssetRegistry::getAssetType(const pxr::SdfPath& path) const {
if (getData(path)) {
return AssetType::DATA;
} else if (getEllipsoid(path)) {
return AssetType::ELLIPSOID;
} else if (getTileset(path)) {
return AssetType::TILESET;
} else if (getIonRasterOverlay(path)) {
Expand All @@ -375,6 +400,7 @@ bool AssetRegistry::hasAsset(const pxr::SdfPath& path) const {

void AssetRegistry::clear() {
_datas.clear();
_ellipsoids.clear();
_tilesets.clear();
_ionRasterOverlays.clear();
_polygonRasterOverlays.clear();
Expand Down
Loading

0 comments on commit 030ccde

Please sign in to comment.