Skip to content

Commit

Permalink
Merge pull request #718 from CesiumGS/point-size
Browse files Browse the repository at this point in the history
Added pointSize attribute
  • Loading branch information
r-veenstra committed May 31, 2024
2 parents 21b4708 + e80fca0 commit c7c158b
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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

* Fixed point cloud styling.
* 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.
* Fixed point cloud styling.

### v0.20.0 - 2024-05-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
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 @@ -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" (
Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FabricGeometry {
const CesiumGltf::MeshPrimitive& primitive,
const FabricMaterialInfo& materialInfo,
bool smoothNormals,
double pointSize,
const std::unordered_map<uint64_t, uint64_t>& texcoordIndexMapping,
const std::unordered_map<uint64_t, uint64_t>& rasterOverlayTexcoordIndexMapping);

Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class OmniTileset {
[[nodiscard]] glm::dvec3 getDisplayColor() const;
[[nodiscard]] double getDisplayOpacity() const;
[[nodiscard]] std::vector<pxr::SdfPath> getRasterOverlayPaths() const;
[[nodiscard]] double getPointSize() const;

void updateTilesetOptions();

Expand Down
3 changes: 2 additions & 1 deletion src/core/src/FabricGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ void FabricGeometry::setGeometry(
const CesiumGltf::MeshPrimitive& primitive,
const FabricMaterialInfo& materialInfo,
bool smoothNormals,
double pointSize,
const std::unordered_map<uint64_t, uint64_t>& texcoordIndexMapping,
const std::unordered_map<uint64_t, uint64_t>& rasterOverlayTexcoordIndexMapping) {

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/core/src/FabricPrepareRenderResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -267,6 +268,7 @@ void setFabricMeshes(
primitive,
fabricMesh.materialInfo,
smoothNormals,
pointSize,
fabricMesh.texcoordIndexMapping,
fabricMesh.rasterOverlayTexcoordIndexMapping);

Expand Down
12 changes: 12 additions & 0 deletions src/core/src/OmniTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,18 @@ std::vector<pxr::SdfPath> 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<double>(pointSize);
}

void OmniTileset::updateTilesetOptions() {
auto& options = _pTileset->getOptions();
options.maximumScreenSpaceError = getMaximumScreenSpaceError();
Expand Down
1 change: 1 addition & 0 deletions src/core/src/UsdNotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
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 @@ -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."
Expand Down
18 changes: 18 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -478,6 +495,7 @@ CesiumTileset::GetSchemaAttributeNames(bool includeInherited)
CesiumTokens->cesiumSmoothNormals,
CesiumTokens->cesiumShowCreditsOnScreen,
CesiumTokens->cesiumMainThreadLoadingTimeLimit,
CesiumTokens->cesiumPointSize,
};
static TfTokenVector allNames =
_ConcatenateAttributeNames(
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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),
Expand Down Expand Up @@ -144,6 +145,7 @@ CesiumTokensType::CesiumTokensType() :
cesiumMinimumZoomLevel,
cesiumNorth,
cesiumOverlayRenderMethod,
cesiumPointSize,
cesiumPreloadAncestors,
cesiumPreloadSiblings,
cesiumProjectDefaultIonAccessToken,
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 @@ -259,6 +259,10 @@ struct CesiumTokensType {
///
/// CesiumPolygonRasterOverlay, CesiumRasterOverlay
const TfToken cesiumOverlayRenderMethod;
/// \brief "cesium:pointSize"
///
/// CesiumTileset
const TfToken cesiumPointSize;
/// \brief "cesium:preloadAncestors"
///
/// CesiumTileset
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/CesiumUsdSchemas/src/CesiumUsdSchemas/wrapTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c7c158b

Please sign in to comment.