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

Use rel for cartographic polygon #648

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions exts/cesium.omniverse/cesium/omniverse/usdUtils/usdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import re
from pxr import Sdf
from typing import List, Optional
from pxr import UsdGeom

from cesium.usd.plugins.CesiumUsdSchemas import (
CartographicPolygon as CesiumCartographicPolygon,
Data as CesiumData,
Tileset as CesiumTileset,
IonRasterOverlay as CesiumIonRasterOverlay,
Expand Down Expand Up @@ -103,7 +103,7 @@ def add_cartographic_polygon() -> str:
cartographic_polygon_path = Sdf.Path("/CesiumCartographicPolygons").AppendPath(name).pathString
cartographic_polygon_path = omni.usd.get_stage_next_free_path(stage, cartographic_polygon_path, False)

CesiumCartographicPolygon.Define(stage, cartographic_polygon_path)
UsdGeom.BasisCurves.Define(stage, cartographic_polygon_path)
add_globe_anchor_to_prim(cartographic_polygon_path)

return cartographic_polygon_path
Expand Down
2 changes: 0 additions & 2 deletions exts/cesium.powertools/cesium/powertools/powertools_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
save_carb_settings,
save_fabric_stage,
set_sunstudy_from_georef,
convert_curves_to_polygons,
)
import os
from functools import partial
Expand Down Expand Up @@ -52,7 +51,6 @@ def __init__(self, **kwargs):
PowertoolsAction("Save Carb Settings", partial(save_carb_settings, powertools_extension_location)),
PowertoolsAction("Save Fabric Stage", partial(save_fabric_stage, powertools_extension_location)),
PowertoolsAction("Set Sun Study from Georef", set_sunstudy_from_georef),
PowertoolsAction("BasisCurves to Cartographic Polygons", convert_curves_to_polygons),
]

self.frame.set_build_fn(self._build_fn)
Expand Down
40 changes: 0 additions & 40 deletions exts/cesium.powertools/cesium/powertools/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import json
import carb.settings
import os
from cesium.omniverse.usdUtils import add_globe_anchor_to_prim
from cesium.omniverse.utils.cesium_interface import CesiumInterfaceManager
from cesium.usd.plugins.CesiumUsdSchemas import CartographicPolygon
from asyncio import ensure_future


Expand Down Expand Up @@ -84,41 +82,3 @@ def set_sunstudy_from_georef():
north_attr = get_or_create_attribute(environment_prim, "location:north_orientation", Sdf.ValueTypeNames.Float)
north_attr.Set(90.0) # Always set to 90, otherwise the sun is at the wrong angle


async def convert():
ctx = omni.usd.get_context()
stage = ctx.get_stage()
logger = logging.getLogger(__name__)

selection = ctx.get_selection().get_selected_prim_paths()
for curve_path in selection:
curve_prim = stage.GetPrimAtPath(curve_path)

if curve_prim.GetTypeName() != "BasisCurves":
continue

polygon_path = curve_path + "_Cesium"

if stage.GetPrimAtPath(polygon_path).IsValid():
logger.warning(f"{polygon_path} already exists, skipping")
continue

# Create a new cartographic polygon
polygon = CartographicPolygon.Define(stage, polygon_path)
polygon_prim = polygon.GetPrim()

# Add a globe anchor
add_globe_anchor_to_prim(polygon_path)

# Iterate through the curve attributes and copy them to the new polygon
curve_attributes = curve_prim.GetAttributes()
for attrib in curve_attributes:
value = attrib.Get()
if value is not None:
polygon_prim.GetAttribute(attrib.GetName()).Set(attrib.Get())
else:
polygon_prim.GetAttribute(attrib.GetName()).Clear()


def convert_curves_to_polygons():
ensure_future(convert())
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ import pxr.UsdGeom

__MFB_FULL_PACKAGE_NAME: str

class CartographicPolygon(pxr.UsdGeom.BasisCurves):
__instance_size__: ClassVar[int] = ...
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

class Data(pxr.Usd.Typed):
__instance_size__: ClassVar[int] = ...
@classmethod
Expand Down
10 changes: 0 additions & 10 deletions exts/cesium.usd.plugins/schemas/cesium_schemas.usda
Original file line number Diff line number Diff line change
Expand Up @@ -502,16 +502,6 @@ class CesiumPolygonRasterOverlayPrim "CesiumPolygonRasterOverlayPrim" (
)
}

class CesiumCartographicPolygonPrim "CesiumCartographicPolygonPrim" (
doc = """Adds a prim that represents a globe-anchored polygon"""
inherits = </BasisCurves>
prepend apiSchemas = ["CesiumGlobeAnchorSchemaAPI"]
customData = {
string className = "CartographicPolygon"
}
) {
}

class "CesiumGlobeAnchorSchemaAPI" (
doc = """Adds Globe Anchoring information to a Prim for use with Cesium for Omniverse."""
inherits = </APISchemaBase>
Expand Down
5 changes: 2 additions & 3 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <glm/fwd.hpp>
#include <pxr/base/gf/declare.h>
#include <pxr/usd/usd/common.h>
#include <pxr/usd/usdGeom/basisCurves.h>
#include <pxr/usd/usdGeom/xformOp.h>

PXR_NAMESPACE_OPEN_SCOPE
class CesiumCartographicPolygon;
class CesiumData;
class CesiumGeoreference;
class CesiumGlobeAnchorAPI;
Expand Down Expand Up @@ -120,8 +120,7 @@ getCesiumPolygonRasterOverlay(const pxr::UsdStageWeakPtr& pStage, const pxr::Sdf
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);
pxr::CesiumCartographicPolygon
getCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::UsdGeomBasisCurves getCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::UsdShadeShader getUsdShader(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);
pxr::UsdGeomBasisCurves getUsdBasisCurves(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path);

Expand Down
2 changes: 1 addition & 1 deletion src/core/src/OmniCartographicPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "cesium/omniverse/UsdUtil.h"

#include <CesiumGeospatial/Cartographic.h>
#include <CesiumUsdSchemas/cartographicPolygon.h>
#include <CesiumUsdSchemas/globeAnchorAPI.h>
#include <glm/glm.hpp>
#include <pxr/usd/usdGeom/basisCurves.h>

namespace cesium::omniverse {

Expand Down
16 changes: 8 additions & 8 deletions src/core/src/UsdUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "cesium/omniverse/UsdUtil.h"

#include "CesiumUsdSchemas/cartographicPolygon.h"

#include "cesium/omniverse/AssetRegistry.h"
#include "cesium/omniverse/Context.h"
#include "cesium/omniverse/MathUtil.h"
Expand All @@ -18,7 +16,6 @@
#include <CesiumGeospatial/GlobeAnchor.h>
#include <CesiumGeospatial/GlobeTransforms.h>
#include <CesiumGeospatial/LocalHorizontalCoordinateSystem.h>
#include <CesiumUsdSchemas/cartographicPolygon.h>
#include <CesiumUsdSchemas/data.h>
#include <CesiumUsdSchemas/georeference.h>
#include <CesiumUsdSchemas/globeAnchorAPI.h>
Expand Down Expand Up @@ -373,9 +370,10 @@ pxr::CesiumIonServer getCesiumIonServer(const pxr::UsdStageWeakPtr& pStage, cons
return pxr::CesiumIonServer::Get(pStage, path);
}

pxr::CesiumCartographicPolygon
getCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
return pxr::CesiumCartographicPolygon::Get(pStage, path);
// This is currently a pass-through to getUsdBasisCurves until
// issue with crashes in prims that inherit from BasisCurves is resolved
pxr::UsdGeomBasisCurves getCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
return getUsdBasisCurves(pStage, path);
}

pxr::UsdShadeShader getUsdShader(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
Expand Down Expand Up @@ -473,8 +471,10 @@ bool isCesiumCartographicPolygon(const pxr::UsdStageWeakPtr& pStage, const pxr::
if (!prim.IsValid()) {
return false;
}

return prim.IsA<pxr::CesiumCartographicPolygon>();
if (!prim.IsA<pxr::UsdGeomBasisCurves>()) {
return false;
}
return prim.HasAPI<pxr::CesiumGlobeAnchorAPI>();
}

bool isCesiumSession(const pxr::UsdStageWeakPtr& pStage, const pxr::SdfPath& path) {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/CesiumUsdSchemas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include(Macros)

set(SOURCES
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/cartographicPolygon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/data.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/globeAnchorAPI.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/georeference.cpp"
Expand All @@ -16,7 +15,6 @@ set(SOURCES
set(PY_BINDING_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/module.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/moduleDeps.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapCartographicPolygon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapData.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapGlobeAnchorAPI.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/CesiumUsdSchemas/wrapGeoreference.cpp"
Expand Down
Loading
Loading