From 514be3d0b453b19e6dbcb943060eb296cd547c58 Mon Sep 17 00:00:00 2001 From: Benedikt Reiser Date: Tue, 24 Dec 2024 01:24:59 +0100 Subject: [PATCH] feat: publish loading progress via cloudxr --- .../innoactive/serverextension/extension.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/source/extensions/innoactive.serverextension/innoactive/serverextension/extension.py b/source/extensions/innoactive.serverextension/innoactive/serverextension/extension.py index 2870976..f0de012 100644 --- a/source/extensions/innoactive.serverextension/innoactive/serverextension/extension.py +++ b/source/extensions/innoactive.serverextension/innoactive/serverextension/extension.py @@ -153,6 +153,48 @@ def _set_active_camera_in_viewport(self, camera_path): f"Failed to set active camera in the viewport '{camera_path}': {str(e)}" ) + def _on_tick(self, _event): + """ + Handler for the Update Loop event. + """ + # carb.log_info(f"Update Loop event: {event.type} => {event.payload}") + + if self.is_loading: + # check how many files have been loaded on stage + _loading_message, num_loaded_files, num_total_files = ( + omni.usd.get_context().get_stage_loading_status() + ) + + is_loading = num_loaded_files or num_total_files + + if not is_loading: + carb.log_verbose("Finished loading.") + self.is_loading = False + self.send_loading_progress(1) + return + + # carb.log_info( + # f"TICK: Loading message: {loading_message[:10]}... ({num_loaded_files}/{num_total_files})" + # ) + + # calculate the progress + progress = num_loaded_files / num_total_files + self.send_loading_progress(progress) + + def send_loading_progress(self, progress: float): + """ + Sends the loading progress to the client. + Args: + progress (float): The progress value to send. + """ + carb.log_info(f"Sending loading progress: {progress}") + message = { + # XXX: For some reason, the CXR team chose to use "Type" instead of "type" in the message + "Type": "fileLoadingProgress", + "progress": progress, + } + self.send_cloudxr_message(message) + def _on_stage_event(self, event): if event.type == int(omni.usd.StageEventType.OMNIGRAPH_START_PLAY): # notify client that playback has started