Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

Catch blender errors (#569)

philipqueen1bab764ce223
diff --git a/freemocap/core_processes/export_data/blender_stuff/export_to_blender/methods/ajc_addon/run_ajc_addon_main.py b/freemocap/core_processes/export_data/blender_stuff/export_to_blender/methods/ajc_addon/run_ajc_addon_main.py
index 417a15ad..e6b83068 100644
--- a/freemocap/core_processes/export_data/blender_stuff/export_to_blender/methods/ajc_addon/run_ajc_addon_main.py
+++ b/freemocap/core_processes/export_data/blender_stuff/export_to_blender/methods/ajc_addon/run_ajc_addon_main.py
@@ -36,6 +36,12 @@ def run_ajc_blender_addon_subprocess(
blender_file_path: Union[str, Path],
blender_exe_path: Union[str, Path],
):
+ try:
+ ajc_blender_addon_validator(recording_folder_path=recording_folder_path)
+ except FileNotFoundError as e:
+ logger.error("Missing required files to run AJC addon, did something go wrong during processing?")
+ raise e
+
ajc_addon_main_file_path = inspect.getfile(ajc27_run_as_main_function)
logger.debug(f"Running ajc27_freemocap_blender_addon as a subprocess using script at : {ajc_addon_main_file_path}")
@@ -51,7 +57,8 @@ def run_ajc_blender_addon_subprocess(
raise FileNotFoundError(f"Could not find the blender executable at {blender_exe_path}")
except Exception as e:
logger.error(e)
- return
+ raise e
+
simple_run_script = inspect.getfile(run_simple)
command_list = [
@@ -107,6 +114,43 @@ def get_blenders_numpy(blender_exe_path: Union[str, Path]) -> str:
return numpy_path
+def ajc_blender_addon_validator(recording_folder_path: Union[str, Path]):
+ """
+ Check if the required files exist in the recording folder
+ """
+ recording_path = Path(recording_folder_path)
+ output_data_path = recording_path / "output_data"
+
+ if not (output_data_path / "mediapipe_body_3d_xyz.npy").exists():
+ raise FileNotFoundError(f"Could not find required file: {output_data_path / 'mediapipe_body_3d_xyz.npy'}")
+
+ if not (output_data_path / "mediapipe_right_hand_3d_xyz.npy").exists():
+ raise FileNotFoundError(f"Could not find required file: {output_data_path / 'mediapipe_right_hand_3d_xyz.npy'}")
+
+ if not (output_data_path / "mediapipe_left_hand_3d_xyz.npy").exists():
+ raise FileNotFoundError(f"Could not find required file: {output_data_path / 'mediapipe_left_hand_3d_xyz.npy'}")
+
+ if not (output_data_path / "mediapipe_face_3d_xyz.npy").exists():
+ raise FileNotFoundError(f"Could not find required file: {output_data_path / 'mediapipe_face_3d_xyz.npy'}")
+
+ if not (output_data_path / "center_of_mass" / "total_body_center_of_mass_xyz.npy").exists():
+ raise FileNotFoundError(
+ f"Could not find required file: {output_data_path / 'center_of_mass' / 'total_body_center_of_mass_xyz.npy'}"
+ )
+
+ if not (output_data_path / "center_of_mass" / "segmentCOM_frame_joint_xyz.npy").exists():
+ raise FileNotFoundError(
+ f"Could not find required file: {output_data_path / 'center_of_mass' / 'segmentCOM_frame_joint_xyz.npy'}"
+ )
+
+ if not (
+ output_data_path / "raw_data" / "mediapipe3dData_numFrames_numTrackedPoints_reprojectionError.npy"
+ ).exists():
+ raise FileNotFoundError(
+ f"Could not find required file: {output_data_path / 'raw_data' / 'mediapipe3dData_numFrames_numTrackedPoints_reprojectionError.npy'}"
+ )
+
+
if __name__ == "__main__":
from freemocap.core_processes.export_data.blender_stuff.get_best_guess_of_blender_path import (
get_best_guess_of_blender_path,
diff --git a/freemocap/gui/qt/main_window/freemocap_main_window.py b/freemocap/gui/qt/main_window/freemocap_main_window.py
index 4c311a6f..d8d624db 100644
--- a/freemocap/gui/qt/main_window/freemocap_main_window.py
+++ b/freemocap/gui/qt/main_window/freemocap_main_window.py
@@ -310,12 +310,13 @@ class MainWindow(QMainWindow):
kill_thread_event=self._kill_thread_event,
)
self._export_to_blender_thread_worker.start()
- self._export_to_blender_thread_worker.finished.connect(self._handle_export_to_blender_finished)
+ self._export_to_blender_thread_worker.success.connect(self._handle_export_to_blender_finished)
- def _handle_export_to_blender_finished(self) -> None:
- if (
- self._controller_group_box.auto_open_in_blender_checked
- ):
+ @Slot()
+ def _handle_export_to_blender_finished(self, success_value: bool) -> None:
+ if success_value is False:
+ logger.error("Blender export failed!")
+ elif self._controller_group_box.auto_open_in_blender_checked:
if Path(self._active_recording_info_widget.active_recording_info.blender_file_path).exists():
open_file(self._active_recording_info_widget.active_recording_info.blender_file_path)
else:
@@ -356,7 +357,9 @@ class MainWindow(QMainWindow):
try:
self._process_motion_capture_data_panel.update_calibration_path()
- except AttributeError: # Active Recording and Data Panel widgets rely on each other, so we're guaranteed to hit this every time the app opens
+ except (
+ AttributeError
+ ): # Active Recording and Data Panel widgets rely on each other, so we're guaranteed to hit this every time the app opens
logger.debug("Process motion capture data panel not created yet, skipping claibraiton setting")
except Exception as e:
logger.error(e)
diff --git a/freemocap/gui/qt/workers/export_to_blender_thread_worker.py b/freemocap/gui/qt/workers/export_to_blender_thread_worker.py
index 19ecb5b1..af208fd6 100644
--- a/freemocap/gui/qt/workers/export_to_blender_thread_worker.py
+++ b/freemocap/gui/qt/workers/export_to_blender_thread_worker.py
@@ -10,7 +10,7 @@ logger = logging.getLogger(__name__)
class ExportToBlenderThreadWorker(QThread):
- finished = Signal()
+ success = Signal(bool)
in_progress = Signal(str)
def __init__(
@@ -48,11 +48,11 @@ class ExportToBlenderThreadWorker(QThread):
blender_exe_path=self.blender_executable_path,
method=self.blender_method,
)
+ self.success.emit(True)
+ logger.debug("Blender Export Complete")
except Exception as e:
logger.exception("something went wrong in the Blender export")
- logger.exception(e)
+ logger.error(e)
+ self.success.emit(False)
- self.finished.emit()
self._work_done = True
-
- logger.debug("Blender Export Complete")