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

Large refactor of the C++ code #626

Merged
merged 31 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9eb0d9c
Cleanup
lilleyse Jan 5, 2024
5029680
Merge branch 'main' into cleanup
lilleyse Jan 19, 2024
61f2698
Use std::array in dispatchImpl
lilleyse Jan 19, 2024
e5bf365
Fix gcc compile error
lilleyse Jan 19, 2024
ba866c0
Fix formatting
lilleyse Jan 19, 2024
cc0f569
Rename getAll functions
lilleyse Jan 22, 2024
7301121
Merge branch 'main' into cleanup
lilleyse Jan 22, 2024
6ba5e2d
Switch to using Context ref for functions
lilleyse Jan 22, 2024
ab4a455
Fix formatting
lilleyse Jan 22, 2024
ad30353
Fix setting globa anchor by prim local transform
lilleyse Jan 22, 2024
7c91f9e
More globe anchor fixes
lilleyse Jan 23, 2024
9d81e04
Create translate, rotate, scale ops if they don't exist
lilleyse Jan 24, 2024
14b27f3
PXR_NS back to pxr
lilleyse Jan 25, 2024
006ff41
Pass Context to FabricAttributesBuilder
lilleyse Jan 25, 2024
91c1481
Fix setting georeference after coordinates
lilleyse Jan 25, 2024
4f06bcd
Globe anchors and tilesets - use first georeference if binding not su…
lilleyse Jan 25, 2024
89b3252
More careful about not logging unsupported styling properties unless …
lilleyse Jan 25, 2024
a3cc968
Separate geographicCoordinates into three properties
lilleyse Jan 25, 2024
14725a6
Update genStubs so it doesn't conflict with regular build directory
lilleyse Jan 25, 2024
151ba22
Update CHANGES.md
lilleyse Jan 25, 2024
e15c8f9
Fix globe anchor detect transform changes
lilleyse Jan 25, 2024
bb46c2d
Remove ECEF rotation and scale properties
lilleyse Jan 25, 2024
7fd2a07
Add getResolvedIonServerPath for tilesets and imagery, remove workaro…
lilleyse Jan 25, 2024
8401244
Move ScopedEdit into own file
lilleyse Jan 25, 2024
66c14ff
Add UI for bindings
lilleyse Jan 25, 2024
29b1c3a
Update CHANGES.md
lilleyse Jan 25, 2024
1795b92
Fix python formatting
lilleyse Jan 26, 2024
0ab7069
Update UsdNotificationHandler for implicitly referenced bindings
lilleyse Jan 26, 2024
be1024c
Update UsdNotificationHandler for implicitly referenced imagery bindings
lilleyse Jan 26, 2024
5e2755e
Add plugin deps to fix linker error on CI
lilleyse Jan 26, 2024
016dd5b
Disable tests
lilleyse Jan 26, 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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

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

* **Breaking change:** Removed `cesium.omniverse.api.globe_anchor`. Globe anchor prims can now be created directly in USD.
* **Breaking change:** Globe anchors no longer add a `cesium:transform` op to the attached prim. Instead they modify the `translate`, `rotate` (all variants), and `scale` ops directly.
* Tilesets are no longer required to supply a `cesium:georeferenceBinding` target if they are meant to be rendered in a local coordinate system

### v0.16.0 - 2024-01-02

* Fixed issue where the current ion session would be signed out on reload.
Expand Down
Empty file.
14 changes: 0 additions & 14 deletions exts/cesium.omniverse/cesium/omniverse/api/globe_anchor.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,29 @@ class Connection:

class ICesiumOmniverseInterface:
def __init__(self, *args, **kwargs) -> None: ...
@overload
def add_global_anchor_to_prim(self, arg0: str) -> None: ...
@overload
def add_global_anchor_to_prim(self, arg0: str, arg1: float, arg2: float, arg3: float) -> None: ...
def connect_to_ion(self) -> None: ...
def create_token(self, arg0: str) -> None: ...
def credits_available(self) -> bool: ...
def credits_start_next_frame(self) -> None: ...
def get_all_server_paths(self) -> List[str]: ...
def get_all_sessions(self, *args, **kwargs) -> Any: ...
def get_asset_token_troubleshooting_details(self, *args, **kwargs) -> Any: ...
def get_asset_troubleshooting_details(self, *args, **kwargs) -> Any: ...
def get_credits(self) -> List[Tuple[str, bool]]: ...
def get_default_token_troubleshooting_details(self, *args, **kwargs) -> Any: ...
def get_render_statistics(self, *args, **kwargs) -> Any: ...
def get_server_path(self) -> str: ...
def get_server_paths(self) -> List[str]: ...
def get_session(self, *args, **kwargs) -> Any: ...
def get_sessions(self, *args, **kwargs) -> Any: ...
def get_set_default_token_result(self, *args, **kwargs) -> Any: ...
def is_default_token_set(self) -> bool: ...
def is_tracing_enabled(self) -> bool: ...
def on_shutdown(self) -> None: ...
def on_stage_change(self, arg0: int) -> None: ...
def on_startup(self, arg0: str) -> None: ...
def on_update_frame(self, arg0) -> None: ...
def on_update_ui(self) -> None: ...
def on_update_frame(self, arg0: List[ViewportPythonBinding]) -> None: ...
def print_fabric_stage(self) -> str: ...
def reload_tileset(self, arg0: str) -> None: ...
def select_token(self, arg0: str, arg1: str) -> None: ...
def set_georeference_origin(self, arg0: float, arg1: float, arg2: float) -> None: ...
def specify_token(self, arg0: str) -> None: ...
@overload
def update_troubleshooting_details(self, arg0: str, arg1: int, arg2: int, arg3: int) -> None: ...
Expand Down
4 changes: 3 additions & 1 deletion exts/cesium.omniverse/cesium/omniverse/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .ui.add_menu_controller import CesiumAddMenuController
from .install import perform_vendor_install
from .utils import wait_n_frames, dock_window_async, perform_action_after_n_frames_async
from .usdUtils import add_tileset_ion, add_imagery_ion, add_cartographic_polygon
from .usdUtils import add_tileset_ion, add_imagery_ion, add_cartographic_polygon, get_or_create_cesium_data
from .ui.asset_window import CesiumOmniverseAssetWindow
from .ui.debug_window import CesiumOmniverseDebugWindow
from .ui.main_window import CesiumOmniverseMainWindow
Expand Down Expand Up @@ -270,6 +270,8 @@ def _on_stage_event(self, event):
if not fabric_enabled:
asyncio.ensure_future(perform_action_after_n_frames_async(15, CesiumOmniverseExtension._open_modal))

get_or_create_cesium_data()

self._setup_ion_server_prims()
elif event.type == int(omni.usd.StageEventType.CLOSED):
_cesium_omniverse_interface.on_stage_change(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
PolygonImagery as CesiumPolygonImagery,
IonImagery as CesiumIonImagery,
)
from ..api.globe_anchor import anchor_xform_at_path
from ..usdUtils import add_globe_anchor_to_prim
from ..bindings import ICesiumOmniverseInterface


Expand Down Expand Up @@ -49,7 +49,7 @@ def destroy(self):

def _add_globe_anchor_api(self, payload: PrimSelectionPayload):
for path in payload:
anchor_xform_at_path(path)
add_globe_anchor_to_prim(path)
get_property_window().request_rebuild()

def _add_ion_imagery(self, payload: PrimSelectionPayload):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .models import IonAssetItem
from ..models import AssetToAdd, ImageryToAdd
from .styles import CesiumOmniverseUiStyles
from ..usdUtils import is_tileset, get_all_tileset_paths
from ..usdUtils import is_tileset, get_tileset_paths


class CesiumAssetDetailsWidget(ui.ScrollingFrame):
Expand Down Expand Up @@ -80,7 +80,7 @@ def _add_imagery_button_clicked(self):
tileset_path = selection[0]

if tileset_path is None:
all_tileset_paths = get_all_tileset_paths()
all_tileset_paths = get_tileset_paths()

if len(all_tileset_paths) > 0:
tileset_path = all_tileset_paths[0]
Expand Down
6 changes: 3 additions & 3 deletions exts/cesium.omniverse/cesium/omniverse/ui/debug_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import omni.ui as ui
from .statistics_widget import CesiumOmniverseStatisticsWidget
from ..bindings import ICesiumOmniverseInterface
from ..usdUtils import remove_tileset, get_all_tileset_paths
from ..usdUtils import remove_tileset, get_tileset_paths


class CesiumOmniverseDebugWindow(ui.Window):
Expand Down Expand Up @@ -44,15 +44,15 @@ def _build_fn(self):
def remove_all_tilesets():
"""Removes all tilesets from the stage."""

tileset_paths = get_all_tileset_paths()
tileset_paths = get_tileset_paths()

for tileset_path in tileset_paths:
remove_tileset(tileset_path)

def reload_all_tilesets():
"""Reloads all tilesets."""

tileset_paths = get_all_tileset_paths()
tileset_paths = get_tileset_paths()

for tileset_path in tileset_paths:
self._cesium_omniverse_interface.reload_tileset(tileset_path)
Expand Down
2 changes: 0 additions & 2 deletions exts/cesium.omniverse/cesium/omniverse/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ def _setup_subscriptions(self):
)

def _on_update_frame(self, _e: carb.events.IEvent):
self._cesium_omniverse_interface.on_update_ui()
lilleyse marked this conversation as resolved.
Show resolved Hide resolved

session: CesiumIonSession = self._cesium_omniverse_interface.get_session()

if session is not None and self._sign_in_widget is not None:
Expand Down
4 changes: 2 additions & 2 deletions exts/cesium.omniverse/cesium/omniverse/ui/profile_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def _on_update_frame(self, _e: carb.events.IEvent):

stage = omni.usd.get_context().get_stage()

sessions = self._cesium_omniverse_interface.get_all_sessions()
server_paths = self._cesium_omniverse_interface.get_all_server_paths()
sessions = self._cesium_omniverse_interface.get_sessions()
server_paths = self._cesium_omniverse_interface.get_server_paths()
servers = [CesiumIonServer.Get(stage, server_path) for server_path in server_paths]
server_names = [server.GetDisplayNameAttr().Get() for server in servers]
current_server_path = self._cesium_omniverse_interface.get_server_path()
Expand Down
139 changes: 90 additions & 49 deletions exts/cesium.omniverse/cesium/omniverse/usdUtils/usdUtils.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,71 @@
import omni.usd
import omni.kit
import re
from typing import List
from ..utils.cesium_interface import CesiumInterfaceManager

from pxr import Sdf
from typing import List, Optional

from cesium.usd.plugins.CesiumUsdSchemas import (
IonImagery as CesiumIonImagery,
CartographicPolygon as CesiumCartographicPolygon,
Data as CesiumData,
Tileset as CesiumTileset,
IonImagery as CesiumIonImagery,
Georeference as CesiumGeoreference,
GlobeAnchorAPI as CesiumGlobeAnchorAPI,
Tokens as CesiumTokens,
Data as CesiumData,
)
from pxr import Sdf
from pxr.UsdGeom import Gprim

CESIUM_DATA_PRIM_PATH = "/Cesium"
CESIUM_GEOREFERENCE_PRIM_PATH = "/CesiumGeoreference"


def get_safe_name(name: str) -> str:
return re.sub("[\\W]+", "_", name)


def get_or_create_cesium_data() -> CesiumData:
stage = omni.usd.get_context().get_stage()

path = CESIUM_DATA_PRIM_PATH
prim = stage.GetPrimAtPath(path)

if prim.IsValid():
return CesiumData.Get(stage, path)

return CesiumData.Define(stage, path)


def get_or_create_cesium_georeference() -> CesiumGeoreference:
stage = omni.usd.get_context().get_stage()

georeference_paths = get_georeference_paths()

if len(georeference_paths) < 1:
return CesiumGeoreference.Define(stage, CESIUM_GEOREFERENCE_PRIM_PATH)

return CesiumGeoreference.Get(stage, georeference_paths[0])

def add_tileset_ion(name: str, tileset_id: int, token: str = "") -> str:

def add_tileset_ion(name: str, asset_id: int, token: str = "") -> str:
stage = omni.usd.get_context().get_stage()

safe_name = re.sub("[\\W]+", "_", name)
safe_name = get_safe_name(name)
if not safe_name.startswith("/"):
safe_name = "/" + safe_name

tileset_path: str = omni.usd.get_stage_next_free_path(stage, safe_name, False)
# get_stage_next_free_path will increment the path name if there is a collision
tileset_path = omni.usd.get_stage_next_free_path(stage, safe_name, False)

tileset = CesiumTileset.Define(stage, tileset_path)
assert tileset.GetPrim().IsValid()

tileset.GetIonAssetIdAttr().Set(tileset_id)
tileset.GetIonAssetIdAttr().Set(asset_id)
tileset.GetIonAccessTokenAttr().Set(token)
tileset.GetSourceTypeAttr().Set(CesiumTokens.ion)

georeference = get_or_create_cesium_georeference()
georeference_path = georeference.GetPath().pathString
tileset.GetGeoreferenceBindingRel().AddTarget(georeference_path)

server_prim_path = get_path_to_current_ion_server()
if server_prim_path != Sdf.Path.emptyPath:
if server_prim_path != "":
tileset.GetIonServerBindingRel().AddTarget(server_prim_path)

return tileset_path
Expand All @@ -42,75 +74,84 @@ def add_tileset_ion(name: str, tileset_id: int, token: str = "") -> str:
def add_imagery_ion(tileset_path: str, name: str, asset_id: int, token: str = "") -> str:
stage = omni.usd.get_context().get_stage()

safe_name = re.sub("[\\W]+", "_", name)
safe_name = get_safe_name(name)

imagery_path: str = Sdf.Path(tileset_path).AppendPath(safe_name)
imagery_path = Sdf.Path(tileset_path).AppendPath(safe_name).pathString

# get_stage_next_free_path will increment the path name if there is a colllision
imagery_path: str = Sdf.Path(omni.usd.get_stage_next_free_path(stage, imagery_path, False))
# get_stage_next_free_path will increment the path name if there is a collision
imagery_path = omni.usd.get_stage_next_free_path(stage, imagery_path, False)

imagery = CesiumIonImagery.Define(stage, imagery_path)
assert imagery.GetPrim().IsValid()
parent = imagery.GetPrim().GetParent()
assert parent.IsA(CesiumTileset)

imagery.GetIonAssetIdAttr().Set(asset_id)
imagery.GetIonAccessTokenAttr().Set(token)

server_prim_path = get_path_to_current_ion_server()
if server_prim_path != Sdf.Path.emptyPath:
if server_prim_path != "":
corybarr marked this conversation as resolved.
Show resolved Hide resolved
imagery.GetIonServerBindingRel().AddTarget(server_prim_path)

return imagery_path


def add_cartographic_polygon() -> None:
safe_name = "cartographic_polygon"
cartographic_polygon_path: str = Sdf.Path("/CesiumCartographicPolygons").AppendPath(safe_name)
def add_cartographic_polygon() -> str:
stage = omni.usd.get_context().get_stage()
cartographic_polygon_path = Sdf.Path(omni.usd.get_stage_next_free_path(stage, cartographic_polygon_path, False))

with CesiumInterfaceManager() as interface:
interface.add_cartographic_polygon_prim(str(cartographic_polygon_path))
name = "cartographic_polygon"
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)
add_globe_anchor_to_prim(cartographic_polygon_path)

def is_tileset(maybe_tileset: Gprim) -> bool:
return maybe_tileset.IsA(CesiumTileset)
return cartographic_polygon_path


def remove_tileset(tileset_path: str) -> None:
def is_tileset(path: str) -> bool:
stage = omni.usd.get_context().get_stage()

stage.RemovePrim(Sdf.Path(tileset_path))
prim = stage.GetPrimAtPath(path)
return prim.IsA(CesiumTileset)


def get_path_to_current_ion_server() -> Sdf.Path:
def remove_tileset(path: str) -> None:
stage = omni.usd.get_context().get_stage()
stage.RemovePrim(path)

data: CesiumData = CesiumData.Get(stage, CESIUM_DATA_PRIM_PATH)

if not data.GetPrim().IsValid():
return Sdf.Path()

def get_path_to_current_ion_server() -> Optional[str]:
data = get_or_create_cesium_data()
rel = data.GetSelectedIonServerRel()
targets = rel.GetForwardedTargets()

return targets[0]
if len(targets) < 1:
return None

return targets[0].pathString

def set_path_to_current_ion_server(server_path: str):
stage = omni.usd.get_context().get_stage()

data = CesiumData.Get(stage, CESIUM_DATA_PRIM_PATH)
def set_path_to_current_ion_server(path: str) -> None:
data = get_or_create_cesium_data()
rel = data.GetSelectedIonServerRel()
rel.SetTargets([path])

if not data.GetPrim().IsValid():
return

rel = data.GetSelectedIonServerRel()
rel.SetTargets([server_path])
def get_tileset_paths() -> List[str]:
stage = omni.usd.get_context().get_stage()
paths = [x.GetPath().pathString for x in stage.Traverse() if x.IsA(CesiumTileset)]
return paths


def get_georeference_paths() -> List[str]:
stage = omni.usd.get_context().get_stage()
paths = [x.GetPath().pathString for x in stage.Traverse() if x.IsA(CesiumGeoreference)]
return paths


def get_all_tileset_paths() -> List[str]:
def add_globe_anchor_to_prim(path: str) -> CesiumGlobeAnchorAPI:
stage = omni.usd.get_context().get_stage()
tileset_paths = [x.GetPath().pathString for x in stage.Traverse() if x.IsA(CesiumTileset)]
return tileset_paths
prim = stage.GetPrimAtPath(path)
georeference_path = get_or_create_cesium_georeference().GetPath().pathString

globe_anchor = CesiumGlobeAnchorAPI.Apply(prim)
globe_anchor.GetGeoreferenceBindingRel().AddTarget(georeference_path)

return globe_anchor
4 changes: 2 additions & 2 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ export gltf_texture_lookup_value cesium_internal_imagery_layer_resolver(
}

export gltf_texture_lookup_value cesium_internal_clipping_imagery_layer_resolver(
uniform int clipping_imagery_layers_count = 0,
uniform int imagery_layers_count = 0,
gltf_texture_lookup_value imagery_layer_0 = gltf_texture_lookup_value(),
gltf_texture_lookup_value imagery_layer_1 = gltf_texture_lookup_value(),
gltf_texture_lookup_value imagery_layer_2 = gltf_texture_lookup_value(),
Expand Down Expand Up @@ -1649,7 +1649,7 @@ export gltf_texture_lookup_value cesium_internal_clipping_imagery_layer_resolver

auto resolved_value = float4(0.0);

for (int i = 0; i < clipping_imagery_layers_count; i++) {
for (int i = 0; i < imagery_layers_count; i++) {
auto imagery_layer = imagery_layers[i];
if (imagery_layer.valid) {
resolved_value += imagery_layer.value;
Expand Down
Loading
Loading