Skip to content

Commit

Permalink
Merge pull request #674 from CesiumGS/movie-capture-load-tiles
Browse files Browse the repository at this point in the history
Wait for loading tiles when using the movie capture tool
  • Loading branch information
lilleyse authored Feb 14, 2024
2 parents 2945933 + 91f487a commit e57d1e7
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions .vscode/cesium-omniverse-linux.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.audio.test.usd",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.autocapture",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.capture",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.capture.viewport",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.clipboard",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.collaboration.channel_manager",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.collaboration.presence_layer",
Expand Down
1 change: 1 addition & 0 deletions .vscode/cesium-omniverse-windows.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.audiodeviceenum",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.autocapture",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.capture",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.capture.viewport",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.clipboard",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.collaboration.channel_manager",
"${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/exts/omni.kit.collaboration.presence_layer",
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Fixed crash when disabling and re-enabling the extension.
* Fixed crash when removing USD prims in certain order.
* Fixed issue where Cesium ion session would not resume on reload.
* The movie capture tool now waits for tilesets to complete loading before it captures a frame.

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

Expand Down
11 changes: 10 additions & 1 deletion exts/cesium.omniverse/cesium/omniverse/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from typing import List, Optional, Callable
from .ui.credits_viewport_controller import CreditsViewportController
from cesium.usd.plugins.CesiumUsdSchemas import Data as CesiumData, IonServer as CesiumIonServer
from omni.kit.capture.viewport import CaptureExtension

CESIUM_DATA_PRIM_PATH = "/Cesium"

Expand Down Expand Up @@ -70,6 +71,7 @@ def __init__(self) -> None:
self._logger: logging.Logger = logging.getLogger(__name__)
self._menus = []
self._num_credits_viewport_frames: int = 0
self._capture_instance = None

perform_vendor_install()

Expand Down Expand Up @@ -171,6 +173,8 @@ def on_startup(self):
add_raster_overlay_event, self._on_add_raster_overlay_to_tileset
)

self._capture_instance = CaptureExtension.get_instance()

def on_shutdown(self):
self._menus.clear()

Expand Down Expand Up @@ -235,6 +239,8 @@ def on_shutdown(self):
self._add_menu_controller.destroy()
self._add_menu_controller = None

self._capture_instance = None

self._destroy_credits_viewport_frames()

self._logger.info("CesiumOmniverse shutdown")
Expand All @@ -261,7 +267,10 @@ def _on_update_frame(self, _):
self._setup_credits_viewport_frames()
self._num_credits_viewport_frames = len(viewports)

_cesium_omniverse_interface.on_update_frame(viewports)
wait_for_loading_tiles = (
self._capture_instance.progress.capture_status == omni.kit.capture.viewport.CaptureStatus.CAPTURING
)
_cesium_omniverse_interface.on_update_frame(viewports, wait_for_loading_tiles)

def _on_stage_event(self, event):
if _cesium_omniverse_interface is None:
Expand Down
1 change: 1 addition & 0 deletions exts/cesium.omniverse/config/extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ python = false
"omni.kit.viewport.utility" = {}
"omni.kit.property.usd" = {}
"omni.kit.menu.utils" = {}
"omni.kit.capture.viewport" = {}

# Main python module this extension provides, it will be publicly available as "import cesium.omniverse"
[[python.module]]
Expand Down
6 changes: 4 additions & 2 deletions include/cesium/omniverse/CesiumOmniverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ class ICesiumOmniverseInterface {
/**
* @brief Updates all tilesets this frame.
*
* @param viewports A list of viewports.
* @param viewports The viewports.
* @param count The number of viewports.
* @param waitForLoadingTiles Whether to wait for all tiles to load before continuing.
*/
virtual void onUpdateFrame(const ViewportApi* viewports, uint64_t count) noexcept = 0;
virtual void onUpdateFrame(const ViewportApi* viewports, uint64_t count, bool waitForLoadingTiles) noexcept = 0;

/**
* @brief Updates the reference to the USD stage for the C++ layer.
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/PythonBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ PYBIND11_MODULE(CesiumOmniversePythonBindings, m) {
.def("on_startup", &ICesiumOmniverseInterface::onStartup)
.def("on_shutdown", &ICesiumOmniverseInterface::onShutdown)
.def("reload_tileset", &ICesiumOmniverseInterface::reloadTileset)
.def("on_update_frame", [](ICesiumOmniverseInterface& interface, const std::vector<ViewportPythonBinding>& viewports) {
return interface.onUpdateFrame(reinterpret_cast<const ViewportApi*>(viewports.data()), viewports.size());
.def("on_update_frame", [](ICesiumOmniverseInterface& interface, const std::vector<ViewportPythonBinding>& viewports, bool waitForLoadingTiles) {
return interface.onUpdateFrame(reinterpret_cast<const ViewportApi*>(viewports.data()), viewports.size(), waitForLoadingTiles);
})
.def("on_stage_change", &ICesiumOmniverseInterface::onUsdStageChanged)
.def("connect_to_ion", &ICesiumOmniverseInterface::connectToIon)
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/cesium/omniverse/AssetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AssetRegistry {
AssetRegistry(AssetRegistry&&) noexcept = delete;
AssetRegistry& operator=(AssetRegistry&&) noexcept = delete;

void onUpdateFrame(const gsl::span<const Viewport>& viewports);
void onUpdateFrame(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles);

OmniData& addData(const pxr::SdfPath& path);
void removeData(const pxr::SdfPath& path);
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/cesium/omniverse/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Context {
void clearStage();
void reloadStage();

void onUpdateFrame(const gsl::span<const Viewport>& viewports);
void onUpdateFrame(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles);
void onUsdStageChanged(int64_t stageId);

[[nodiscard]] const pxr::UsdStageWeakPtr& getUsdStage() const;
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class OmniTileset {
void updateShaderInput(const pxr::SdfPath& shaderPath, const pxr::TfToken& attributeName);
void updateDisplayColorAndOpacity();

void onUpdateFrame(const gsl::span<const Viewport>& viewports);
void onUpdateFrame(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles);

private:
void updateTransform();
void updateView(const gsl::span<const Viewport>& viewports);
void updateView(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles);
[[nodiscard]] bool updateExtent();
void updateLoadStatus();

Expand Down
4 changes: 2 additions & 2 deletions src/core/src/AssetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ AssetRegistry::AssetRegistry(Context* pContext)

AssetRegistry::~AssetRegistry() = default;

void AssetRegistry::onUpdateFrame(const gsl::span<const Viewport>& viewports) {
void AssetRegistry::onUpdateFrame(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles) {
for (const auto& pTileset : _tilesets) {
pTileset->onUpdateFrame(viewports);
pTileset->onUpdateFrame(viewports, waitForLoadingTiles);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ void Context::reloadStage() {
}
}

void Context::onUpdateFrame(const gsl::span<const Viewport>& viewports) {
void Context::onUpdateFrame(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles) {
_pUsdNotificationHandler->onUpdateFrame();
_pAssetRegistry->onUpdateFrame(viewports);
_pAssetRegistry->onUpdateFrame(viewports, waitForLoadingTiles);
_pCesiumIonServerManager->onUpdateFrame();
}

Expand Down
12 changes: 8 additions & 4 deletions src/core/src/OmniTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,15 @@ void OmniTileset::updateShaderInput(const pxr::SdfPath& shaderPath, const pxr::T
});
}

void OmniTileset::onUpdateFrame(const gsl::span<const Viewport>& viewports) {
void OmniTileset::onUpdateFrame(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles) {
if (!UsdUtil::primExists(_pContext->getUsdStage(), _path)) {
// TfNotice can be slow, and sometimes we get a frame or two before we actually get a chance to react on it.
// This guard prevents us from crashing if the prim no longer exists.
return;
}

updateTransform();
updateView(viewports);
updateView(viewports, waitForLoadingTiles);

if (!_extentSet) {
_extentSet = updateExtent();
Expand Down Expand Up @@ -675,7 +675,7 @@ void OmniTileset::updateTransform() {
}
}

void OmniTileset::updateView(const gsl::span<const Viewport>& viewports) {
void OmniTileset::updateView(const gsl::span<const Viewport>& viewports, bool waitForLoadingTiles) {
const auto visible = UsdUtil::isPrimVisible(_pContext->getUsdStage(), _path);

if (visible && !getSuspendUpdate()) {
Expand All @@ -687,7 +687,11 @@ void OmniTileset::updateView(const gsl::span<const Viewport>& viewports) {
_viewStates.push_back(UsdUtil::computeViewState(*_pContext, georeferencePath, _path, viewport));
}

_pViewUpdateResult = &_pTileset->updateView(_viewStates);
if (waitForLoadingTiles) {
_pViewUpdateResult = &_pTileset->updateViewOffline(_viewStates);
} else {
_pViewUpdateResult = &_pTileset->updateView(_viewStates);
}
}

if (!_pViewUpdateResult) {
Expand Down
4 changes: 2 additions & 2 deletions src/public/CesiumOmniverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class CesiumOmniversePlugin final : public ICesiumOmniverseInterface {
}
}

void onUpdateFrame(const ViewportApi* viewports, uint64_t count) noexcept override {
void onUpdateFrame(const ViewportApi* viewports, uint64_t count, bool waitForLoadingTiles) noexcept override {
const auto span = gsl::span<const Viewport>(reinterpret_cast<const Viewport*>(viewports), count);
_pContext->onUpdateFrame(span);
_pContext->onUpdateFrame(span, waitForLoadingTiles);
}

void onUsdStageChanged(long stageId) noexcept override {
Expand Down

0 comments on commit e57d1e7

Please sign in to comment.