From 96b8ab551faa4f345ae808679297a8acaee3b5da Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Tue, 6 Feb 2024 18:20:34 -0800 Subject: [PATCH 1/8] add WMSRasterOverlay support and UI --- .../omniverse/ui/add_menu_controller.py | 16 + .../omniverse/ui/attributes/__init__.py | 1 + .../ui/attributes/custom_attribute_widgets.py | 25 +- ...ervice_raster_overlay_attributes_widget.py | 40 +++ .../ui/attributes_widget_controller.py | 17 ++ .../usd/plugins/CesiumUsdSchemas/__init__.pyi | 63 ++++ .../schemas/cesium_schemas.usda | 61 +++- .../include/cesium/omniverse/AssetRegistry.h | 9 + .../OmniWebMapServiceRasterOverlay.h | 33 +++ .../cesium/omniverse/UsdNotificationHandler.h | 1 + src/core/include/cesium/omniverse/UsdUtil.h | 4 + src/core/src/AssetRegistry.cpp | 32 +- src/core/src/OmniTileset.cpp | 6 +- .../src/OmniWebMapServiceRasterOverlay.cpp | 102 +++++++ src/core/src/UsdNotificationHandler.cpp | 62 ++++ src/core/src/UsdUtil.cpp | 17 ++ src/plugins/CesiumUsdSchemas/CMakeLists.txt | 6 +- .../CesiumUsdSchemas/generatedSchema.usda.in | 47 ++- src/plugins/CesiumUsdSchemas/plugInfo.json.in | 10 + .../src/CesiumUsdSchemas/ionRasterOverlay.h | 2 +- .../src/CesiumUsdSchemas/module.cpp | 1 + .../CesiumUsdSchemas/polygonRasterOverlay.h | 2 +- .../src/CesiumUsdSchemas/tokens.cpp | 12 + .../src/CesiumUsdSchemas/tokens.h | 24 ++ .../webMapServiceRasterOverlay.cpp | 229 +++++++++++++++ .../webMapServiceRasterOverlay.h | 275 ++++++++++++++++++ .../src/CesiumUsdSchemas/wrapTokens.cpp | 6 + .../wrapWebMapServiceRasterOverlay.cpp | 185 ++++++++++++ 28 files changed, 1268 insertions(+), 20 deletions(-) create mode 100644 exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py create mode 100644 src/core/include/cesium/omniverse/OmniWebMapServiceRasterOverlay.h create mode 100644 src/core/src/OmniWebMapServiceRasterOverlay.cpp create mode 100644 src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.cpp create mode 100644 src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.h create mode 100644 src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapWebMapServiceRasterOverlay.cpp diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/add_menu_controller.py b/exts/cesium.omniverse/cesium/omniverse/ui/add_menu_controller.py index 5837f808..62fd8e27 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/add_menu_controller.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/add_menu_controller.py @@ -9,6 +9,7 @@ Tileset as CesiumTileset, PolygonRasterOverlay as CesiumPolygonRasterOverlay, IonRasterOverlay as CesiumIonRasterOverlay, + WebMapServiceRasterOverlay as CesiumWebMapServiceRasterOverlay, ) from ..usdUtils import add_globe_anchor_to_prim from ..bindings import ICesiumOmniverseInterface @@ -40,6 +41,11 @@ def __init__(self, cesium_omniverse_interface: ICesiumOmniverseInterface): show_fn=partial(self._show_add_raster_overlay, context_menu=context_menu, usd_type=CesiumTileset), onclick_fn=self._add_polygon_raster_overlay, ), + PrimPathWidget.add_button_menu_entry( + "Cesium/Web Map Service Raster Overlay", + show_fn=partial(self._show_add_raster_overlay, context_menu=context_menu, usd_type=CesiumTileset), + onclick_fn=self._add_web_map_service_raster_overlay, + ), ] def destroy(self): @@ -72,6 +78,16 @@ def _add_polygon_raster_overlay(self, payload: PrimSelectionPayload): tileset_prim.GetRasterOverlayBindingRel().AddTarget(polygon_raster_overlay_path) get_property_window().request_rebuild() + def _add_web_map_service_raster_overlay(self, payload: PrimSelectionPayload): + stage = omni.usd.get_context().get_stage() + for path in payload: + child_path = Sdf.Path(path).AppendPath("web_map_service_raster_overlay") + raster_overlay_path: str = omni.usd.get_stage_next_free_path(stage, child_path, False) + CesiumWebMapServiceRasterOverlay.Define(stage, raster_overlay_path) + tileset_prim = CesiumTileset.Get(stage, path) + tileset_prim.GetRasterOverlayBindingRel().AddTarget(raster_overlay_path) + get_property_window().request_rebuild() + @staticmethod def _show_add_globe_anchor(objects: dict, context_menu: omni.kit.context_menu, usd_type: Tf.Type) -> bool: return context_menu.prim_is_type(objects, type=usd_type) and not context_menu.prim_is_type( diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py index 1edf4a4d..aebdcc5b 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py @@ -5,3 +5,4 @@ from .ion_server_attributes_widget import CesiumIonServerAttributesWidget # noqa: F401 from .ion_raster_overlay_attributes_widget import CesiumIonRasterOverlayAttributesWidget # noqa: F401 from .polygon_raster_overlay_attributes_widget import CesiumPolygonRasterOverlayAttributesWidget # noqa: F401 +from .web_map_service_raster_overlay_attributes_widget import CesiumWebMapServiceRasterOverlayAttributesWidget # noqa: F401 diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py index 3c36f40b..c3295d68 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py @@ -9,6 +9,7 @@ def _build_slider( metadata, property_type, prim_paths: List[Sdf.Path], + type="float", additional_label_kwargs={}, additional_widget_kwargs={}, ): @@ -35,9 +36,14 @@ def _build_slider( if additional_widget_kwargs: widget_kwargs.update(additional_widget_kwargs) with ui.ZStack(): - value_widget = UsdPropertiesWidgetBuilder.create_drag_or_slider( - ui.FloatDrag, ui.FloatSlider, **widget_kwargs - ) + if type == "float": + value_widget = UsdPropertiesWidgetBuilder.create_drag_or_slider( + ui.FloatDrag, ui.FloatSlider, **widget_kwargs + ) + else: + value_widget = UsdPropertiesWidgetBuilder.create_drag_or_slider( + ui.IntDrag, ui.IntSlider, **widget_kwargs + ) mixed_overlay = UsdPropertiesWidgetBuilder.create_mixed_text_overlay() UsdPropertiesWidgetBuilder.create_control_state( value_widget=value_widget, mixed_overlay=mixed_overlay, **widget_kwargs @@ -46,12 +52,21 @@ def _build_slider( return model -def build_slider(min_value, max_value): +def build_slider(min_value, max_value, type="float"): + if type not in ["int", "float"]: + raise ValueError("slider_type must be 'int' or 'float'") + def custom_slider(stage, attr_name, metadata, property_type, prim_paths, *args, **kwargs): additional_widget_kwargs = {"min": min_value, "max": max_value} additional_widget_kwargs.update(kwargs) return _build_slider( - stage, attr_name, metadata, property_type, prim_paths, additional_widget_kwargs=additional_widget_kwargs + stage, + attr_name, + metadata, + property_type, + prim_paths, + additional_widget_kwargs=additional_widget_kwargs, + type=type, ) return custom_slider diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py new file mode 100644 index 00000000..90c38180 --- /dev/null +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py @@ -0,0 +1,40 @@ +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 ( + WebMapServiceRasterOverlay as CesiumWebMapServiceRasterOverlay, +) +from pxr import UsdGeom +from .custom_attribute_widgets import build_slider + + +class CesiumWebMapServiceRasterOverlayAttributesWidget(SchemaPropertiesWidget): + def __init__(self): + super().__init__("Cesium Web Map Service Raster Overlay Settings", CesiumWebMapServiceRasterOverlay, include_inherited=True) + + self._logger = logging.getLogger(__name__) + + def clean(self): + super().clean() + + def _customize_props_layout(self, props): + frame = CustomLayoutFrame(hide_extra=True) + + with frame: + with CustomLayoutGroup("Base URL"): + CustomLayoutProperty("cesium:baseUrl") + with CustomLayoutGroup("Layers"): + CustomLayoutProperty("cesium:layers") + with CustomLayoutGroup("Tile Size"): + CustomLayoutProperty("cesium:tileWidth", build_fn=build_slider(64, 2048, type="int")) + CustomLayoutProperty("cesium:tileHeight", build_fn=build_slider(64, 2048, type="int")) + with CustomLayoutGroup("Zoom Settings"): + CustomLayoutProperty("cesium:minimumLevel", build_fn=build_slider(0, 30, type="int")) + CustomLayoutProperty("cesium:maximumLevel", build_fn=build_slider(0, 30, type="int")) + with CustomLayoutGroup("Rendering"): + CustomLayoutProperty("cesium:alpha", build_fn=build_slider(0, 1)) + CustomLayoutProperty("cesium:overlayRenderMethod") + with CustomLayoutGroup("Credit Display"): + CustomLayoutProperty("cesium:showCreditsOnScreen") + + return frame.apply(props) diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes_widget_controller.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes_widget_controller.py index 9058d26d..1f3b10eb 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes_widget_controller.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes_widget_controller.py @@ -8,6 +8,7 @@ CesiumIonServerAttributesWidget, CesiumIonRasterOverlayAttributesWidget, CesiumPolygonRasterOverlayAttributesWidget, + CesiumWebMapServiceRasterOverlayAttributesWidget, ) from ..bindings import ICesiumOmniverseInterface @@ -29,6 +30,7 @@ def __init__(self, _cesium_omniverse_interface: ICesiumOmniverseInterface): self._register_ion_server_attributes_widget() self._register_ion_raster_overlay_attributes_widget() self._register_polygon_raster_overlay_attributes_widget() + self._register_web_map_service_raster_overlay_attributes_widget() def destroy(self): self._unregister_data_attributes_widget() @@ -38,6 +40,7 @@ def destroy(self): self._unregister_ion_server_attributes_widget() self._unregister_ion_raster_overlay_attributes_widget() self._unregister_polygon_raster_overlay_attributes_widget() + self._unregister_web_map_service_raster_overlay_attributes_widget() @staticmethod def _register_data_attributes_widget(): @@ -100,6 +103,20 @@ def _unregister_polygon_raster_overlay_attributes_widget(): if window is not None: window.unregister_widget("prim", "cesiumPolygonRasterOverlay") + @staticmethod + def _register_web_map_service_raster_overlay_attributes_widget(): + window = omni.kit.window.property.get_window() + if window is not None: + window.register_widget( + "prim", "cesiumWebMapServiceRasterOverlay", CesiumWebMapServiceRasterOverlayAttributesWidget() + ) + + @staticmethod + def _unregister_web_map_service_raster_overlay_attributes_widget(): + window = omni.kit.window.property.get_window() + if window is not None: + window.unregister_widget("prim", "cesiumWebMapServiceRasterOverlay") + def _register_global_anchor_attributes_widget(self): window = omni.kit.window.property.get_window() if window is not None: diff --git a/exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/__init__.pyi b/exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/__init__.pyi index 5da8d59b..c519ba08 100644 --- a/exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/__init__.pyi +++ b/exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/__init__.pyi @@ -228,12 +228,20 @@ class PolygonRasterOverlay(RasterOverlay): @classmethod def CreateCartographicPolygonBindingRel(cls, *args, **kwargs) -> Any: ... @classmethod + def CreateCesiumOverlayRenderMethodAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def CreateInvertSelectionAttr(cls, *args, **kwargs) -> Any: ... + @classmethod def Define(cls, *args, **kwargs) -> Any: ... @classmethod def Get(cls, *args, **kwargs) -> Any: ... @classmethod def GetCartographicPolygonBindingRel(cls, *args, **kwargs) -> Any: ... @classmethod + def GetCesiumOverlayRenderMethodAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetInvertSelectionAttr(cls, *args, **kwargs) -> Any: ... + @classmethod def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ... @classmethod def _GetStaticTfType(cls, *args, **kwargs) -> Any: ... @@ -417,6 +425,8 @@ class Tokens(Boost.Python.instance): @property def cesiumAnchorPosition(self) -> Any: ... @property + def cesiumBaseUrl(self) -> Any: ... + @property def cesiumCartographicPolygonBinding(self) -> Any: ... @property def cesiumCulledScreenSpaceError(self) -> Any: ... @@ -461,6 +471,10 @@ class Tokens(Boost.Python.instance): @property def cesiumGeoreferenceOriginLongitude(self) -> Any: ... @property + def cesiumHeight(self) -> Any: ... + @property + def cesiumInvertSelection(self) -> Any: ... + @property def cesiumIonAccessToken(self) -> Any: ... @property def cesiumIonAssetId(self) -> Any: ... @@ -473,16 +487,22 @@ class Tokens(Boost.Python.instance): @property def cesiumIonServerUrl(self) -> Any: ... @property + def cesiumLayers(self) -> Any: ... + @property def cesiumLoadingDescendantLimit(self) -> Any: ... @property def cesiumMainThreadLoadingTimeLimit(self) -> Any: ... @property def cesiumMaximumCachedBytes(self) -> Any: ... @property + def cesiumMaximumLevel(self) -> Any: ... + @property def cesiumMaximumScreenSpaceError(self) -> Any: ... @property def cesiumMaximumSimultaneousTileLoads(self) -> Any: ... @property + def cesiumMinimumLevel(self) -> Any: ... + @property def cesiumOverlayRenderMethod(self) -> Any: ... @property def cesiumPreloadAncestors(self) -> Any: ... @@ -507,6 +527,8 @@ class Tokens(Boost.Python.instance): @property def cesiumUrl(self) -> Any: ... @property + def cesiumWidth(self) -> Any: ... + @property def clip(self) -> Any: ... @property def ion(self) -> Any: ... @@ -515,6 +537,47 @@ class Tokens(Boost.Python.instance): @property def url(self) -> Any: ... +class WebMapServiceRasterOverlay(RasterOverlay): + __instance_size__: ClassVar[int] = ... + @classmethod + def __init__(cls, *args, **kwargs) -> None: ... + @classmethod + def CreateBaseUrlAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def CreateHeightAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def CreateLayersAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def CreateMaximumLevelAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def CreateMinimumLevelAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def CreateWidthAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def Define(cls, *args, **kwargs) -> Any: ... + @classmethod + def Get(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetBaseUrlAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetHeightAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetLayersAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetMaximumLevelAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetMinimumLevelAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ... + @classmethod + def GetWidthAttr(cls, *args, **kwargs) -> Any: ... + @classmethod + def _GetStaticTfType(cls, *args, **kwargs) -> Any: ... + @classmethod + def __bool__(cls) -> bool: ... + @classmethod + def __reduce__(cls) -> Any: ... + class _CanApplyResult(Boost.Python.instance): __instance_size__: ClassVar[int] = ... @classmethod diff --git a/exts/cesium.usd.plugins/schemas/cesium_schemas.usda b/exts/cesium.usd.plugins/schemas/cesium_schemas.usda index 9a3a8c37..2551787b 100644 --- a/exts/cesium.usd.plugins/schemas/cesium_schemas.usda +++ b/exts/cesium.usd.plugins/schemas/cesium_schemas.usda @@ -455,7 +455,7 @@ class "CesiumRasterOverlayPrim" ( } class CesiumIonRasterOverlayPrim "CesiumIonRasterOverlayPrim" ( - doc = """Adds a prim for representing an Ion raster overlay. Should be a child of a tileset.""" + doc = """Adds a prim for representing an Ion raster overlay.""" inherits = customData = { string className = "IonRasterOverlay" @@ -487,7 +487,7 @@ class CesiumIonRasterOverlayPrim "CesiumIonRasterOverlayPrim" ( } class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" ( - doc = """Adds a prim for representing a polygon raster overlay. Should be a child of a tileset.""" + doc = """Adds a prim for representing a polygon raster overlay.""" inherits = customData = { string className = "PolygonRasterOverlay" @@ -512,6 +512,63 @@ class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" ( uniform token cesium:overlayRenderMethod = "clip" } +class CesiumWebMapServiceRasterOverlayPrim "CesiumWebMapServiceRasterOverlayPrim" ( + doc = """Adds a prim for representing a Web Map Service raster overlay.""" + inherits = + customData = { + string className = "WebMapServiceRasterOverlay" + } +) { + + string cesium:baseUrl = "" ( + customData = { + string apiName = "baseUrl" + } + displayName = "Base URL" + doc = "The base url of the Web Map Service (WMS). e.g. https://services.ga.gov.au/gis/services/NM_Culture_and_Infrastructure/MapServer/WMSServer" + ) + + string cesium:layers = "1" ( + customData = { + string apiName = "layers" + } + displayName = "Layers" + doc = "Comma-separated layer names to request from the server." + ) + + int cesium:tileWidth = 256 ( + customData = { + string apiName = "tileWidth" + } + displayName = "Tile Width" + doc = "Image width" + ) + + int cesium:tileHeight = 256 ( + customData = { + string apiName = "tileHeight" + } + displayName = "Tile Height" + doc = "Image height" + ) + + int cesium:minimumLevel = 0 ( + customData = { + string apiName = "minimumLevel" + } + displayName = "Minimum Level" + doc = "Take care when specifying this that the number of tiles at the minimum level is small, such as four or less. A larger number is likely to result in rendering problems." + ) + + int cesium:maximumLevel = 14 ( + customData = { + string apiName = "maximumLevel" + } + displayName = "Maximum Level" + doc = "Maximum zoom level." + ) +} + class "CesiumGlobeAnchorSchemaAPI" ( doc = """Adds Globe Anchoring information to a Prim for use with Cesium for Omniverse.""" inherits = diff --git a/src/core/include/cesium/omniverse/AssetRegistry.h b/src/core/include/cesium/omniverse/AssetRegistry.h index 848bec40..9720bb55 100644 --- a/src/core/include/cesium/omniverse/AssetRegistry.h +++ b/src/core/include/cesium/omniverse/AssetRegistry.h @@ -18,6 +18,7 @@ class OmniIonRasterOverlay; class OmniIonServer; class OmniPolygonRasterOverlay; class OmniTileset; +class OmniWebMapServiceRasterOverlay; struct Viewport; enum AssetType { @@ -25,6 +26,7 @@ enum AssetType { TILESET, ION_RASTER_OVERLAY, POLYGON_RASTER_OVERLAY, + WEB_MAP_SERVICE_RASTER_OVERLAY, GEOREFERENCE, GLOBE_ANCHOR, ION_SERVER, @@ -64,6 +66,12 @@ class AssetRegistry { [[nodiscard]] OmniPolygonRasterOverlay* getPolygonRasterOverlay(const pxr::SdfPath& path) const; [[nodiscard]] const std::vector>& getPolygonRasterOverlays() const; + OmniWebMapServiceRasterOverlay& addWebMapServiceRasterOverlay(const pxr::SdfPath& path); + void removeWebMapServiceRasterOverlay(const pxr::SdfPath& path); + [[nodiscard]] OmniWebMapServiceRasterOverlay* getWebMapServiceRasterOverlay(const pxr::SdfPath& path) const; + [[nodiscard]] const std::vector>& + getWebMapServiceRasterOverlays() const; + [[nodiscard]] OmniRasterOverlay* getRasterOverlay(const pxr::SdfPath& path) const; OmniGeoreference& addGeoreference(const pxr::SdfPath& path); @@ -99,6 +107,7 @@ class AssetRegistry { std::vector> _tilesets; std::vector> _ionRasterOverlays; std::vector> _polygonRasterOverlays; + std::vector> _webMapServiceRasterOverlays; std::vector> _georeferences; std::vector> _globeAnchors; std::vector> _ionServers; diff --git a/src/core/include/cesium/omniverse/OmniWebMapServiceRasterOverlay.h b/src/core/include/cesium/omniverse/OmniWebMapServiceRasterOverlay.h new file mode 100644 index 00000000..e546ae71 --- /dev/null +++ b/src/core/include/cesium/omniverse/OmniWebMapServiceRasterOverlay.h @@ -0,0 +1,33 @@ +#pragma once + +#include "cesium/omniverse/OmniRasterOverlay.h" + +#include +#include + +#include + +namespace cesium::omniverse { + +class OmniWebMapServiceRasterOverlay final : public OmniRasterOverlay { + public: + OmniWebMapServiceRasterOverlay(Context* pContext, const pxr::SdfPath& path); + ~OmniWebMapServiceRasterOverlay() override = default; + OmniWebMapServiceRasterOverlay(const OmniWebMapServiceRasterOverlay&) = delete; + OmniWebMapServiceRasterOverlay& operator=(const OmniWebMapServiceRasterOverlay&) = delete; + OmniWebMapServiceRasterOverlay(OmniWebMapServiceRasterOverlay&&) noexcept = default; + OmniWebMapServiceRasterOverlay& operator=(OmniWebMapServiceRasterOverlay&&) noexcept = default; + + [[nodiscard]] CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const override; + [[nodiscard]] std::string getBaseUrl() const; + [[nodiscard]] int getMinimumLevel() const; + [[nodiscard]] int getMaximumLevel() const; + [[nodiscard]] int getTileWidth() const; + [[nodiscard]] int getTileHeight() const; + [[nodiscard]] std::string getLayers() const; + void reload() override; + + private: + CesiumUtility::IntrusivePointer _pWebMapServiceRasterOverlay; +}; +} // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/UsdNotificationHandler.h b/src/core/include/cesium/omniverse/UsdNotificationHandler.h index f9efb209..9308115e 100644 --- a/src/core/include/cesium/omniverse/UsdNotificationHandler.h +++ b/src/core/include/cesium/omniverse/UsdNotificationHandler.h @@ -25,6 +25,7 @@ class UsdNotificationHandler final : public pxr::TfWeakBase { CESIUM_TILESET, CESIUM_ION_RASTER_OVERLAY, CESIUM_POLYGON_RASTER_OVERLAY, + CESIUM_WEB_MAP_SERVICE_RASTER_OVERLAY, CESIUM_GEOREFERENCE, CESIUM_GLOBE_ANCHOR, CESIUM_ION_SERVER, diff --git a/src/core/include/cesium/omniverse/UsdUtil.h b/src/core/include/cesium/omniverse/UsdUtil.h index 3a348f7e..f3fb55ed 100644 --- a/src/core/include/cesium/omniverse/UsdUtil.h +++ b/src/core/include/cesium/omniverse/UsdUtil.h @@ -18,6 +18,7 @@ class CesiumIonServer; class CesiumPolygonRasterOverlay; class CesiumSession; class CesiumTileset; +class CesiumWebMapServiceRasterOverlay; class UsdGeomBasisCurves; class UsdGeomXformable; class UsdGeomXformOp; @@ -117,6 +118,8 @@ pxr::CesiumRasterOverlay getCesiumRasterOverlay(const pxr::UsdStageWeakPtr& pSta pxr::CesiumIonRasterOverlay getCesiumIonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); pxr::CesiumPolygonRasterOverlay getCesiumPolygonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); +pxr::CesiumWebMapServiceRasterOverlay +getCesiumWebMapServiceRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); pxr::CesiumGeoreference getCesiumGeoreference(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); pxr::CesiumGlobeAnchorAPI getCesiumGlobeAnchor(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); pxr::CesiumIonServer getCesiumIonServer(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); @@ -131,6 +134,7 @@ bool isCesiumTileset(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& pat bool isCesiumRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); bool isCesiumIonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); bool isCesiumPolygonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); +bool isCesiumWebMapServiceRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path); 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); diff --git a/src/core/src/AssetRegistry.cpp b/src/core/src/AssetRegistry.cpp index 8c91cdc0..578edec0 100644 --- a/src/core/src/AssetRegistry.cpp +++ b/src/core/src/AssetRegistry.cpp @@ -10,6 +10,7 @@ #include "cesium/omniverse/OmniIonServer.h" #include "cesium/omniverse/OmniPolygonRasterOverlay.h" #include "cesium/omniverse/OmniTileset.h" +#include "cesium/omniverse/OmniWebMapServiceRasterOverlay.h" #include "cesium/omniverse/UsdUtil.h" #include "cesium/omniverse/Viewport.h" @@ -131,23 +132,50 @@ OmniPolygonRasterOverlay* AssetRegistry::getPolygonRasterOverlay(const pxr::SdfP return nullptr; } +OmniWebMapServiceRasterOverlay& AssetRegistry::addWebMapServiceRasterOverlay(const pxr::SdfPath& path) { + return *_webMapServiceRasterOverlays + .insert( + _webMapServiceRasterOverlays.end(), + std::make_unique(_pContext, path)) + ->get(); +} + +void AssetRegistry::removeWebMapServiceRasterOverlay(const pxr::SdfPath& path) { + CppUtil::eraseIf(_webMapServiceRasterOverlays, [&path](const auto& pWebMapServiceRasterOverlay) { + return pWebMapServiceRasterOverlay->getPath() == path; + }); +} + +OmniWebMapServiceRasterOverlay* AssetRegistry::getWebMapServiceRasterOverlay(const pxr::SdfPath& path) const { + for (const auto& pWebMapServiceRasterOverlay : _webMapServiceRasterOverlays) { + if (pWebMapServiceRasterOverlay->getPath() == path) { + return pWebMapServiceRasterOverlay.get(); + } + } + + return nullptr; +} + const std::vector>& AssetRegistry::getPolygonRasterOverlays() const { return _polygonRasterOverlays; } OmniRasterOverlay* AssetRegistry::getRasterOverlay(const pxr::SdfPath& path) const { const auto pIonRasterOverlay = getIonRasterOverlay(path); - if (pIonRasterOverlay) { return pIonRasterOverlay; } const auto pPolygonRasterOverlay = getPolygonRasterOverlay(path); - if (pPolygonRasterOverlay) { return pPolygonRasterOverlay; } + const auto pWebMapServiceRasterOverlay = getWebMapServiceRasterOverlay(path); + if (pWebMapServiceRasterOverlay) { + return pWebMapServiceRasterOverlay; + } + return nullptr; } diff --git a/src/core/src/OmniTileset.cpp b/src/core/src/OmniTileset.cpp index 3dd461d2..846ca47e 100644 --- a/src/core/src/OmniTileset.cpp +++ b/src/core/src/OmniTileset.cpp @@ -16,9 +16,8 @@ #include "cesium/omniverse/OmniCartographicPolygon.h" #include "cesium/omniverse/OmniGeoreference.h" #include "cesium/omniverse/OmniGlobeAnchor.h" -#include "cesium/omniverse/OmniIonRasterOverlay.h" #include "cesium/omniverse/OmniIonServer.h" -#include "cesium/omniverse/OmniPolygonRasterOverlay.h" +#include "cesium/omniverse/OmniRasterOverlay.h" #include "cesium/omniverse/TaskProcessor.h" #include "cesium/omniverse/TilesetStatistics.h" #include "cesium/omniverse/UsdUtil.h" @@ -32,9 +31,6 @@ #include #include #include -#include -#include -#include #include #include #include diff --git a/src/core/src/OmniWebMapServiceRasterOverlay.cpp b/src/core/src/OmniWebMapServiceRasterOverlay.cpp new file mode 100644 index 00000000..95a9520a --- /dev/null +++ b/src/core/src/OmniWebMapServiceRasterOverlay.cpp @@ -0,0 +1,102 @@ +#include "cesium/omniverse/OmniWebMapServiceRasterOverlay.h" + +#include "cesium/omniverse/AssetRegistry.h" +#include "cesium/omniverse/Context.h" +#include "cesium/omniverse/GltfUtil.h" +#include "cesium/omniverse/Logger.h" +#include "cesium/omniverse/OmniGeoreference.h" +#include "cesium/omniverse/UsdUtil.h" + +#include +#include + +namespace cesium::omniverse { + +OmniWebMapServiceRasterOverlay::OmniWebMapServiceRasterOverlay(Context* pContext, const pxr::SdfPath& path) + : OmniRasterOverlay(pContext, path) { + reload(); +} + +CesiumRasterOverlays::RasterOverlay* OmniWebMapServiceRasterOverlay::getRasterOverlay() const { + return _pWebMapServiceRasterOverlay.get(); +} + +std::string OmniWebMapServiceRasterOverlay::getBaseUrl() const { + auto cesiumWebMapServiceRasterOverlay = + UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + std::string baseUrl; + cesiumWebMapServiceRasterOverlay.GetBaseUrlAttr().Get(&baseUrl); + return baseUrl; +} + +int OmniWebMapServiceRasterOverlay::getMinimumLevel() const { + auto cesiumWebMapServiceRasterOverlay = + UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + int val; + cesiumWebMapServiceRasterOverlay.GetMinimumLevelAttr().Get(&val); + return val; +} + +int OmniWebMapServiceRasterOverlay::getMaximumLevel() const { + auto cesiumWebMapServiceRasterOverlay = + UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + int val; + cesiumWebMapServiceRasterOverlay.GetMaximumLevelAttr().Get(&val); + return val; +} + +int OmniWebMapServiceRasterOverlay::getTileWidth() const { + auto cesiumWebMapServiceRasterOverlay = + UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + int val; + cesiumWebMapServiceRasterOverlay.GetTileWidthAttr().Get(&val); + return val; +} + +int OmniWebMapServiceRasterOverlay::getTileHeight() const { + auto cesiumWebMapServiceRasterOverlay = + UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + int val; + cesiumWebMapServiceRasterOverlay.GetTileHeightAttr().Get(&val); + return val; +} + +std::string OmniWebMapServiceRasterOverlay::getLayers() const { + auto cesiumWebMapServiceRasterOverlay = + UsdUtil::getCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), _path); + std::string val; + cesiumWebMapServiceRasterOverlay.GetLayersAttr().Get(&val); + return val; +} + +void OmniWebMapServiceRasterOverlay::reload() { + const auto rasterOverlayName = UsdUtil::getName(_pContext->getUsdStage(), _path); + + CesiumRasterOverlays::RasterOverlayOptions options; + options.showCreditsOnScreen = getShowCreditsOnScreen(); + // options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets(); + + options.loadErrorCallback = [this](const CesiumRasterOverlays::RasterOverlayLoadFailureDetails& error) { + _pContext->getLogger()->error(error.message); + }; + + CesiumRasterOverlays::WebMapServiceRasterOverlayOptions wmsOptions; + int minimumLevel = getMinimumLevel(); + int maximumLevel = getMaximumLevel(); + int tileWidth = getTileWidth(); + int tileHeight = getTileHeight(); + std::string layers = getLayers(); + + if (maximumLevel > minimumLevel) { + wmsOptions.minimumLevel = minimumLevel; + wmsOptions.maximumLevel = maximumLevel; + } + wmsOptions.layers = layers; + wmsOptions.tileWidth = tileWidth; + wmsOptions.tileHeight = tileHeight; + + _pWebMapServiceRasterOverlay = new CesiumRasterOverlays::WebMapServiceRasterOverlay( + rasterOverlayName, getBaseUrl(), std::vector(), wmsOptions, options); +} + +} // namespace cesium::omniverse diff --git a/src/core/src/UsdNotificationHandler.cpp b/src/core/src/UsdNotificationHandler.cpp index acfab35a..b28d9c93 100644 --- a/src/core/src/UsdNotificationHandler.cpp +++ b/src/core/src/UsdNotificationHandler.cpp @@ -13,6 +13,7 @@ #include "cesium/omniverse/OmniPolygonRasterOverlay.h" #include "cesium/omniverse/OmniRasterOverlay.h" #include "cesium/omniverse/OmniTileset.h" +#include "cesium/omniverse/OmniWebMapServiceRasterOverlay.h" #include "cesium/omniverse/UsdTokens.h" #include "cesium/omniverse/UsdUtil.h" @@ -318,6 +319,39 @@ void processCesiumPolygonRasterOverlayChanged( } } +void processCesiumWebMapServiceRasterOverlayChanged( + const Context& context, + const pxr::SdfPath& webMapServiceRasterOverlayPath, + const std::vector& properties) { + + const auto pWebMapServiceRasterOverlay = + context.getAssetRegistry().getWebMapServiceRasterOverlay(webMapServiceRasterOverlayPath); + if (!pWebMapServiceRasterOverlay) { + return; + } + + // Process base class first + processCesiumRasterOverlayChanged(context, webMapServiceRasterOverlayPath, properties); + + auto reload = false; + auto updateBindings = false; + + for (const auto& property : properties) { + if (property == pxr::CesiumTokens->cesiumBaseUrl || property == pxr::CesiumTokens->cesiumLayers) { + reload = true; + updateBindings = true; + } + } + + if (reload) { + pWebMapServiceRasterOverlay->reload(); + } + + if (updateBindings) { + updateRasterOverlayBindings(context, webMapServiceRasterOverlayPath); + } +} + void processCesiumGeoreferenceChanged(const Context& context, const std::vector& properties) { auto updateBindings = false; @@ -546,6 +580,13 @@ void processCesiumPolygonRasterOverlayRemoved(Context& context, const pxr::SdfPa updateRasterOverlayBindings(context, polygonRasterOverlayPath); } +void processCesiumWebMapServiceRasterOverlayRemoved( + Context& context, + const pxr::SdfPath& webMapServiceRasterOverlayPath) { + context.getAssetRegistry().removeWebMapServiceRasterOverlay(webMapServiceRasterOverlayPath); + updateRasterOverlayBindings(context, webMapServiceRasterOverlayPath); +} + void processCesiumGeoreferenceRemoved(Context& context, const pxr::SdfPath& georeferencePath) { context.getAssetRegistry().removeGeoreference(georeferencePath); updateGeoreferenceBindings(context); @@ -586,6 +627,13 @@ void processCesiumPolygonRasterOverlayAdded(Context& context, const pxr::SdfPath updateRasterOverlayBindings(context, polygonRasterOverlayPath); } +void processCesiumWebMapServiceRasterOverlayAdded( + Context& context, + const pxr::SdfPath& webMapServiceRasterOverlayPath) { + context.getAssetRegistry().addWebMapServiceRasterOverlay(webMapServiceRasterOverlayPath); + updateRasterOverlayBindings(context, webMapServiceRasterOverlayPath); +} + void processCesiumGeoreferenceAdded(Context& context, const pxr::SdfPath& georeferencePath) { context.getAssetRegistry().addGeoreference(georeferencePath); updateGeoreferenceBindings(context); @@ -703,6 +751,10 @@ bool UsdNotificationHandler::processChangedPrim(const ChangedPrim& changedPrim) case ChangedPrimType::CESIUM_POLYGON_RASTER_OVERLAY: processCesiumPolygonRasterOverlayChanged(*_pContext, changedPrim.primPath, changedPrim.properties); break; + case ChangedPrimType::CESIUM_WEB_MAP_SERVICE_RASTER_OVERLAY: + processCesiumWebMapServiceRasterOverlayChanged( + *_pContext, changedPrim.primPath, changedPrim.properties); + break; case ChangedPrimType::CESIUM_GEOREFERENCE: processCesiumGeoreferenceChanged(*_pContext, changedPrim.properties); break; @@ -736,6 +788,9 @@ bool UsdNotificationHandler::processChangedPrim(const ChangedPrim& changedPrim) case ChangedPrimType::CESIUM_POLYGON_RASTER_OVERLAY: processCesiumPolygonRasterOverlayAdded(*_pContext, changedPrim.primPath); break; + case ChangedPrimType::CESIUM_WEB_MAP_SERVICE_RASTER_OVERLAY: + processCesiumWebMapServiceRasterOverlayAdded(*_pContext, changedPrim.primPath); + break; case ChangedPrimType::CESIUM_GEOREFERENCE: processCesiumGeoreferenceAdded(*_pContext, changedPrim.primPath); break; @@ -767,6 +822,9 @@ bool UsdNotificationHandler::processChangedPrim(const ChangedPrim& changedPrim) case ChangedPrimType::CESIUM_POLYGON_RASTER_OVERLAY: processCesiumPolygonRasterOverlayRemoved(*_pContext, changedPrim.primPath); break; + case ChangedPrimType::CESIUM_WEB_MAP_SERVICE_RASTER_OVERLAY: + processCesiumWebMapServiceRasterOverlayRemoved(*_pContext, changedPrim.primPath); + break; case ChangedPrimType::CESIUM_GEOREFERENCE: processCesiumGeoreferenceRemoved(*_pContext, changedPrim.primPath); break; @@ -963,6 +1021,8 @@ UsdNotificationHandler::ChangedPrimType UsdNotificationHandler::getTypeFromStage return ChangedPrimType::CESIUM_ION_RASTER_OVERLAY; } else if (UsdUtil::isCesiumPolygonRasterOverlay(_pContext->getUsdStage(), path)) { return ChangedPrimType::CESIUM_POLYGON_RASTER_OVERLAY; + } else if (UsdUtil::isCesiumWebMapServiceRasterOverlay(_pContext->getUsdStage(), path)) { + return ChangedPrimType::CESIUM_WEB_MAP_SERVICE_RASTER_OVERLAY; } else if (UsdUtil::isCesiumGeoreference(_pContext->getUsdStage(), path)) { return ChangedPrimType::CESIUM_GEOREFERENCE; } else if (UsdUtil::isCesiumIonServer(_pContext->getUsdStage(), path)) { @@ -992,6 +1052,8 @@ UsdNotificationHandler::getTypeFromAssetRegistry(const pxr::SdfPath& path) const return ChangedPrimType::CESIUM_ION_RASTER_OVERLAY; case AssetType::POLYGON_RASTER_OVERLAY: return ChangedPrimType::CESIUM_POLYGON_RASTER_OVERLAY; + case AssetType::WEB_MAP_SERVICE_RASTER_OVERLAY: + return ChangedPrimType::CESIUM_WEB_MAP_SERVICE_RASTER_OVERLAY; case AssetType::GEOREFERENCE: return ChangedPrimType::CESIUM_GEOREFERENCE; case AssetType::GLOBE_ANCHOR: diff --git a/src/core/src/UsdUtil.cpp b/src/core/src/UsdUtil.cpp index bf0acc2e..a9e56015 100644 --- a/src/core/src/UsdUtil.cpp +++ b/src/core/src/UsdUtil.cpp @@ -1,5 +1,7 @@ #include "cesium/omniverse/UsdUtil.h" +#include "CesiumUsdSchemas/webMapServiceRasterOverlay.h" + #include "cesium/omniverse/AssetRegistry.h" #include "cesium/omniverse/Context.h" #include "cesium/omniverse/CppUtil.h" @@ -25,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -359,6 +362,11 @@ getCesiumPolygonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::Sdf return pxr::CesiumPolygonRasterOverlay::Get(pStage, path); } +pxr::CesiumWebMapServiceRasterOverlay +getCesiumWebMapServiceRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { + return pxr::CesiumWebMapServiceRasterOverlay::Get(pStage, path); +} + pxr::CesiumGeoreference getCesiumGeoreference(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { return pxr::CesiumGeoreference::Get(pStage, path); } @@ -449,6 +457,15 @@ bool isCesiumPolygonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr: return prim.IsA(); } +bool isCesiumWebMapServiceRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { + const auto prim = pStage->GetPrimAtPath(path); + if (!prim.IsValid()) { + return false; + } + + return prim.IsA(); +} + bool isCesiumGeoreference(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) { const auto prim = pStage->GetPrimAtPath(path); if (!prim.IsValid()) { diff --git a/src/plugins/CesiumUsdSchemas/CMakeLists.txt b/src/plugins/CesiumUsdSchemas/CMakeLists.txt index 126150ac..04a4827e 100644 --- a/src/plugins/CesiumUsdSchemas/CMakeLists.txt +++ b/src/plugins/CesiumUsdSchemas/CMakeLists.txt @@ -10,7 +10,8 @@ set(SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/polygonRasterOverlay.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/session.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/tileset.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/tokens.cpp") + "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/tokens.cpp" + "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/webMapServiceRasterOverlay.cpp") set(PY_BINDING_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/module.cpp" @@ -24,7 +25,8 @@ set(PY_BINDING_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapPolygonRasterOverlay.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapSession.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapTileset.cpp" - "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapTokens.cpp") + "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapTokens.cpp" + "${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapWebMapServiceRasterOverlay.cpp") set(CESIUM_USD_SCHEMAS_CXX_FLAGS ${CESIUM_OMNI_CXX_FLAGS}) diff --git a/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in b/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in index e9885dde..b102945a 100644 --- a/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in +++ b/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in @@ -343,7 +343,7 @@ class "CesiumRasterOverlayPrim" ( } class CesiumIonRasterOverlayPrim "CesiumIonRasterOverlayPrim" ( - doc = "Adds a prim for representing an Ion raster overlay. Should be a child of a tileset." + doc = "Adds a prim for representing an Ion raster overlay." ) { float cesium:alpha = 1 ( @@ -374,7 +374,7 @@ class CesiumIonRasterOverlayPrim "CesiumIonRasterOverlayPrim" ( } class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" ( - doc = "Adds a prim for representing a polygon raster overlay. Should be a child of a tileset." + doc = "Adds a prim for representing a polygon raster overlay." ) { float cesium:alpha = 1 ( @@ -400,6 +400,49 @@ class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" ( ) } +class CesiumWebMapServiceRasterOverlayPrim "CesiumWebMapServiceRasterOverlayPrim" ( + doc = "Adds a prim for representing a Web Map Service raster overlay." +) +{ + float cesium:alpha = 1 ( + displayName = "Alpha" + doc = "The alpha blending value, from 0.0 to 1.0, where 1.0 is fully opaque." + ) + string cesium:baseUrl = "" ( + displayName = "Base URL" + doc = "The base url of the Web Map Service (WMS). e.g. https://services.ga.gov.au/gis/services/NM_Culture_and_Infrastructure/MapServer/WMSServer" + ) + string cesium:layers = "1" ( + displayName = "Layers" + doc = "Comma-separated layer names to request from the server." + ) + int cesium:maximumLevel = 14 ( + displayName = "Maximum Level" + doc = "Maximum zoom level." + ) + int cesium:minimumLevel = 0 ( + displayName = "Minimum Level" + doc = "Take care when specifying this that the number of tiles at the minimum level is small, such as four or less. A larger number is likely to result in rendering problems." + ) + uniform token cesium:overlayRenderMethod = "overlay" ( + allowedTokens = ["overlay", "clip"] + displayName = "Overlay Render Method" + doc = "The Cesium default material will give the raster overlay a different rendering treatment based on this selection." + ) + bool cesium:showCreditsOnScreen = 0 ( + displayName = "Show Credits On Screen" + doc = "Whether or not to show this raster overlay's credits on screen." + ) + int cesium:tileHeight = 256 ( + displayName = "Tile Height" + doc = "Image height" + ) + int cesium:tileWidth = 256 ( + displayName = "Tile Width" + doc = "Image width" + ) +} + class "CesiumGlobeAnchorSchemaAPI" ( doc = "Adds Globe Anchoring information to a Prim for use with Cesium for Omniverse." ) diff --git a/src/plugins/CesiumUsdSchemas/plugInfo.json.in b/src/plugins/CesiumUsdSchemas/plugInfo.json.in index 8e082979..55fad6d4 100644 --- a/src/plugins/CesiumUsdSchemas/plugInfo.json.in +++ b/src/plugins/CesiumUsdSchemas/plugInfo.json.in @@ -95,6 +95,16 @@ "UsdGeomGprim" ], "schemaKind": "concreteTyped" + }, + "CesiumWebMapServiceRasterOverlay": { + "alias": { + "UsdSchemaBase": "CesiumWebMapServiceRasterOverlayPrim" + }, + "autoGenerated": true, + "bases": [ + "CesiumRasterOverlay" + ], + "schemaKind": "concreteTyped" } } }, diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/ionRasterOverlay.h b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/ionRasterOverlay.h index 2d9d7969..b6a4f946 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/ionRasterOverlay.h +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/ionRasterOverlay.h @@ -29,7 +29,7 @@ class SdfAssetPath; /// \class CesiumIonRasterOverlay /// -/// Adds a prim for representing an Ion raster overlay. Should be a child of a tileset. +/// Adds a prim for representing an Ion raster overlay. /// class CesiumIonRasterOverlay : public CesiumRasterOverlay { diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/module.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/module.cpp index d4c5ddea..e2c334fb 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/module.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/module.cpp @@ -15,4 +15,5 @@ TF_WRAP_MODULE TF_WRAP(CesiumSession); TF_WRAP(CesiumTileset); TF_WRAP(CesiumTokens); + TF_WRAP(CesiumWebMapServiceRasterOverlay); } diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/polygonRasterOverlay.h b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/polygonRasterOverlay.h index 3fb35b64..b3a0d41e 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/polygonRasterOverlay.h +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/polygonRasterOverlay.h @@ -29,7 +29,7 @@ class SdfAssetPath; /// \class CesiumPolygonRasterOverlay /// -/// Adds a prim for representing a polygon raster overlay. Should be a child of a tileset. +/// Adds a prim for representing a polygon raster overlay. /// /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below /// that are text/tokens, the actual token is published and defined in \ref CesiumTokens. diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp index fae97443..3e616e87 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp @@ -11,6 +11,7 @@ CesiumTokensType::CesiumTokensType() : cesiumAnchorLatitude("cesium:anchor:latitude", TfToken::Immortal), cesiumAnchorLongitude("cesium:anchor:longitude", TfToken::Immortal), cesiumAnchorPosition("cesium:anchor:position", TfToken::Immortal), + cesiumBaseUrl("cesium:baseUrl", TfToken::Immortal), cesiumCartographicPolygonBinding("cesium:cartographicPolygonBinding", TfToken::Immortal), cesiumCulledScreenSpaceError("cesium:culledScreenSpaceError", TfToken::Immortal), cesiumDebugDisableGeometryPool("cesium:debug:disableGeometryPool", TfToken::Immortal), @@ -40,11 +41,14 @@ CesiumTokensType::CesiumTokensType() : cesiumIonServerApplicationId("cesium:ionServerApplicationId", TfToken::Immortal), cesiumIonServerBinding("cesium:ionServerBinding", TfToken::Immortal), cesiumIonServerUrl("cesium:ionServerUrl", TfToken::Immortal), + cesiumLayers("cesium:layers", TfToken::Immortal), cesiumLoadingDescendantLimit("cesium:loadingDescendantLimit", TfToken::Immortal), cesiumMainThreadLoadingTimeLimit("cesium:mainThreadLoadingTimeLimit", TfToken::Immortal), cesiumMaximumCachedBytes("cesium:maximumCachedBytes", TfToken::Immortal), + cesiumMaximumLevel("cesium:maximumLevel", TfToken::Immortal), cesiumMaximumScreenSpaceError("cesium:maximumScreenSpaceError", TfToken::Immortal), cesiumMaximumSimultaneousTileLoads("cesium:maximumSimultaneousTileLoads", TfToken::Immortal), + cesiumMinimumLevel("cesium:minimumLevel", TfToken::Immortal), cesiumOverlayRenderMethod("cesium:overlayRenderMethod", TfToken::Immortal), cesiumPreloadAncestors("cesium:preloadAncestors", TfToken::Immortal), cesiumPreloadSiblings("cesium:preloadSiblings", TfToken::Immortal), @@ -56,6 +60,8 @@ CesiumTokensType::CesiumTokensType() : cesiumSmoothNormals("cesium:smoothNormals", TfToken::Immortal), cesiumSourceType("cesium:sourceType", TfToken::Immortal), cesiumSuspendUpdate("cesium:suspendUpdate", TfToken::Immortal), + cesiumTileHeight("cesium:tileHeight", TfToken::Immortal), + cesiumTileWidth("cesium:tileWidth", TfToken::Immortal), cesiumUrl("cesium:url", TfToken::Immortal), clip("clip", TfToken::Immortal), ion("ion", TfToken::Immortal), @@ -70,6 +76,7 @@ CesiumTokensType::CesiumTokensType() : cesiumAnchorLatitude, cesiumAnchorLongitude, cesiumAnchorPosition, + cesiumBaseUrl, cesiumCartographicPolygonBinding, cesiumCulledScreenSpaceError, cesiumDebugDisableGeometryPool, @@ -99,11 +106,14 @@ CesiumTokensType::CesiumTokensType() : cesiumIonServerApplicationId, cesiumIonServerBinding, cesiumIonServerUrl, + cesiumLayers, cesiumLoadingDescendantLimit, cesiumMainThreadLoadingTimeLimit, cesiumMaximumCachedBytes, + cesiumMaximumLevel, cesiumMaximumScreenSpaceError, cesiumMaximumSimultaneousTileLoads, + cesiumMinimumLevel, cesiumOverlayRenderMethod, cesiumPreloadAncestors, cesiumPreloadSiblings, @@ -115,6 +125,8 @@ CesiumTokensType::CesiumTokensType() : cesiumSmoothNormals, cesiumSourceType, cesiumSuspendUpdate, + cesiumTileHeight, + cesiumTileWidth, cesiumUrl, clip, ion, diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h index 0445dddd..ce48fa09 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h @@ -71,6 +71,10 @@ struct CesiumTokensType { /// /// CesiumGlobeAnchorAPI const TfToken cesiumAnchorPosition; + /// \brief "cesium:baseUrl" + /// + /// CesiumWebMapServiceRasterOverlay + const TfToken cesiumBaseUrl; /// \brief "cesium:cartographicPolygonBinding" /// /// CesiumPolygonRasterOverlay @@ -187,6 +191,10 @@ struct CesiumTokensType { /// /// CesiumIonServer const TfToken cesiumIonServerUrl; + /// \brief "cesium:layers" + /// + /// CesiumWebMapServiceRasterOverlay + const TfToken cesiumLayers; /// \brief "cesium:loadingDescendantLimit" /// /// CesiumTileset @@ -199,6 +207,10 @@ struct CesiumTokensType { /// /// CesiumTileset const TfToken cesiumMaximumCachedBytes; + /// \brief "cesium:maximumLevel" + /// + /// CesiumWebMapServiceRasterOverlay + const TfToken cesiumMaximumLevel; /// \brief "cesium:maximumScreenSpaceError" /// /// CesiumTileset @@ -207,6 +219,10 @@ struct CesiumTokensType { /// /// CesiumTileset const TfToken cesiumMaximumSimultaneousTileLoads; + /// \brief "cesium:minimumLevel" + /// + /// CesiumWebMapServiceRasterOverlay + const TfToken cesiumMinimumLevel; /// \brief "cesium:overlayRenderMethod" /// /// CesiumPolygonRasterOverlay, CesiumRasterOverlay @@ -251,6 +267,14 @@ struct CesiumTokensType { /// /// CesiumTileset const TfToken cesiumSuspendUpdate; + /// \brief "cesium:tileHeight" + /// + /// CesiumWebMapServiceRasterOverlay + const TfToken cesiumTileHeight; + /// \brief "cesium:tileWidth" + /// + /// CesiumWebMapServiceRasterOverlay + const TfToken cesiumTileWidth; /// \brief "cesium:url" /// /// CesiumTileset diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.cpp new file mode 100644 index 00000000..89ef1ea4 --- /dev/null +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.cpp @@ -0,0 +1,229 @@ +#include ".//webMapServiceRasterOverlay.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + + // Register the usd prim typename as an alias under UsdSchemaBase. This + // enables one to call + // TfType::Find().FindDerivedByName("CesiumWebMapServiceRasterOverlayPrim") + // to find TfType, which is how IsA queries are + // answered. + TfType::AddAlias("CesiumWebMapServiceRasterOverlayPrim"); +} + +/* virtual */ +CesiumWebMapServiceRasterOverlay::~CesiumWebMapServiceRasterOverlay() +{ +} + +/* static */ +CesiumWebMapServiceRasterOverlay +CesiumWebMapServiceRasterOverlay::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return CesiumWebMapServiceRasterOverlay(); + } + return CesiumWebMapServiceRasterOverlay(stage->GetPrimAtPath(path)); +} + +/* static */ +CesiumWebMapServiceRasterOverlay +CesiumWebMapServiceRasterOverlay::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("CesiumWebMapServiceRasterOverlayPrim"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return CesiumWebMapServiceRasterOverlay(); + } + return CesiumWebMapServiceRasterOverlay( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind CesiumWebMapServiceRasterOverlay::_GetSchemaKind() const +{ + return CesiumWebMapServiceRasterOverlay::schemaKind; +} + +/* static */ +const TfType & +CesiumWebMapServiceRasterOverlay::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +CesiumWebMapServiceRasterOverlay::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +CesiumWebMapServiceRasterOverlay::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::GetBaseUrlAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumBaseUrl); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::CreateBaseUrlAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumBaseUrl, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::GetLayersAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumLayers); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::CreateLayersAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumLayers, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::GetTileWidthAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumTileWidth); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::CreateTileWidthAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumTileWidth, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::GetTileHeightAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumTileHeight); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::CreateTileHeightAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumTileHeight, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::GetMinimumLevelAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumMinimumLevel); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::CreateMinimumLevelAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumMinimumLevel, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::GetMaximumLevelAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumMaximumLevel); +} + +UsdAttribute +CesiumWebMapServiceRasterOverlay::CreateMaximumLevelAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumMaximumLevel, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +CesiumWebMapServiceRasterOverlay::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + CesiumTokens->cesiumBaseUrl, + CesiumTokens->cesiumLayers, + CesiumTokens->cesiumTileWidth, + CesiumTokens->cesiumTileHeight, + CesiumTokens->cesiumMinimumLevel, + CesiumTokens->cesiumMaximumLevel, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + CesiumRasterOverlay::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.h b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.h new file mode 100644 index 00000000..c099d617 --- /dev/null +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/webMapServiceRasterOverlay.h @@ -0,0 +1,275 @@ +#ifndef CESIUMUSDSCHEMAS_GENERATED_WEBMAPSERVICERASTEROVERLAY_H +#define CESIUMUSDSCHEMAS_GENERATED_WEBMAPSERVICERASTEROVERLAY_H + +/// \file CesiumUsdSchemas/webMapServiceRasterOverlay.h + +#include "pxr/pxr.h" +#include ".//api.h" +#include ".//rasterOverlay.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include ".//tokens.h" + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// CESIUMWEBMAPSERVICERASTEROVERLAYPRIM // +// -------------------------------------------------------------------------- // + +/// \class CesiumWebMapServiceRasterOverlay +/// +/// Adds a prim for representing a Web Map Service raster overlay. +/// +class CesiumWebMapServiceRasterOverlay : public CesiumRasterOverlay +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a CesiumWebMapServiceRasterOverlay on UsdPrim \p prim . + /// Equivalent to CesiumWebMapServiceRasterOverlay::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit CesiumWebMapServiceRasterOverlay(const UsdPrim& prim=UsdPrim()) + : CesiumRasterOverlay(prim) + { + } + + /// Construct a CesiumWebMapServiceRasterOverlay on the prim held by \p schemaObj . + /// Should be preferred over CesiumWebMapServiceRasterOverlay(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit CesiumWebMapServiceRasterOverlay(const UsdSchemaBase& schemaObj) + : CesiumRasterOverlay(schemaObj) + { + } + + /// Destructor. + CESIUMUSDSCHEMAS_API + virtual ~CesiumWebMapServiceRasterOverlay(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + CESIUMUSDSCHEMAS_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a CesiumWebMapServiceRasterOverlay holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// CesiumWebMapServiceRasterOverlay(stage->GetPrimAtPath(path)); + /// \endcode + /// + CESIUMUSDSCHEMAS_API + static CesiumWebMapServiceRasterOverlay + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + CESIUMUSDSCHEMAS_API + static CesiumWebMapServiceRasterOverlay + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + CESIUMUSDSCHEMAS_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + CESIUMUSDSCHEMAS_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + CESIUMUSDSCHEMAS_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // BASEURL + // --------------------------------------------------------------------- // + /// The base url of the Web Map Service (WMS). e.g. https://services.ga.gov.au/gis/services/NM_Culture_and_Infrastructure/MapServer/WMSServer + /// + /// | || + /// | -- | -- | + /// | Declaration | `string cesium:baseUrl = ""` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + CESIUMUSDSCHEMAS_API + UsdAttribute GetBaseUrlAttr() const; + + /// See GetBaseUrlAttr(), 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 CreateBaseUrlAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // LAYERS + // --------------------------------------------------------------------- // + /// Comma-separated layer names to request from the server. + /// + /// | || + /// | -- | -- | + /// | Declaration | `string cesium:layers = "1"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + CESIUMUSDSCHEMAS_API + UsdAttribute GetLayersAttr() const; + + /// See GetLayersAttr(), 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 CreateLayersAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // TILEWIDTH + // --------------------------------------------------------------------- // + /// Image width + /// + /// | || + /// | -- | -- | + /// | Declaration | `int cesium:tileWidth = 256` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + CESIUMUSDSCHEMAS_API + UsdAttribute GetTileWidthAttr() const; + + /// See GetTileWidthAttr(), 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 CreateTileWidthAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // TILEHEIGHT + // --------------------------------------------------------------------- // + /// Image height + /// + /// | || + /// | -- | -- | + /// | Declaration | `int cesium:tileHeight = 256` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + CESIUMUSDSCHEMAS_API + UsdAttribute GetTileHeightAttr() const; + + /// See GetTileHeightAttr(), 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 CreateTileHeightAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // MINIMUMLEVEL + // --------------------------------------------------------------------- // + /// Take care when specifying this that the number of tiles at the minimum level is small, such as four or less. A larger number is likely to result in rendering problems. + /// + /// | || + /// | -- | -- | + /// | Declaration | `int cesium:minimumLevel = 0` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + CESIUMUSDSCHEMAS_API + UsdAttribute GetMinimumLevelAttr() const; + + /// See GetMinimumLevelAttr(), 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 CreateMinimumLevelAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // MAXIMUMLEVEL + // --------------------------------------------------------------------- // + /// Maximum zoom level. + /// + /// | || + /// | -- | -- | + /// | Declaration | `int cesium:maximumLevel = 14` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + CESIUMUSDSCHEMAS_API + UsdAttribute GetMaximumLevelAttr() const; + + /// See GetMaximumLevelAttr(), 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 CreateMaximumLevelAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp index c2498372..0946b844 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp @@ -49,6 +49,7 @@ void wrapCesiumTokens() _AddToken(cls, "cesiumAnchorLatitude", CesiumTokens->cesiumAnchorLatitude); _AddToken(cls, "cesiumAnchorLongitude", CesiumTokens->cesiumAnchorLongitude); _AddToken(cls, "cesiumAnchorPosition", CesiumTokens->cesiumAnchorPosition); + _AddToken(cls, "cesiumBaseUrl", CesiumTokens->cesiumBaseUrl); _AddToken(cls, "cesiumCartographicPolygonBinding", CesiumTokens->cesiumCartographicPolygonBinding); _AddToken(cls, "cesiumCulledScreenSpaceError", CesiumTokens->cesiumCulledScreenSpaceError); _AddToken(cls, "cesiumDebugDisableGeometryPool", CesiumTokens->cesiumDebugDisableGeometryPool); @@ -78,11 +79,14 @@ void wrapCesiumTokens() _AddToken(cls, "cesiumIonServerApplicationId", CesiumTokens->cesiumIonServerApplicationId); _AddToken(cls, "cesiumIonServerBinding", CesiumTokens->cesiumIonServerBinding); _AddToken(cls, "cesiumIonServerUrl", CesiumTokens->cesiumIonServerUrl); + _AddToken(cls, "cesiumLayers", CesiumTokens->cesiumLayers); _AddToken(cls, "cesiumLoadingDescendantLimit", CesiumTokens->cesiumLoadingDescendantLimit); _AddToken(cls, "cesiumMainThreadLoadingTimeLimit", CesiumTokens->cesiumMainThreadLoadingTimeLimit); _AddToken(cls, "cesiumMaximumCachedBytes", CesiumTokens->cesiumMaximumCachedBytes); + _AddToken(cls, "cesiumMaximumLevel", CesiumTokens->cesiumMaximumLevel); _AddToken(cls, "cesiumMaximumScreenSpaceError", CesiumTokens->cesiumMaximumScreenSpaceError); _AddToken(cls, "cesiumMaximumSimultaneousTileLoads", CesiumTokens->cesiumMaximumSimultaneousTileLoads); + _AddToken(cls, "cesiumMinimumLevel", CesiumTokens->cesiumMinimumLevel); _AddToken(cls, "cesiumOverlayRenderMethod", CesiumTokens->cesiumOverlayRenderMethod); _AddToken(cls, "cesiumPreloadAncestors", CesiumTokens->cesiumPreloadAncestors); _AddToken(cls, "cesiumPreloadSiblings", CesiumTokens->cesiumPreloadSiblings); @@ -94,6 +98,8 @@ void wrapCesiumTokens() _AddToken(cls, "cesiumSmoothNormals", CesiumTokens->cesiumSmoothNormals); _AddToken(cls, "cesiumSourceType", CesiumTokens->cesiumSourceType); _AddToken(cls, "cesiumSuspendUpdate", CesiumTokens->cesiumSuspendUpdate); + _AddToken(cls, "cesiumTileHeight", CesiumTokens->cesiumTileHeight); + _AddToken(cls, "cesiumTileWidth", CesiumTokens->cesiumTileWidth); _AddToken(cls, "cesiumUrl", CesiumTokens->cesiumUrl); _AddToken(cls, "clip", CesiumTokens->clip); _AddToken(cls, "ion", CesiumTokens->ion); diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapWebMapServiceRasterOverlay.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapWebMapServiceRasterOverlay.cpp new file mode 100644 index 00000000..b179cc04 --- /dev/null +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapWebMapServiceRasterOverlay.cpp @@ -0,0 +1,185 @@ +#include ".//webMapServiceRasterOverlay.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateBaseUrlAttr(CesiumWebMapServiceRasterOverlay &self, + object defaultVal, bool writeSparsely) { + return self.CreateBaseUrlAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateLayersAttr(CesiumWebMapServiceRasterOverlay &self, + object defaultVal, bool writeSparsely) { + return self.CreateLayersAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateTileWidthAttr(CesiumWebMapServiceRasterOverlay &self, + object defaultVal, bool writeSparsely) { + return self.CreateTileWidthAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateTileHeightAttr(CesiumWebMapServiceRasterOverlay &self, + object defaultVal, bool writeSparsely) { + return self.CreateTileHeightAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateMinimumLevelAttr(CesiumWebMapServiceRasterOverlay &self, + object defaultVal, bool writeSparsely) { + return self.CreateMinimumLevelAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateMaximumLevelAttr(CesiumWebMapServiceRasterOverlay &self, + object defaultVal, bool writeSparsely) { + return self.CreateMaximumLevelAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static std::string +_Repr(const CesiumWebMapServiceRasterOverlay &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "CesiumUsdSchemas.WebMapServiceRasterOverlay(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapCesiumWebMapServiceRasterOverlay() +{ + typedef CesiumWebMapServiceRasterOverlay This; + + class_ > + cls("WebMapServiceRasterOverlay"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetBaseUrlAttr", + &This::GetBaseUrlAttr) + .def("CreateBaseUrlAttr", + &_CreateBaseUrlAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetLayersAttr", + &This::GetLayersAttr) + .def("CreateLayersAttr", + &_CreateLayersAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetTileWidthAttr", + &This::GetTileWidthAttr) + .def("CreateTileWidthAttr", + &_CreateTileWidthAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetTileHeightAttr", + &This::GetTileHeightAttr) + .def("CreateTileHeightAttr", + &_CreateTileHeightAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetMinimumLevelAttr", + &This::GetMinimumLevelAttr) + .def("CreateMinimumLevelAttr", + &_CreateMinimumLevelAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetMaximumLevelAttr", + &This::GetMaximumLevelAttr) + .def("CreateMaximumLevelAttr", + &_CreateMaximumLevelAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} From db0aeff1487e362f5cc2b2dd14b5100f7b8e156c Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Tue, 6 Feb 2024 18:29:48 -0800 Subject: [PATCH 2/8] python formatting --- .../cesium/omniverse/ui/attributes/__init__.py | 4 +++- .../web_map_service_raster_overlay_attributes_widget.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py index aebdcc5b..421a57ad 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py @@ -5,4 +5,6 @@ from .ion_server_attributes_widget import CesiumIonServerAttributesWidget # noqa: F401 from .ion_raster_overlay_attributes_widget import CesiumIonRasterOverlayAttributesWidget # noqa: F401 from .polygon_raster_overlay_attributes_widget import CesiumPolygonRasterOverlayAttributesWidget # noqa: F401 -from .web_map_service_raster_overlay_attributes_widget import CesiumWebMapServiceRasterOverlayAttributesWidget # noqa: F401 +from .web_map_service_raster_overlay_attributes_widget import ( + CesiumWebMapServiceRasterOverlayAttributesWidget, +) # noqa: F401 diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py index 90c38180..0872c90b 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py @@ -4,13 +4,14 @@ from cesium.usd.plugins.CesiumUsdSchemas import ( WebMapServiceRasterOverlay as CesiumWebMapServiceRasterOverlay, ) -from pxr import UsdGeom from .custom_attribute_widgets import build_slider class CesiumWebMapServiceRasterOverlayAttributesWidget(SchemaPropertiesWidget): def __init__(self): - super().__init__("Cesium Web Map Service Raster Overlay Settings", CesiumWebMapServiceRasterOverlay, include_inherited=True) + super().__init__( + "Cesium Web Map Service Raster Overlay Settings", CesiumWebMapServiceRasterOverlay, include_inherited=True + ) self._logger = logging.getLogger(__name__) From 27df2af5b47db636b06dc10f18c9e1cddc114891 Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Tue, 6 Feb 2024 18:33:17 -0800 Subject: [PATCH 3/8] noqa change to __init__ file --- .../cesium/omniverse/ui/attributes/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py index 421a57ad..3f878f0b 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/__init__.py @@ -5,6 +5,6 @@ from .ion_server_attributes_widget import CesiumIonServerAttributesWidget # noqa: F401 from .ion_raster_overlay_attributes_widget import CesiumIonRasterOverlayAttributesWidget # noqa: F401 from .polygon_raster_overlay_attributes_widget import CesiumPolygonRasterOverlayAttributesWidget # noqa: F401 -from .web_map_service_raster_overlay_attributes_widget import ( +from .web_map_service_raster_overlay_attributes_widget import ( # noqa: F401 CesiumWebMapServiceRasterOverlayAttributesWidget, -) # noqa: F401 +) From 6887032bc14d7bf7c3dbb12c9caa1adf1f4b5d78 Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Wed, 7 Feb 2024 11:20:26 -0800 Subject: [PATCH 4/8] tweaks from PR review --- exts/cesium.usd.plugins/schemas/cesium_schemas.usda | 2 +- src/core/src/OmniWebMapServiceRasterOverlay.cpp | 10 +++++----- src/core/src/UsdNotificationHandler.cpp | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/exts/cesium.usd.plugins/schemas/cesium_schemas.usda b/exts/cesium.usd.plugins/schemas/cesium_schemas.usda index 2551787b..98c947cf 100644 --- a/exts/cesium.usd.plugins/schemas/cesium_schemas.usda +++ b/exts/cesium.usd.plugins/schemas/cesium_schemas.usda @@ -455,7 +455,7 @@ class "CesiumRasterOverlayPrim" ( } class CesiumIonRasterOverlayPrim "CesiumIonRasterOverlayPrim" ( - doc = """Adds a prim for representing an Ion raster overlay.""" + doc = """Adds a prim for representing an ion raster overlay.""" inherits = customData = { string className = "IonRasterOverlay" diff --git a/src/core/src/OmniWebMapServiceRasterOverlay.cpp b/src/core/src/OmniWebMapServiceRasterOverlay.cpp index 95a9520a..8eb70ea0 100644 --- a/src/core/src/OmniWebMapServiceRasterOverlay.cpp +++ b/src/core/src/OmniWebMapServiceRasterOverlay.cpp @@ -74,17 +74,17 @@ void OmniWebMapServiceRasterOverlay::reload() { CesiumRasterOverlays::RasterOverlayOptions options; options.showCreditsOnScreen = getShowCreditsOnScreen(); - // options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets(); + options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets(); options.loadErrorCallback = [this](const CesiumRasterOverlays::RasterOverlayLoadFailureDetails& error) { _pContext->getLogger()->error(error.message); }; CesiumRasterOverlays::WebMapServiceRasterOverlayOptions wmsOptions; - int minimumLevel = getMinimumLevel(); - int maximumLevel = getMaximumLevel(); - int tileWidth = getTileWidth(); - int tileHeight = getTileHeight(); + const auto minimumLevel = getMinimumLevel(); + const auto maximumLevel = getMaximumLevel(); + const auto tileWidth = getTileWidth(); + const auto tileHeight = getTileHeight(); std::string layers = getLayers(); if (maximumLevel > minimumLevel) { diff --git a/src/core/src/UsdNotificationHandler.cpp b/src/core/src/UsdNotificationHandler.cpp index 0f335abd..6ab65f02 100644 --- a/src/core/src/UsdNotificationHandler.cpp +++ b/src/core/src/UsdNotificationHandler.cpp @@ -664,6 +664,10 @@ void processCesiumPolygonRasterOverlayAdded(Context& context, const pxr::SdfPath void processCesiumWebMapServiceRasterOverlayAdded( Context& context, const pxr::SdfPath& webMapServiceRasterOverlayPath) { + if (context.getAssetRegistry().getWebMapServiceRasterOverlay(webMapServiceRasterOverlayPath)) { + return; + } + context.getAssetRegistry().addWebMapServiceRasterOverlay(webMapServiceRasterOverlayPath); updateRasterOverlayBindings(context, webMapServiceRasterOverlayPath); } From a176158e5a5e91f27510c756f5c468da57606da4 Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Thu, 8 Feb 2024 16:50:15 -0800 Subject: [PATCH 5/8] move C++ min/max check to Python UI layer --- .../ui/attributes/custom_attribute_widgets.py | 42 +++++++++++++++++-- ...ervice_raster_overlay_attributes_widget.py | 14 ++++++- .../src/OmniWebMapServiceRasterOverlay.cpp | 6 +-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py index c3295d68..47e61e2a 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py @@ -1,6 +1,34 @@ from typing import List import omni.ui as ui from pxr import Sdf +from functools import partial + + +def update_range(stage, prim_paths, constrain, attr_name): + + min_val = max_val = None + + for path in prim_paths: + prim = stage.GetPrimAtPath(path) + attr = prim.GetAttribute(constrain["attr"]) if prim else None + if prim and attr: + if constrain["type"] == "minimum": + min_val = attr.Get() + else: + max_val = attr.Get() + break + + for path in prim_paths: + prim = stage.GetPrimAtPath(path) + attr = prim.GetAttribute(attr_name) if prim else None + if prim and attr: + val = attr.Get() + if min_val: + val = max(min_val, val) + elif max_val: + val = min(max_val, val) + attr.Set(val) + break def _build_slider( @@ -49,15 +77,23 @@ def _build_slider( value_widget=value_widget, mixed_overlay=mixed_overlay, **widget_kwargs ) + if len(additional_widget_kwargs["constrain"]) == 2: + callback = partial(update_range, stage, prim_paths, additional_widget_kwargs["constrain"], attr_name) + model.add_value_changed_fn(lambda m: callback()) return model -def build_slider(min_value, max_value, type="float"): +def build_slider(min_value, max_value, type="float", constrain={}): if type not in ["int", "float"]: - raise ValueError("slider_type must be 'int' or 'float'") + raise ValueError("'type' must be 'int' or 'float'") + + if len(constrain) not in [0, 2]: + raise ValueError("'constrain' must be empty or a {'attr': ___, 'type': ___} dictionary") + if constrain[1] not in ["minimum", "maximum"]: + raise ValueError("constrain['type'] must be 'minimum' or 'maximum'") def custom_slider(stage, attr_name, metadata, property_type, prim_paths, *args, **kwargs): - additional_widget_kwargs = {"min": min_value, "max": max_value} + additional_widget_kwargs = {"min": min_value, "max": max_value, "constrain": constrain} additional_widget_kwargs.update(kwargs) return _build_slider( stage, diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py index 0872c90b..a3961c53 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/web_map_service_raster_overlay_attributes_widget.py @@ -30,8 +30,18 @@ def _customize_props_layout(self, props): CustomLayoutProperty("cesium:tileWidth", build_fn=build_slider(64, 2048, type="int")) CustomLayoutProperty("cesium:tileHeight", build_fn=build_slider(64, 2048, type="int")) with CustomLayoutGroup("Zoom Settings"): - CustomLayoutProperty("cesium:minimumLevel", build_fn=build_slider(0, 30, type="int")) - CustomLayoutProperty("cesium:maximumLevel", build_fn=build_slider(0, 30, type="int")) + CustomLayoutProperty( + "cesium:minimumLevel", + build_fn=build_slider( + 0, 30, type="int", constrain={"attr": "cesium:maximumLevel", "type": "maximum"} + ), + ) + CustomLayoutProperty( + "cesium:maximumLevel", + build_fn=build_slider( + 0, 30, type="int", constrain={"attr": "cesium:minimumLevel", "type": "minimum"} + ), + ) with CustomLayoutGroup("Rendering"): CustomLayoutProperty("cesium:alpha", build_fn=build_slider(0, 1)) CustomLayoutProperty("cesium:overlayRenderMethod") diff --git a/src/core/src/OmniWebMapServiceRasterOverlay.cpp b/src/core/src/OmniWebMapServiceRasterOverlay.cpp index 8eb70ea0..71996b48 100644 --- a/src/core/src/OmniWebMapServiceRasterOverlay.cpp +++ b/src/core/src/OmniWebMapServiceRasterOverlay.cpp @@ -87,10 +87,8 @@ void OmniWebMapServiceRasterOverlay::reload() { const auto tileHeight = getTileHeight(); std::string layers = getLayers(); - if (maximumLevel > minimumLevel) { - wmsOptions.minimumLevel = minimumLevel; - wmsOptions.maximumLevel = maximumLevel; - } + wmsOptions.minimumLevel = minimumLevel; + wmsOptions.maximumLevel = maximumLevel; wmsOptions.layers = layers; wmsOptions.tileWidth = tileWidth; wmsOptions.tileHeight = tileHeight; From a027e978311d862f002356870dcd5d2d71425ba9 Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Thu, 8 Feb 2024 17:04:28 -0800 Subject: [PATCH 6/8] python formatting --- .../cesium/omniverse/ui/attributes/custom_attribute_widgets.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py index 47e61e2a..e24dea9e 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/custom_attribute_widgets.py @@ -5,7 +5,6 @@ def update_range(stage, prim_paths, constrain, attr_name): - min_val = max_val = None for path in prim_paths: From 101cee814a688ea0eb6fae801f55c5f4181c1c38 Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Mon, 12 Feb 2024 12:51:03 -0800 Subject: [PATCH 7/8] when a tileset reloads, also reload bound raster overlays --- src/core/src/OmniTileset.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/src/OmniTileset.cpp b/src/core/src/OmniTileset.cpp index 458b711a..ee1fdc4e 100644 --- a/src/core/src/OmniTileset.cpp +++ b/src/core/src/OmniTileset.cpp @@ -497,12 +497,13 @@ void OmniTileset::reload() { } const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); - const auto rasterOverlayPaths = getRasterOverlayPaths(); + const auto boundRasterOverlayPaths = getRasterOverlayPaths(); - for (const auto& rasterOverlayPath : rasterOverlayPaths) { - const auto pRasterOverlay = _pContext->getAssetRegistry().getRasterOverlay(rasterOverlayPath); - if (pRasterOverlay) { - const auto pNativeRasterOverlay = pRasterOverlay->getRasterOverlay(); + for (const auto& boundRasterOverlayPath : boundRasterOverlayPaths) { + const auto pOmniRasterOverlay = _pContext->getAssetRegistry().getRasterOverlay(boundRasterOverlayPath); + if (pOmniRasterOverlay) { + pOmniRasterOverlay->reload(); + const auto pNativeRasterOverlay = pOmniRasterOverlay->getRasterOverlay(); if (pNativeRasterOverlay) { _pTileset->getOverlays().add(pNativeRasterOverlay); } From fdc4af1bb4fb782554e2d11feceb55096c4a5af5 Mon Sep 17 00:00:00 2001 From: Cory Barr Date: Mon, 12 Feb 2024 12:51:34 -0800 Subject: [PATCH 8/8] reload WMSRasterOverlay on additional property changes --- src/core/src/UsdNotificationHandler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/src/UsdNotificationHandler.cpp b/src/core/src/UsdNotificationHandler.cpp index 6ab65f02..0816073e 100644 --- a/src/core/src/UsdNotificationHandler.cpp +++ b/src/core/src/UsdNotificationHandler.cpp @@ -416,7 +416,9 @@ void processCesiumWebMapServiceRasterOverlayChanged( auto updateBindings = false; for (const auto& property : properties) { - if (property == pxr::CesiumTokens->cesiumBaseUrl || property == pxr::CesiumTokens->cesiumLayers) { + if (property == pxr::CesiumTokens->cesiumBaseUrl || property == pxr::CesiumTokens->cesiumLayers || + property == pxr::CesiumTokens->cesiumTileWidth || property == pxr::CesiumTokens->cesiumTileHeight || + property == pxr::CesiumTokens->cesiumMinimumLevel || property == pxr::CesiumTokens->cesiumMaximumLevel) { reload = true; updateBindings = true; }