From 5de3c171550ffa6386b4c8ce0d0c28ac005dc5eb Mon Sep 17 00:00:00 2001 From: ud18010 Date: Fri, 17 Jul 2026 17:16:00 +0800 Subject: [PATCH] =?UTF-8?q?ModelTranslator:=20Quit/RunRizomUV=20=E8=B5=B0?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E9=80=9A=E9=81=93=E9=98=B2=E6=8C=82=E6=AD=BB?= =?UTF-8?q?=20+=20=5Fcall=20=E5=88=86=E6=94=AF=E5=8D=95=E6=B5=8B=EF=BC=88?= =?UTF-8?q?=E5=AE=A1=E6=9F=A5=E4=BF=AE=E5=A4=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- Tools/ModelTranslator/rizom_unwrap.py | 11 ++++++----- Tools/ModelTranslator/tests/test_rizom_unwrap.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Tools/ModelTranslator/rizom_unwrap.py b/Tools/ModelTranslator/rizom_unwrap.py index d4e32eb6..09e8d44a 100644 --- a/Tools/ModelTranslator/rizom_unwrap.py +++ b/Tools/ModelTranslator/rizom_unwrap.py @@ -53,7 +53,8 @@ def find_rizomuv(cli_arg=None, use_registry=True, default=DEFAULT_RIZOM): def _import_link(exe): - """从 RizomUV 安装目录动态引入官方 RizomUVLink 模块(随安装自带,MIT)。""" + """从 RizomUV 安装目录动态引入官方 RizomUVLink 模块(随安装自带,MIT)。 + 同进程只支持单一安装路径(import 缓存,首次 import 后不会再切换目录)。""" link_dir = os.path.join(os.path.dirname(exe), "RizomUVLink") if not os.path.isdir(link_dir): raise RizomError("RizomUVLink 目录不存在:%s" % link_dir) @@ -95,8 +96,8 @@ def rizom_unwrap(fbx_path, exe, map_res=MAP_RES, padding_px=PADDING_PX): mod = _import_link(exe) link = mod.CRizomUVLink() try: - link.RunRizomUV(exePath=exe) - except Exception as e: + _call("RunRizomUV", lambda _p: link.RunRizomUV(exePath=exe), None, timeout=60) + except RizomError as e: raise RizomError("RizomUV 启动失败(license/环境):%s" % e) fbx_abs = os.path.abspath(fbx_path) pad_uv = float(padding_px) / map_res @@ -137,6 +138,6 @@ def rizom_unwrap(fbx_path, exe, map_res=MAP_RES, padding_px=PADDING_PX): _call("Save", link.Save, {"File.Path": fbx_abs}) finally: try: - link.Quit({}) + _call("Quit", link.Quit, {}, timeout=10) except Exception: - pass + print("[警告] RizomUV Quit 未确认,可能残留 rizomuv 进程占用 license") diff --git a/Tools/ModelTranslator/tests/test_rizom_unwrap.py b/Tools/ModelTranslator/tests/test_rizom_unwrap.py index 3b2e2096..59908c5b 100644 --- a/Tools/ModelTranslator/tests/test_rizom_unwrap.py +++ b/Tools/ModelTranslator/tests/test_rizom_unwrap.py @@ -1,5 +1,6 @@ import os import sys +import time import unittest from unittest import mock @@ -35,5 +36,19 @@ class TestFindRizomuv(unittest.TestCase): self.assertTrue(os.path.isfile(p), "注册表返回值应是真实 exe:%s" % p) +class TestCall(unittest.TestCase): + def test_timeout_raises(self): + with self.assertRaises(ru.RizomError) as cm: + ru._call("Slow", lambda p: time.sleep(1.0), None, timeout=0.05) + self.assertIn("超时", str(cm.exception)) + + def test_error_dict_raises(self): + with self.assertRaises(ru.RizomError): + ru._call("Bad", lambda p: {"Error": {"Msg": "x", "Code": 1}}, {}) + + def test_normal_dict_passes_through(self): + self.assertEqual(ru._call("Ok", lambda p: {"Data": 1}, {}), {"Data": 1}) + + if __name__ == "__main__": unittest.main()