Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
fix: make trellis2 file timestamp scanning more robust
sakalond94cb9b76999f
diff --git a/stablegen/core/preferences.py b/stablegen/core/preferences.pyindex 8d8ff7e..c3dc72e 100644--- a/stablegen/core/preferences.py+++ b/stablegen/core/preferences.py@@ -155,6 +155,12 @@ class StableGenAddonPreferences(bpy.types.AddonPreferences):default=600.0, min=60.0, max=3600.0, step=100, precision=0,) # type: ignore+ timeout_scan: bpy.props.FloatProperty(+ name="Scan Timeout (s)",+ description="Timeout per request when guessing GLB filenames",+ default=10.0, min=1.0, max=120.0, step=100, precision=0,+ ) # type: ignore+enable_scene_queue: bpy.props.BoolProperty(name="Enable Scene Queue",description="Show the Scene Queue panel in the sidebar",@@ -212,6 +218,7 @@ class StableGenAddonPreferences(bpy.types.AddonPreferences):col.prop(self, "timeout_transfer")col.prop(self, "timeout_reboot")col.prop(self, "timeout_mesh_gen")+ col.prop(self, "timeout_scan")# ── Server-status check operator ──────────────────────────────────────────diff --git a/stablegen/mesh_gen/workflows.py b/stablegen/mesh_gen/workflows.pyindex 4fe3701..fdd9aec 100644--- a/stablegen/mesh_gen/workflows.py+++ b/stablegen/mesh_gen/workflows.py@@ -723,7 +723,6 @@ class _Trellis2WorkflowMixin:# Or just check common ComfyUI locationscommon_paths = [os.path.join(os.environ.get('COMFYUI_PATH', ''), 'output'),- 'E:/tools/ComfyUI/output','C:/ComfyUI/output',os.path.expanduser('~/ComfyUI/output'),]@@ -758,23 +757,36 @@ class _Trellis2WorkflowMixin:# block for minutes, and check for cancellation each iteration.is_remote = not self._is_local_server(server_address)scan_range = 30 if is_remote else 120 # fewer guesses for remote- scan_timeout = 5 if is_remote else 10 # per-request timeout (seconds)- now = datetime.now()+ scan_timeout = get_timeout('scan')+ if is_remote:+ scan_timeout = max(1.0, scan_timeout / 2.0)++ clock_offset = getattr(self, '_clock_offset', timedelta(0))+ now_local = datetime.now() + clock_offset+ candidates = [now_local]+ if is_remote:+ clock_offset_utc = getattr(self, '_clock_offset_utc', None)+ if clock_offset_utc is not None:+ now_utc = datetime.now() + clock_offset_utc+ if abs((now_utc - now_local).total_seconds()) > 5:+ candidates.append(now_utc)+for delta_seconds in range(0, scan_range):if _cancelled():return {"error": "cancelled"}for delta in [timedelta(seconds=-delta_seconds), timedelta(seconds=delta_seconds)]:- candidate_time = now + delta- candidate_name = f"{unique_prefix}_{candidate_time.strftime('%Y%m%d_%H%M%S')}.glb"- try:- view_url = f"http://{server_address}/view?filename={urllib.parse.quote(candidate_name)}&type=output"- glb_response = urllib.request.urlopen(view_url, timeout=scan_timeout)- glb_data = glb_response.read()- if glb_data and len(glb_data) > 0:- print(f"[TRELLIS2] Found GLB via timestamp scan: {candidate_name} ({len(glb_data)} bytes)")- return glb_data- except Exception:- continue+ for base_now in candidates:+ candidate_time = base_now + delta+ candidate_name = f"{unique_prefix}_{candidate_time.strftime('%Y%m%d_%H%M%S')}.glb"+ try:+ view_url = f"http://{server_address}/view?filename={urllib.parse.quote(candidate_name)}&type=output"+ glb_response = urllib.request.urlopen(view_url, timeout=scan_timeout)+ glb_data = glb_response.read()+ if glb_data and len(glb_data) > 0:+ print(f"[TRELLIS2] Found GLB via timestamp scan: {candidate_name} ({len(glb_data)} bytes)")+ return glb_data+ except Exception:+ continueif _cancelled():return {"error": "cancelled"}diff --git a/stablegen/timeout_config.py b/stablegen/timeout_config.pyindex 31d7de3..1c902cf 100644--- a/stablegen/timeout_config.py+++ b/stablegen/timeout_config.py@@ -2,7 +2,7 @@import bpy # pylint: disable=import-error-_DEFAULTS = {'ping': 1.0, 'api': 10.0, 'transfer': 120.0, 'reboot': 120.0, 'mesh_gen': 600.0}+_DEFAULTS = {'ping': 1.0, 'api': 10.0, 'transfer': 120.0, 'reboot': 120.0, 'mesh_gen': 600.0, 'scan': 10.0}def get_timeout(category, default=None):diff --git a/stablegen/workflows.py b/stablegen/workflows.pyindex 4b8a19d..5cc4ec8 100644--- a/stablegen/workflows.py+++ b/stablegen/workflows.py@@ -6,6 +6,8 @@ import websocketimport socketimport urllib.requestimport urllib.parse+import email.utils+from datetime import datetime, timezone, timedeltafrom .timeout_config import get_timeout@@ -28,6 +30,8 @@ class _WorkflowBase:operator: The instance of the ComfyUIGenerate operator."""self.operator = operator+ self._clock_offset = timedelta(0)+ self._clock_offset_utc = timedelta(0)def _check_server_alive(self, server_address, timeout=None):"""Return True if the ComfyUI server responds to a lightweight request."""@@ -38,7 +42,25 @@ class _WorkflowBase:f"http://{server_address}/system_stats",method='GET')- urllib.request.urlopen(req, timeout=timeout)+ with urllib.request.urlopen(req, timeout=timeout) as response:+ date_header = response.headers.get('Date')+ if date_header:+ try:+ server_time = email.utils.parsedate_to_datetime(date_header)+ if server_time.tzinfo is None:+ server_time = server_time.replace(tzinfo=timezone.utc)++ server_time_utc = server_time.astimezone(timezone.utc).replace(tzinfo=None)+ client_time_utc = datetime.now(timezone.utc).replace(tzinfo=None)+ client_time_local = datetime.now()++ self._clock_offset = server_time_utc - client_time_utc+ self._clock_offset_utc = server_time_utc - client_time_local++ print(f"[StableGen] Server UTC: {server_time_utc}, Client UTC: {client_time_utc}, Client Local: {client_time_local}")+ print(f"[StableGen] Clock offsets calculated -> drift: {self._clock_offset}, UTC-assumption: {self._clock_offset_utc}")+ except Exception as e_parse:+ print(f"[StableGen] Error parsing HTTP Date header: {e_parse}")return Trueexcept Exception:return False