From 948b5024dcde19acabef166a01fd858e0bd560b5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 13 May 2024 15:10:10 -0400 Subject: [PATCH] Added pointSize attribute --- CHANGES.md | 1 + .../attributes/tileset_attributes_widget.py | 2 ++ .../usd/plugins/CesiumUsdSchemas/__init__.pyi | 6 +++++ .../schemas/cesium_schemas.usda | 8 +++++++ .../include/cesium/omniverse/FabricGeometry.h | 1 + .../include/cesium/omniverse/OmniTileset.h | 1 + src/core/src/FabricGeometry.cpp | 3 ++- src/core/src/FabricPrepareRenderResources.cpp | 2 ++ src/core/src/OmniTileset.cpp | 12 ++++++++++ src/core/src/UsdNotificationHandler.cpp | 1 + .../CesiumUsdSchemas/generatedSchema.usda.in | 4 ++++ .../src/CesiumUsdSchemas/tileset.cpp | 18 +++++++++++++++ .../src/CesiumUsdSchemas/tileset.h | 22 +++++++++++++++++++ .../src/CesiumUsdSchemas/tokens.cpp | 2 ++ .../src/CesiumUsdSchemas/tokens.h | 4 ++++ .../src/CesiumUsdSchemas/wrapTileset.cpp | 14 ++++++++++++ .../src/CesiumUsdSchemas/wrapTokens.cpp | 1 + 17 files changed, 101 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 645f40a9..5fde04e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ### v0.21.0 - 2024-06-03 +* Added `pointSize` attribute to `CesiumTilesetPrim` for controlling the size of points. * Added read-only attribute `ecefToUsdTransform` to `CesiumGeoreferencePrim`. Previously this was stored in `/CesiumSession` which has since been removed. * Fixed crash when updating globe anchor when georeferencing is disabled. diff --git a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/tileset_attributes_widget.py b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/tileset_attributes_widget.py index 6888f909..e29de9fb 100644 --- a/exts/cesium.omniverse/cesium/omniverse/ui/attributes/tileset_attributes_widget.py +++ b/exts/cesium.omniverse/cesium/omniverse/ui/attributes/tileset_attributes_widget.py @@ -61,6 +61,8 @@ def _customize_props_layout(self, props): CustomLayoutProperty("cesium:smoothNormals") with CustomLayoutGroup("Georeference"): CustomLayoutProperty("cesium:georeferenceBinding") + with CustomLayoutGroup("Point Clouds"): + CustomLayoutProperty("cesium:pointSize") return frame.apply(props) 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 55c6c70a..43ebfdbc 100644 --- a/exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/__init__.pyi +++ b/exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/__init__.pyi @@ -359,6 +359,8 @@ class Tileset(pxr.UsdGeom.Gprim): @classmethod def CreateMaximumSimultaneousTileLoadsAttr(cls, *args, **kwargs) -> Any: ... @classmethod + def CreatePointSizeAttr(cls, *args, **kwargs) -> Any: ... + @classmethod def CreatePreloadAncestorsAttr(cls, *args, **kwargs) -> Any: ... @classmethod def CreatePreloadSiblingsAttr(cls, *args, **kwargs) -> Any: ... @@ -407,6 +409,8 @@ class Tileset(pxr.UsdGeom.Gprim): @classmethod def GetMaximumSimultaneousTileLoadsAttr(cls, *args, **kwargs) -> Any: ... @classmethod + def GetPointSizeAttr(cls, *args, **kwargs) -> Any: ... + @classmethod def GetPreloadAncestorsAttr(cls, *args, **kwargs) -> Any: ... @classmethod def GetPreloadSiblingsAttr(cls, *args, **kwargs) -> Any: ... @@ -547,6 +551,8 @@ class Tokens(Boost.Python.instance): @property def cesiumOverlayRenderMethod(self) -> Any: ... @property + def cesiumPointSize(self) -> Any: ... + @property def cesiumPreloadAncestors(self) -> Any: ... @property def cesiumPreloadSiblings(self) -> Any: ... diff --git a/exts/cesium.usd.plugins/schemas/cesium_schemas.usda b/exts/cesium.usd.plugins/schemas/cesium_schemas.usda index ff48e105..3ae3b821 100644 --- a/exts/cesium.usd.plugins/schemas/cesium_schemas.usda +++ b/exts/cesium.usd.plugins/schemas/cesium_schemas.usda @@ -395,6 +395,14 @@ class CesiumTilesetPrim "CesiumTilesetPrim" ( displayName = "Raster Overlay Binding" doc = "Specifies which raster overlays to use for this tileset." ) + + float cesium:pointSize = 1.0 ( + customData = { + string apiName = "pointSize" + } + displayName = "Point Size" + doc = "The size in meters to display each point." + ) } class "CesiumRasterOverlayPrim" ( diff --git a/src/core/include/cesium/omniverse/FabricGeometry.h b/src/core/include/cesium/omniverse/FabricGeometry.h index 6ab7d114..191eff7b 100644 --- a/src/core/include/cesium/omniverse/FabricGeometry.h +++ b/src/core/include/cesium/omniverse/FabricGeometry.h @@ -36,6 +36,7 @@ class FabricGeometry { const CesiumGltf::MeshPrimitive& primitive, const FabricMaterialInfo& materialInfo, bool smoothNormals, + double pointSize, const std::unordered_map& texcoordIndexMapping, const std::unordered_map& rasterOverlayTexcoordIndexMapping); diff --git a/src/core/include/cesium/omniverse/OmniTileset.h b/src/core/include/cesium/omniverse/OmniTileset.h index 35a66ed0..cfc5da6b 100644 --- a/src/core/include/cesium/omniverse/OmniTileset.h +++ b/src/core/include/cesium/omniverse/OmniTileset.h @@ -77,6 +77,7 @@ class OmniTileset { [[nodiscard]] glm::dvec3 getDisplayColor() const; [[nodiscard]] double getDisplayOpacity() const; [[nodiscard]] std::vector getRasterOverlayPaths() const; + [[nodiscard]] double getPointSize() const; void updateTilesetOptions(); diff --git a/src/core/src/FabricGeometry.cpp b/src/core/src/FabricGeometry.cpp index c2001660..4b8889ce 100644 --- a/src/core/src/FabricGeometry.cpp +++ b/src/core/src/FabricGeometry.cpp @@ -318,6 +318,7 @@ void FabricGeometry::setGeometry( const CesiumGltf::MeshPrimitive& primitive, const FabricMaterialInfo& materialInfo, bool smoothNormals, + double pointSize, const std::unordered_map& texcoordIndexMapping, const std::unordered_map& rasterOverlayTexcoordIndexMapping) { @@ -352,7 +353,7 @@ void FabricGeometry::setGeometry( if (primitive.mode == CesiumGltf::MeshPrimitive::Mode::POINTS) { const auto numVoxels = positions.size(); - const auto shapeHalfSize = 1.5f; + const auto shapeHalfSize = (pointSize <= 0.0 ? 1.0 : pointSize) * 0.5; fabricStage.setArrayAttributeSize(_path, FabricTokens::points, numVoxels * 8); fabricStage.setArrayAttributeSize(_path, FabricTokens::faceVertexCounts, numVoxels * 2 * 6); fabricStage.setArrayAttributeSize(_path, FabricTokens::faceVertexIndices, numVoxels * 6 * 2 * 3); diff --git a/src/core/src/FabricPrepareRenderResources.cpp b/src/core/src/FabricPrepareRenderResources.cpp index dbc7e913..48583cc3 100644 --- a/src/core/src/FabricPrepareRenderResources.cpp +++ b/src/core/src/FabricPrepareRenderResources.cpp @@ -250,6 +250,7 @@ void setFabricMeshes( const auto tilesetId = tileset.getTilesetId(); const auto smoothNormals = tileset.getSmoothNormals(); + const auto pointSize = tileset.getPointSize(); for (uint64_t i = 0; i < loadingMeshes.size(); ++i) { const auto& loadingMesh = loadingMeshes[i]; @@ -267,6 +268,7 @@ void setFabricMeshes( primitive, fabricMesh.materialInfo, smoothNormals, + pointSize, fabricMesh.texcoordIndexMapping, fabricMesh.rasterOverlayTexcoordIndexMapping); diff --git a/src/core/src/OmniTileset.cpp b/src/core/src/OmniTileset.cpp index 0cc5493a..bd4afe96 100644 --- a/src/core/src/OmniTileset.cpp +++ b/src/core/src/OmniTileset.cpp @@ -486,6 +486,18 @@ std::vector OmniTileset::getRasterOverlayPaths() const { return targets; } +double OmniTileset::getPointSize() const { + const auto cesiumTileset = UsdUtil::getCesiumTileset(_pContext->getUsdStage(), _path); + if (!UsdUtil::isSchemaValid(cesiumTileset)) { + return 1.0; + } + + float pointSize; + cesiumTileset.GetPointSizeAttr().Get(&pointSize); + + return static_cast(pointSize); +} + void OmniTileset::updateTilesetOptions() { auto& options = _pTileset->getOptions(); options.maximumScreenSpaceError = getMaximumScreenSpaceError(); diff --git a/src/core/src/UsdNotificationHandler.cpp b/src/core/src/UsdNotificationHandler.cpp index 9d8494d1..f3b8fd9d 100644 --- a/src/core/src/UsdNotificationHandler.cpp +++ b/src/core/src/UsdNotificationHandler.cpp @@ -263,6 +263,7 @@ void processCesiumTilesetChanged( property == pxr::CesiumTokens->cesiumSmoothNormals || property == pxr::CesiumTokens->cesiumShowCreditsOnScreen || property == pxr::CesiumTokens->cesiumRasterOverlayBinding || + property == pxr::CesiumTokens->cesiumPointSize || property == pxr::UsdTokens->material_binding) { reload = true; } else if ( diff --git a/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in b/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in index 85f2a77f..dad3f808 100644 --- a/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in +++ b/src/plugins/CesiumUsdSchemas/generatedSchema.usda.in @@ -165,6 +165,10 @@ class CesiumTilesetPrim "CesiumTilesetPrim" ( displayName = "Maximum Simultaneous Tile Loads" doc = "The maximum number of tiles that may be loaded at once. When new parts of the tileset become visible, the tasks to load the corresponding tiles are put into a queue. This value determines how many of these tasks are processed at the same time. A higher value may cause the tiles to be loaded and rendered more quickly, at the cost of a higher network and processing load." ) + float cesium:pointSize = 1 ( + displayName = "Point Size" + doc = "The size in meters to display each point." + ) bool cesium:preloadAncestors = 1 ( displayName = "Preload Ancestors" doc = "Whether to preload ancestor tiles. Setting this to true optimizes the zoom-out experience and provides more detail in newly-exposed areas when panning. The down side is that it requires loading more tiles." diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.cpp index af59776a..fd9ac9b7 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.cpp @@ -403,6 +403,23 @@ CesiumTileset::CreateMainThreadLoadingTimeLimitAttr(VtValue const &defaultValue, writeSparsely); } +UsdAttribute +CesiumTileset::GetPointSizeAttr() const +{ + return GetPrim().GetAttribute(CesiumTokens->cesiumPointSize); +} + +UsdAttribute +CesiumTileset::CreatePointSizeAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(CesiumTokens->cesiumPointSize, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + UsdRelationship CesiumTileset::GetGeoreferenceBindingRel() const { @@ -478,6 +495,7 @@ CesiumTileset::GetSchemaAttributeNames(bool includeInherited) CesiumTokens->cesiumSmoothNormals, CesiumTokens->cesiumShowCreditsOnScreen, CesiumTokens->cesiumMainThreadLoadingTimeLimit, + CesiumTokens->cesiumPointSize, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.h b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.h index 05f5a2b5..0208fc5a 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.h +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.h @@ -550,6 +550,28 @@ class CesiumTileset : public UsdGeomGprim CESIUMUSDSCHEMAS_API UsdAttribute CreateMainThreadLoadingTimeLimitAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // POINTSIZE + // --------------------------------------------------------------------- // + /// The size in meters to display each point. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float cesium:pointSize = 1` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + CESIUMUSDSCHEMAS_API + UsdAttribute GetPointSizeAttr() const; + + /// See GetPointSizeAttr(), 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 CreatePointSizeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // --------------------------------------------------------------------- // // GEOREFERENCEBINDING diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp index c1f7cc36..a9544958 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.cpp @@ -58,6 +58,7 @@ CesiumTokensType::CesiumTokensType() : cesiumMinimumZoomLevel("cesium:minimumZoomLevel", TfToken::Immortal), cesiumNorth("cesium:north", TfToken::Immortal), cesiumOverlayRenderMethod("cesium:overlayRenderMethod", TfToken::Immortal), + cesiumPointSize("cesium:pointSize", TfToken::Immortal), cesiumPreloadAncestors("cesium:preloadAncestors", TfToken::Immortal), cesiumPreloadSiblings("cesium:preloadSiblings", TfToken::Immortal), cesiumProjectDefaultIonAccessToken("cesium:projectDefaultIonAccessToken", TfToken::Immortal), @@ -144,6 +145,7 @@ CesiumTokensType::CesiumTokensType() : cesiumMinimumZoomLevel, cesiumNorth, cesiumOverlayRenderMethod, + cesiumPointSize, cesiumPreloadAncestors, cesiumPreloadSiblings, cesiumProjectDefaultIonAccessToken, diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h index 662ea411..1b77f7de 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tokens.h @@ -259,6 +259,10 @@ struct CesiumTokensType { /// /// CesiumPolygonRasterOverlay, CesiumRasterOverlay const TfToken cesiumOverlayRenderMethod; + /// \brief "cesium:pointSize" + /// + /// CesiumTileset + const TfToken cesiumPointSize; /// \brief "cesium:preloadAncestors" /// /// CesiumTileset diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTileset.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTileset.cpp index 9fe2eee8..eb4e77c9 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTileset.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTileset.cpp @@ -158,6 +158,13 @@ _CreateMainThreadLoadingTimeLimitAttr(CesiumTileset &self, return self.CreateMainThreadLoadingTimeLimitAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); } + +static UsdAttribute +_CreatePointSizeAttr(CesiumTileset &self, + object defaultVal, bool writeSparsely) { + return self.CreatePointSizeAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} static std::string _Repr(const CesiumTileset &self) @@ -333,6 +340,13 @@ void wrapCesiumTileset() &_CreateMainThreadLoadingTimeLimitAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetPointSizeAttr", + &This::GetPointSizeAttr) + .def("CreatePointSizeAttr", + &_CreatePointSizeAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("GetGeoreferenceBindingRel", diff --git a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp index a96e2673..74568a3b 100644 --- a/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp +++ b/src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTokens.cpp @@ -96,6 +96,7 @@ void wrapCesiumTokens() _AddToken(cls, "cesiumMinimumZoomLevel", CesiumTokens->cesiumMinimumZoomLevel); _AddToken(cls, "cesiumNorth", CesiumTokens->cesiumNorth); _AddToken(cls, "cesiumOverlayRenderMethod", CesiumTokens->cesiumOverlayRenderMethod); + _AddToken(cls, "cesiumPointSize", CesiumTokens->cesiumPointSize); _AddToken(cls, "cesiumPreloadAncestors", CesiumTokens->cesiumPreloadAncestors); _AddToken(cls, "cesiumPreloadSiblings", CesiumTokens->cesiumPreloadSiblings); _AddToken(cls, "cesiumProjectDefaultIonAccessToken", CesiumTokens->cesiumProjectDefaultIonAccessToken);