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

Bypass loading of clipped tiles #658

Merged
merged 24 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
148aa72
add excludeSelectedTiles to schema and OmniPolygonRasterOverlay class
corybarr Jan 31, 2024
4b88241
add tileset excluder to Omni* classes
corybarr Feb 1, 2024
8b54e4a
formatting
corybarr Feb 1, 2024
0a9044d
remove unused accessors
corybarr Feb 1, 2024
912214d
remove additional accessor
corybarr Feb 1, 2024
71f2606
push version with exception thrown in Native
corybarr Feb 1, 2024
f7db1e8
fix nullptr exception
corybarr Feb 1, 2024
e0650a7
Merge branch 'main' into exclude-tiles-not-in-polygon
corybarr Feb 3, 2024
202f3ad
cleanup
corybarr Feb 5, 2024
65b602c
Merge branch 'main' of https://github.com/CesiumGS/cesium-omniverse i…
corybarr Feb 5, 2024
f0ca63a
cleanup
corybarr Feb 5, 2024
bb34368
Only add polygon exclude to bound raster overlays
corybarr Feb 5, 2024
2e87203
Merge branch 'exclude-tiles-not-in-polygon' of https://github.com/Ces…
corybarr Feb 5, 2024
6d0f5d5
cleanup
corybarr Feb 5, 2024
c21c320
cleanup
corybarr Feb 5, 2024
1edaaf7
changes from PR review
corybarr Feb 7, 2024
275a618
Merge branch 'main' of https://github.com/CesiumGS/cesium-omniverse i…
corybarr Feb 7, 2024
256d31e
Merge branch 'main' into exclude-tiles-not-in-polygon
corybarr Feb 8, 2024
2021cd5
Merge branch 'main' into exclude-tiles-not-in-polygon
corybarr Feb 12, 2024
258cde0
Merge branch 'main' of https://github.com/CesiumGS/cesium-omniverse i…
corybarr Feb 13, 2024
01d02d8
update CHANGES.md
corybarr Feb 13, 2024
392171d
include OmniPolygonRasterOverlay.h
corybarr Feb 13, 2024
9b5c03a
merge with main
corybarr Feb 15, 2024
288bcc2
updated native
corybarr Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def _customize_props_layout(self, props):
CustomLayoutProperty("cesium:cartographicPolygonBinding")
with CustomLayoutGroup("Invert Selection"):
CustomLayoutProperty("cesium:invertSelection")
with CustomLayoutGroup("Exclude Selected Tiles"):
CustomLayoutProperty("cesium:excludeSelectedTiles")
with CustomLayoutGroup("Rendering"):
CustomLayoutProperty("cesium:alpha", build_fn=build_slider(0, 1))
CustomLayoutProperty("cesium:overlayRenderMethod")
Expand Down
8 changes: 8 additions & 0 deletions exts/cesium.usd.plugins/schemas/cesium_schemas.usda
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" (
doc = "Whether to invert the selection specified by the polygons. If this is true, only the areas outside of the polygons will be rasterized."
)

bool cesium:excludeSelectedTiles = true (
customData = {
string apiName = "excludeSelectedTiles"
}
displayName = "Exclude Selected Tiles"
doc = "Whether tiles that fall entirely within the rasterized selection should be excluded from loading and rendering. For better performance, this should be enabled when this overlay will be used for clipping. But when this overlay is used for other effects, this option should be disabled to avoid missing tiles. Note that if InvertSelection is true, this will cull tiles that are outside of all the polygons. If it is false, this will cull tiles that are completely inside at least one polygon."
)

uniform token cesium:overlayRenderMethod = "clip"
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/include/cesium/omniverse/OmniPolygonRasterOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "cesium/omniverse/OmniRasterOverlay.h"

#include <Cesium3DTilesSelection/RasterizedPolygonsTileExcluder.h>
#include <CesiumRasterOverlays/RasterizedPolygonsOverlay.h>
#include <CesiumUtility/IntrusivePointer.h>

Expand All @@ -19,9 +20,12 @@ class OmniPolygonRasterOverlay final : public OmniRasterOverlay {
[[nodiscard]] std::vector<pxr::SdfPath> getCartographicPolygonPaths() const;
[[nodiscard]] CesiumRasterOverlays::RasterOverlay* getRasterOverlay() const override;
[[nodiscard]] bool getInvertSelection() const;
[[nodiscard]] bool getExcludeSelectedTiles() const;
[[nodiscard]] std::shared_ptr<Cesium3DTilesSelection::RasterizedPolygonsTileExcluder> getExcluder();
void reload() override;

private:
CesiumUtility::IntrusivePointer<CesiumRasterOverlays::RasterizedPolygonsOverlay> _pPolygonRasterOverlay;
std::shared_ptr<Cesium3DTilesSelection::RasterizedPolygonsTileExcluder> _pExcluder;
};
} // namespace cesium::omniverse
22 changes: 21 additions & 1 deletion src/core/src/OmniPolygonRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
namespace cesium::omniverse {

OmniPolygonRasterOverlay::OmniPolygonRasterOverlay(Context* pContext, const pxr::SdfPath& path)
: OmniRasterOverlay(pContext, path) {}
: OmniRasterOverlay(pContext, path)
, _pExcluder(nullptr) {}
corybarr marked this conversation as resolved.
Show resolved Hide resolved

std::vector<pxr::SdfPath> OmniPolygonRasterOverlay::getCartographicPolygonPaths() const {
const auto cesiumPolygonRasterOverlay = UsdUtil::getCesiumPolygonRasterOverlay(_pContext->getUsdStage(), _path);
Expand All @@ -38,6 +39,17 @@ bool OmniPolygonRasterOverlay::getInvertSelection() const {
return invertSelection;
}

bool OmniPolygonRasterOverlay::getExcludeSelectedTiles() const {
auto cesiumPolygonRasterOverlay = UsdUtil::getCesiumPolygonRasterOverlay(_pContext->getUsdStage(), _path);
bool val;
cesiumPolygonRasterOverlay.GetExcludeSelectedTilesAttr().Get(&val);
return val;
}

std::shared_ptr<Cesium3DTilesSelection::RasterizedPolygonsTileExcluder> OmniPolygonRasterOverlay::getExcluder() {
return _pExcluder;
}

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

Expand Down Expand Up @@ -104,6 +116,14 @@ void OmniPolygonRasterOverlay::reload() {

_pPolygonRasterOverlay = new CesiumRasterOverlays::RasterizedPolygonsOverlay(
rasterOverlayName, polygons, getInvertSelection(), *pEllipsoid, projection, options);

auto cesiumPolygonRasterOverlay = UsdUtil::getCesiumPolygonRasterOverlay(_pContext->getUsdStage(), _path);
bool excludeSelectedTiles;
cesiumPolygonRasterOverlay.GetExcludeSelectedTilesAttr().Get(&excludeSelectedTiles);
if (excludeSelectedTiles) {
auto pPolygons = _pPolygonRasterOverlay.get();
_pExcluder = std::make_shared<Cesium3DTilesSelection::RasterizedPolygonsTileExcluder>(pPolygons);
}
corybarr marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace cesium::omniverse
25 changes: 25 additions & 0 deletions src/core/src/OmniTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ void OmniTileset::reload() {
options.culledScreenSpaceError = getCulledScreenSpaceError();
options.mainThreadLoadingTimeLimit = getMainThreadLoadingTimeLimit();
options.showCreditsOnScreen = getShowCreditsOnScreen();
options.excluders = std::vector<std::shared_ptr<Cesium3DTilesSelection::ITileExcluder>>();
corybarr marked this conversation as resolved.
Show resolved Hide resolved

options.loadErrorCallback =
[this, tilesetPath, ionAssetId, name](const Cesium3DTilesSelection::TilesetLoadFailureDetails& error) {
Expand Down Expand Up @@ -504,6 +505,30 @@ void OmniTileset::reload() {
}
}
}

const auto& allOmniPolygonRasterOverlays = _pContext->getAssetRegistry().getPolygonRasterOverlays();
const auto& boundNativeRasterOverlays =
_pTileset->getOverlays().getOverlays(); // get RasterOverlays from RasterOverlayCollection
for (const auto& pOmniPolygonRasterOverlay : allOmniPolygonRasterOverlays) {
const auto& pNativeOverlay = pOmniPolygonRasterOverlay->getRasterOverlay();

auto matchIterator = std::find_if(
boundNativeRasterOverlays.begin(),
boundNativeRasterOverlays.end(),
[&pNativeOverlay](const auto& possibleMatch) { return possibleMatch.get() == pNativeOverlay; });

if (matchIterator == boundNativeRasterOverlays.end()) {
continue;
}

const auto exclude = pOmniPolygonRasterOverlay->getExcludeSelectedTiles();
if (exclude) {
const auto excluder = pOmniPolygonRasterOverlay->getExcluder();
if (excluder) {
_pTileset->getOptions().excluders.push_back(excluder);
corybarr marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
corybarr marked this conversation as resolved.
Show resolved Hide resolved
}

pxr::SdfPath OmniTileset::getRasterOverlayPath(const CesiumRasterOverlays::RasterOverlay& rasterOverlay) const {
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/UsdNotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ void processCesiumPolygonRasterOverlayChanged(

for (const auto& property : properties) {
if (property == pxr::CesiumTokens->cesiumCartographicPolygonBinding ||
property == pxr::CesiumTokens->cesiumInvertSelection) {
property == pxr::CesiumTokens->cesiumInvertSelection ||
property == pxr::CesiumTokens->cesiumExcludeSelectedTiles) {
reload = true;
updateBindings = true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/CesiumUsdSchemas/generatedSchema.usda.in
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" (
displayName = "Cartographic Polygon Binding"
doc = "Specifies which Cartographic Polygons to use in the raster overlay"
)
bool cesium:excludeSelectedTiles = 1 (
displayName = "Exclude Selected Tiles"
doc = "Whether tiles that fall entirely within the rasterized selection should be excluded from loading and rendering. For better performance, this should be enabled when this overlay will be used for clipping. But when this overlay is used for other effects, this option should be disabled to avoid missing tiles. Note that if InvertSelection is true, this will cull tiles that are outside of all the polygons. If it is false, this will cull tiles that are completely inside at least one polygon."
)
bool cesium:invertSelection = 0 (
displayName = "Invert Selection"
doc = "Whether to invert the selection specified by the polygons. If this is true, only the areas outside of the polygons will be rasterized."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ CesiumPolygonRasterOverlay::CreateInvertSelectionAttr(VtValue const &defaultValu
writeSparsely);
}

UsdAttribute
CesiumPolygonRasterOverlay::GetExcludeSelectedTilesAttr() const
{
return GetPrim().GetAttribute(CesiumTokens->cesiumExcludeSelectedTiles);
}

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

UsdAttribute
CesiumPolygonRasterOverlay::GetCesiumOverlayRenderMethodAttr() const
{
Expand Down Expand Up @@ -145,6 +162,7 @@ CesiumPolygonRasterOverlay::GetSchemaAttributeNames(bool includeInherited)
{
static TfTokenVector localNames = {
CesiumTokens->cesiumInvertSelection,
CesiumTokens->cesiumExcludeSelectedTiles,
CesiumTokens->cesiumOverlayRenderMethod,
};
static TfTokenVector allNames =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ class CesiumPolygonRasterOverlay : public CesiumRasterOverlay
CESIUMUSDSCHEMAS_API
UsdAttribute CreateInvertSelectionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;

public:
// --------------------------------------------------------------------- //
// EXCLUDESELECTEDTILES
// --------------------------------------------------------------------- //
/// Whether tiles that fall entirely within the rasterized selection should be excluded from loading and rendering. For better performance, this should be enabled when this overlay will be used for clipping. But when this overlay is used for other effects, this option should be disabled to avoid missing tiles. Note that if InvertSelection is true, this will cull tiles that are outside of all the polygons. If it is false, this will cull tiles that are completely inside at least one polygon.
///
/// | ||
/// | -- | -- |
/// | Declaration | `bool cesium:excludeSelectedTiles = 1` |
/// | C++ Type | bool |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool |
CESIUMUSDSCHEMAS_API
UsdAttribute GetExcludeSelectedTilesAttr() const;

/// See GetExcludeSelectedTilesAttr(), 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 CreateExcludeSelectedTilesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;

public:
// --------------------------------------------------------------------- //
// CESIUMOVERLAYRENDERMETHOD
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CesiumTokensType::CesiumTokensType() :
cesiumEnableFogCulling("cesium:enableFogCulling", TfToken::Immortal),
cesiumEnableFrustumCulling("cesium:enableFrustumCulling", TfToken::Immortal),
cesiumEnforceCulledScreenSpaceError("cesium:enforceCulledScreenSpaceError", TfToken::Immortal),
cesiumExcludeSelectedTiles("cesium:excludeSelectedTiles", TfToken::Immortal),
cesiumForbidHoles("cesium:forbidHoles", TfToken::Immortal),
cesiumGeoreferenceBinding("cesium:georeferenceBinding", TfToken::Immortal),
cesiumGeoreferenceOriginHeight("cesium:georeferenceOrigin:height", TfToken::Immortal),
Expand Down Expand Up @@ -87,6 +88,7 @@ CesiumTokensType::CesiumTokensType() :
cesiumEnableFogCulling,
cesiumEnableFrustumCulling,
cesiumEnforceCulledScreenSpaceError,
cesiumExcludeSelectedTiles,
cesiumForbidHoles,
cesiumGeoreferenceBinding,
cesiumGeoreferenceOriginHeight,
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ struct CesiumTokensType {
///
/// CesiumTileset
const TfToken cesiumEnforceCulledScreenSpaceError;
/// \brief "cesium:excludeSelectedTiles"
///
/// CesiumPolygonRasterOverlay
const TfToken cesiumExcludeSelectedTiles;
/// \brief "cesium:forbidHoles"
///
/// CesiumTileset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ _CreateInvertSelectionAttr(CesiumPolygonRasterOverlay &self,
UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
}

static UsdAttribute
_CreateExcludeSelectedTilesAttr(CesiumPolygonRasterOverlay &self,
object defaultVal, bool writeSparsely) {
return self.CreateExcludeSelectedTilesAttr(
UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
}

static UsdAttribute
_CreateCesiumOverlayRenderMethodAttr(CesiumPolygonRasterOverlay &self,
object defaultVal, bool writeSparsely) {
Expand Down Expand Up @@ -89,6 +96,13 @@ void wrapCesiumPolygonRasterOverlay()
(arg("defaultValue")=object(),
arg("writeSparsely")=false))

.def("GetExcludeSelectedTilesAttr",
&This::GetExcludeSelectedTilesAttr)
.def("CreateExcludeSelectedTilesAttr",
&_CreateExcludeSelectedTilesAttr,
(arg("defaultValue")=object(),
arg("writeSparsely")=false))

.def("GetCesiumOverlayRenderMethodAttr",
&This::GetCesiumOverlayRenderMethodAttr)
.def("CreateCesiumOverlayRenderMethodAttr",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void wrapCesiumTokens()
_AddToken(cls, "cesiumEnableFogCulling", CesiumTokens->cesiumEnableFogCulling);
_AddToken(cls, "cesiumEnableFrustumCulling", CesiumTokens->cesiumEnableFrustumCulling);
_AddToken(cls, "cesiumEnforceCulledScreenSpaceError", CesiumTokens->cesiumEnforceCulledScreenSpaceError);
_AddToken(cls, "cesiumExcludeSelectedTiles", CesiumTokens->cesiumExcludeSelectedTiles);
_AddToken(cls, "cesiumForbidHoles", CesiumTokens->cesiumForbidHoles);
_AddToken(cls, "cesiumGeoreferenceBinding", CesiumTokens->cesiumGeoreferenceBinding);
_AddToken(cls, "cesiumGeoreferenceOriginHeight", CesiumTokens->cesiumGeoreferenceOriginHeight);
Expand Down
Loading