Skip to content

Commit

Permalink
successfully replaced addTilesetIon
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelser committed Aug 3, 2023
1 parent a36c693 commit 3964ef7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ class Connection:
class ICesiumOmniverseInterface:
def __init__(self, *args, **kwargs) -> None: ...
def add_ion_imagery(self, arg0: str, arg1: str, arg2: int) -> str: ...
def add_tileset_and_imagery(self, arg0: str, arg1: int, arg2: str, arg3: int) -> str: ...
@overload
def add_tileset_ion(self, arg0: str, arg1: int) -> str: ...
@overload
def add_tileset_ion(self, arg0: str, arg1: int, arg2: str) -> str: ...
def add_tileset_url(self, arg0: str, arg1: str) -> str: ...
def connect_to_ion(self) -> None: ...
def create_token(self, arg0: str) -> None: ...
def credits_available(self) -> bool: ...
Expand All @@ -85,7 +79,6 @@ class ICesiumOmniverseInterface:
def get_session(self, *args, **kwargs) -> Any: ...
def get_set_default_token_result(self, *args, **kwargs) -> Any: ...
def is_default_token_set(self) -> bool: ...
def is_tileset(self, arg0: str) -> bool: ...
def is_tracing_enabled(self) -> bool: ...
def on_shutdown(self) -> None: ...
def on_stage_change(self, arg0: int) -> None: ...
Expand All @@ -94,7 +87,6 @@ class ICesiumOmniverseInterface:
def on_update_ui(self) -> None: ...
def print_fabric_stage(self) -> str: ...
def reload_tileset(self, arg0: str) -> None: ...
def remove_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: ...
Expand Down
7 changes: 3 additions & 4 deletions exts/cesium.omniverse/cesium/omniverse/extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .bindings import acquire_cesium_omniverse_interface, release_cesium_omniverse_interface, Viewport
from .install import perform_vendor_install
from .utils import wait_n_frames, dock_window_async
from .utils import wait_n_frames, dock_window_async, add_tileset_ion
from .ui.asset_window import CesiumOmniverseAssetWindow
from .ui.debug_window import CesiumOmniverseDebugWindow
from .ui.main_window import CesiumOmniverseMainWindow
Expand All @@ -23,6 +23,7 @@
import os
from typing import List, Optional, Callable
from .ui.credits_viewport_controller import CreditsViewportController
from pxr import Usd

cesium_extension_location = os.path.join(os.path.dirname(__file__), "../../")

Expand Down Expand Up @@ -286,9 +287,7 @@ def _add_ion_assets(self, asset_to_add: Optional[AssetToAdd], skip_ion_checks=Fa
asset_to_add.imagery_ion_asset_id,
)
else:
tileset_path = _cesium_omniverse_interface.add_tileset_ion(
asset_to_add.tileset_name, asset_to_add.tileset_ion_asset_id
)
tileset_path = add_tileset_ion(asset_to_add.tileset_name, asset_to_add.tileset_ion_asset_id)

if tileset_path == "":
self._logger.warning("Error adding tileset and imagery to stage")
Expand Down
51 changes: 51 additions & 0 deletions exts/cesium.omniverse/cesium/omniverse/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from typing import Optional
import omni.usd
import omni.kit
import omni.ui as ui
import re
from cesium.usd.plugins.CesiumUsdSchemas import (
Imagery as CesiumImagery,
Tileset as CesiumTileset,
Tokens as CesiumTokens,
)


async def wait_n_frames(n: int):
Expand Down Expand Up @@ -29,3 +36,47 @@ def str_is_empty_or_none(s: Optional[str]):
return True

return False


# tileset_path = _cesium_omniverse_interface.add_tileset_ion(
# asset_to_add.tileset_name, asset_to_add.tileset_ion_asset_id
# )


def add_tileset_ion(name: str, tilesetId: int, token: str = ""):
stage = omni.usd.get_context().get_stage()
# tileset_path = omni.usd.get_stage_next_free_path(stage, path, False)

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

tileset_path = omni.usd.get_stage_next_free_path(stage, safeName, False)
tileset = CesiumTileset.Define(stage, tileset_path)
assert tileset.GetPrim().IsValid()

tileset.GetIonAssetIdAttr().Set(tilesetId)
tileset.GetIonAccessTokenAttr().Set(token)
tileset.GetSourceTypeAttr().Set(CesiumTokens.ion)

return tileset_path


# def add_imagery_ion():
# stage = omni.usd.get_context().get_stage()
# imagery_path = omni.usd.get_stage_next_free_path(stage, path, False)
# imagery = CesiumImagery.Define(stage, imagery_path)
# assert imagery.GetPrim().IsValid()
# parent = imagery.GetPrim().GetParent()
# assert parent.IsA(CesiumTileset)
#
# imagery.GetIonAssetIdAttr().Set(asset_id)
# imagery.GetIonAccessTokenAttr().Set(access_token)
#
# return imagery_path


def is_tileset():
pass


def remove_tileset():
pass

0 comments on commit 3964ef7

Please sign in to comment.