Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional raster overlay prim properties and UI #681

Merged
merged 9 commits into from
Feb 14, 2024
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Fixed crash when disabling and re-enabling the extension.
* Fixed crash when removing USD prims in certain order.
* Fixed issue where Cesium ion session would not resume on reload.
* Added support for WMS raster overlays
* Added raster overlay options: maximumScreenSpaceError , maximumTextureSize, maximumSimultaneousTileLoads, subTileCacheBytes

### v0.17.0 - 2024-02-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import omni.ui as ui
from pxr import Sdf
from functools import partial
from omni.kit.property.usd.custom_layout_helper import CustomLayoutGroup, CustomLayoutProperty


def update_range(stage, prim_paths, constrain, attr_name):
Expand Down Expand Up @@ -105,3 +106,15 @@ def custom_slider(stage, attr_name, metadata, property_type, prim_paths, *args,
)

return custom_slider


def build_common_raster_overlay_properties(add_overlay_render_method=False):
with CustomLayoutGroup("Rendering"):
CustomLayoutProperty("cesium:alpha", build_fn=build_slider(0, 1))
if add_overlay_render_method:
CustomLayoutProperty("cesium:overlayRenderMethod")
CustomLayoutProperty("cesium:maximumScreenSpaceError")
CustomLayoutProperty("cesium:maximumTextureSize")
CustomLayoutProperty("cesium:maximumSimultaneousTileLoads")
CustomLayoutProperty("cesium:subTileCacheBytes")
CustomLayoutProperty("cesium:showCreditsOnScreen")
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
IonRasterOverlay as CesiumIonRasterOverlay,
IonServer as CesiumIonServer,
)
from .custom_attribute_widgets import build_slider
from .cesium_properties_widget_builder import build_common_raster_overlay_properties


class CesiumIonRasterOverlayAttributesWidget(SchemaPropertiesWidget):
Expand All @@ -25,11 +25,7 @@ def _customize_props_layout(self, props):
CustomLayoutProperty("cesium:ionAssetId")
CustomLayoutProperty("cesium:ionAccessToken")
CustomLayoutProperty("cesium:ionServerBinding")
with CustomLayoutGroup("Rendering"):
CustomLayoutProperty("cesium:alpha", build_fn=build_slider(0, 1))
CustomLayoutProperty("cesium:overlayRenderMethod")
with CustomLayoutGroup("Credit Display"):
CustomLayoutProperty("cesium:showCreditsOnScreen")
build_common_raster_overlay_properties(add_overlay_render_method=True)

return frame.apply(props)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
PolygonRasterOverlay as CesiumPolygonRasterOverlay,
)
from pxr import UsdGeom
from .custom_attribute_widgets import build_slider
from .cesium_properties_widget_builder import build_common_raster_overlay_properties


class CesiumPolygonRasterOverlayAttributesWidget(SchemaPropertiesWidget):
Expand All @@ -25,11 +25,7 @@ def _customize_props_layout(self, props):
CustomLayoutProperty("cesium:cartographicPolygonBinding")
with CustomLayoutGroup("Invert Selection"):
CustomLayoutProperty("cesium:invertSelection")
with CustomLayoutGroup("Rendering"):
CustomLayoutProperty("cesium:alpha", build_fn=build_slider(0, 1))
CustomLayoutProperty("cesium:overlayRenderMethod")
with CustomLayoutGroup("Credit Display"):
CustomLayoutProperty("cesium:showCreditsOnScreen")
build_common_raster_overlay_properties()

return frame.apply(props)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cesium.usd.plugins.CesiumUsdSchemas import (
WebMapServiceRasterOverlay as CesiumWebMapServiceRasterOverlay,
)
from .custom_attribute_widgets import build_slider
from .cesium_properties_widget_builder import build_slider, build_common_raster_overlay_properties


class CesiumWebMapServiceRasterOverlayAttributesWidget(SchemaPropertiesWidget):
Expand Down Expand Up @@ -42,10 +42,6 @@ def _customize_props_layout(self, props):
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")
with CustomLayoutGroup("Credit Display"):
CustomLayoutProperty("cesium:showCreditsOnScreen")
build_common_raster_overlay_properties()

return frame.apply(props)
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,36 @@ class RasterOverlay(pxr.Usd.Typed):
@classmethod
def CreateAlphaAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateMaximumScreenSpaceErrorAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateMaximumSimultaneousTileLoadsAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateMaximumTextureSizeAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateOverlayRenderMethodAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateShowCreditsOnScreenAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateSubTileCacheBytesAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetAlphaAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetMaximumScreenSpaceErrorAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetMaximumSimultaneousTileLoadsAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetMaximumTextureSizeAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetOverlayRenderMethodAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetShowCreditsOnScreenAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetSubTileCacheBytesAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
Expand Down Expand Up @@ -471,8 +487,6 @@ 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: ...
Expand Down Expand Up @@ -501,6 +515,8 @@ class Tokens(Boost.Python.instance):
@property
def cesiumMaximumSimultaneousTileLoads(self) -> Any: ...
@property
def cesiumMaximumTextureSize(self) -> Any: ...
@property
def cesiumMinimumLevel(self) -> Any: ...
@property
def cesiumOverlayRenderMethod(self) -> Any: ...
Expand All @@ -523,11 +539,15 @@ class Tokens(Boost.Python.instance):
@property
def cesiumSourceType(self) -> Any: ...
@property
def cesiumSubTileCacheBytes(self) -> Any: ...
@property
def cesiumSuspendUpdate(self) -> Any: ...
@property
def cesiumUrl(self) -> Any: ...
def cesiumTileHeight(self) -> Any: ...
@property
def cesiumWidth(self) -> Any: ...
def cesiumTileWidth(self) -> Any: ...
@property
def cesiumUrl(self) -> Any: ...
@property
def clip(self) -> Any: ...
@property
Expand All @@ -544,24 +564,22 @@ class WebMapServiceRasterOverlay(RasterOverlay):
@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: ...
def CreateTileHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateTileWidthAttr(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: ...
Expand All @@ -570,7 +588,9 @@ class WebMapServiceRasterOverlay(RasterOverlay):
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetWidthAttr(cls, *args, **kwargs) -> Any: ...
def GetTileHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetTileWidthAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
Expand Down
38 changes: 35 additions & 3 deletions exts/cesium.usd.plugins/schemas/cesium_schemas.usda
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ class "CesiumRasterOverlayPrim" (
string className = "RasterOverlay"
}
) {
bool cesium:showCreditsOnScreen = false (
uniform bool cesium:showCreditsOnScreen = false (
customData = {
string apiName = "showCreditsOnScreen"
}
displayName = "Show Credits On Screen"
displayName = "Show Credits on Screen"
doc = "Whether or not to show this raster overlay's credits on screen."
)

float cesium:alpha = 1.0 (
uniform float cesium:alpha = 1.0 (
customData = {
string apiName = "alpha"
}
Expand All @@ -452,6 +452,38 @@ class "CesiumRasterOverlayPrim" (
displayName = "Overlay Render Method"
doc = "The Cesium default material will give the raster overlay a different rendering treatment based on this selection."
)

uniform float cesium:maximumScreenSpaceError = 2.0 (
corybarr marked this conversation as resolved.
Show resolved Hide resolved
customData = {
string apiName = "maximumScreenSpaceError"
}
displayName = "Maximum Screen Space Error"
doc = "The maximum number of pixels of error when rendering this overlay. This is used to select an appropriate level-of-detail. When this property has its default value, 2.0, it means that raster overlay images will be sized so that, when zoomed in closest, a single pixel in the raster overlay maps to approximately 2x2 pixels on the screen."
)

uniform int cesium:maximumTextureSize = 2048 (
customData = {
string apiName = "maximumTextureSize"
}
displayName = "Maximum Texture Size"
doc = "The maximum texel size of raster overlay textures, in either direction. Images created by this overlay will be no more than this number of texels in either direction. This may result in reduced raster overlay detail in some cases."
)

uniform int cesium:maximumSimultaneousTileLoads = 20 (
customData = {
string apiName = "maximumSimultaneousTileLoads"
}
displayName = "Maximum Simultaneous Tile Loads"
doc = "The maximum number of overlay tiles that may simultaneously be in the process of loading."
)

uniform int cesium:subTileCacheBytes = 16777216 (
customData = {
string apiName = "subTileCacheBytes"
}
displayName = "Sub Tile Cache Bytes"
doc = "The maximum number of bytes to use to cache sub-tiles in memory. This is used by provider types, that have an underlying tiling scheme that may not align with the tiling scheme of the geometry tiles on which the raster overlay tiles are draped. Because a single sub-tile may overlap multiple geometry tiles, it is useful to cache loaded sub-tiles in memory in case they're needed again soon. This property controls the maximum size of that cache."
)
}

class CesiumIonRasterOverlayPrim "CesiumIonRasterOverlayPrim" (
Expand Down
20 changes: 19 additions & 1 deletion src/core/include/cesium/omniverse/OmniRasterOverlay.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include "cesium/omniverse/OmniTileset.h"

#include <CesiumRasterOverlays/RasterOverlay.h>
#include <pxr/usd/sdf/path.h>

namespace CesiumRasterOverlays {
Expand All @@ -9,9 +12,14 @@ class RasterOverlay;
namespace cesium::omniverse {

class Context;
class OmniTileset;
enum class FabricOverlayRenderMethod;

class OmniRasterOverlay {
friend void OmniTileset::addRasterOverlayIfExists(const OmniRasterOverlay* pOverlay);
friend pxr::SdfPath
OmniTileset::getRasterOverlayPathIfExists(const CesiumRasterOverlays::RasterOverlay& rasterOverlay);

public:
OmniRasterOverlay(Context* pContext, const pxr::SdfPath& path);
virtual ~OmniRasterOverlay() = default;
Expand All @@ -24,12 +32,22 @@ class OmniRasterOverlay {
[[nodiscard]] bool getShowCreditsOnScreen() const;
[[nodiscard]] double getAlpha() const;
[[nodiscard]] FabricOverlayRenderMethod getOverlayRenderMethod() const;
[[nodiscard]] float getMaximumScreenSpaceError() const;
[[nodiscard]] int getMaximumTextureSize() const;
[[nodiscard]] int getMaximumSimultaneousTileLoads() const;
[[nodiscard]] int getSubTileCacheBytes() const;

[[nodiscard]] virtual CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const = 0;
[[nodiscard]] CesiumRasterOverlays::RasterOverlayOptions createRasterOverlayOptions() const;

void updateRasterOverlayOptions() const;
virtual void reload() = 0;

protected:
[[nodiscard]] virtual CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const = 0;
Context* _pContext;
pxr::SdfPath _path;

private:
void setRasterOverlayOptionsFromUsd(CesiumRasterOverlays::RasterOverlayOptions& options) const;
};
} // namespace cesium::omniverse
6 changes: 3 additions & 3 deletions src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "cesium/omniverse/OmniTileset.h"

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

Expand Down Expand Up @@ -31,6 +29,7 @@ namespace cesium::omniverse {

class Context;
class FabricPrepareRenderResources;
class OmniRasterOverlay;
struct TilesetStatistics;
struct Viewport;

Expand Down Expand Up @@ -82,10 +81,11 @@ class OmniTileset {
void updateTilesetOptions();

void reload();
[[nodiscard]] pxr::SdfPath getRasterOverlayPath(const CesiumRasterOverlays::RasterOverlay& rasterOverlay) const;
[[nodiscard]] pxr::SdfPath getRasterOverlayPathIfExists(const CesiumRasterOverlays::RasterOverlay& rasterOverlay);
void updateRasterOverlayAlpha(const pxr::SdfPath& rasterOverlayPath);
void updateShaderInput(const pxr::SdfPath& shaderPath, const pxr::TfToken& attributeName);
void updateDisplayColorAndOpacity();
void addRasterOverlayIfExists(const OmniRasterOverlay* overlay);

void onUpdateFrame(const gsl::span<const Viewport>& viewports);

Expand Down
4 changes: 2 additions & 2 deletions src/core/src/FabricPrepareRenderResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void FabricPrepareRenderResources::attachRasterInMainThread(
return;
}

const auto rasterOverlayPath = _pTileset->getRasterOverlayPath(rasterTile.getOverlay());
const auto rasterOverlayPath = _pTileset->getRasterOverlayPathIfExists(rasterTile.getOverlay());

if (rasterOverlayPath.IsEmpty()) {
return;
Expand Down Expand Up @@ -600,7 +600,7 @@ void FabricPrepareRenderResources::detachRasterInMainThread(
return;
}

const auto rasterOverlayPath = _pTileset->getRasterOverlayPath(rasterTile.getOverlay());
const auto rasterOverlayPath = _pTileset->getRasterOverlayPathIfExists(rasterTile.getOverlay());

if (rasterOverlayPath.IsEmpty()) {
return;
Expand Down
5 changes: 1 addition & 4 deletions src/core/src/OmniIonRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "cesium/omniverse/AssetRegistry.h"
#include "cesium/omniverse/Broadcast.h"
#include "cesium/omniverse/Context.h"
#include "cesium/omniverse/GltfUtil.h"
#include "cesium/omniverse/Logger.h"
#include "cesium/omniverse/OmniIonServer.h"
#include "cesium/omniverse/UsdUtil.h"
Expand Down Expand Up @@ -118,9 +117,7 @@ void OmniIonRasterOverlay::reload() {

const auto rasterOverlayName = UsdUtil::getName(_pContext->getUsdStage(), _path);

CesiumRasterOverlays::RasterOverlayOptions options;
options.showCreditsOnScreen = getShowCreditsOnScreen();
options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets();
auto options = createRasterOverlayOptions();

options.loadErrorCallback = [this, rasterOverlayIonAssetId, rasterOverlayName](
const CesiumRasterOverlays::RasterOverlayLoadFailureDetails& error) {
Expand Down
4 changes: 1 addition & 3 deletions src/core/src/OmniPolygonRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ void OmniPolygonRasterOverlay::reload() {

const auto projection = CesiumGeospatial::GeographicProjection(*pEllipsoid);

CesiumRasterOverlays::RasterOverlayOptions options;
options.showCreditsOnScreen = getShowCreditsOnScreen();
options.ktx2TranscodeTargets = GltfUtil::getKtx2TranscodeTargets();
auto options = createRasterOverlayOptions();

options.loadErrorCallback = [this](const CesiumRasterOverlays::RasterOverlayLoadFailureDetails& error) {
_pContext->getLogger()->error(error.message);
Expand Down
Loading
Loading