Refactor 3D and HDRI generation to use direct function calls instead of subprocess execution

This commit is contained in:
2026-05-14 10:40:15 +02:00
parent 562a9ad2e6
commit 7468fce40f

47
main.py
View File

@@ -1043,45 +1043,32 @@ Do NOT mention the object itself. Describe the environment in a concise way, e.g
if not self._get_replicate_api_token():
raise RuntimeError("Replicate API token missing. Open settings and add it.")
script_path = os.path.join(BASE_DIR, "image_to_3d.py")
cmd = [sys.executable, script_path, img_path]
base, _ = os.path.splitext(img_path)
glb_path = base + ".glb"
previous_mtime = os.path.getmtime(glb_path) if os.path.isfile(glb_path) else None
result = subprocess.run(
cmd,
capture_output=True,
text=True,
env=self._subprocess_env(),
)
current_mtime = os.path.getmtime(glb_path) if os.path.isfile(glb_path) else None
if current_mtime is not None and current_mtime != previous_mtime:
self._js("window.on_3d_generated", glb_path)
return glb_path
else:
err_msg = (
result.stderr.strip()
or result.stdout.strip()
or "3D conversion did not produce .glb"
)
raise RuntimeError(err_msg)
import image_to_3d
result = image_to_3d.process_image(img_path, self._get_replicate_api_token())
if result and os.path.isfile(result):
return result
raise RuntimeError("3D conversion did not produce .glb")
def _run_equirect_map(self, prompt: str, output_path: str):
"""
Calls your equi map generator script.
Logs command and full output for debugging.
"""
script_path = os.path.join(BASE_DIR, "generate_equirect.py")
cmd = [sys.executable, script_path, "--prompt", prompt, "--output", output_path]
print(f"[HDRI CMD] {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
print(f"[HDRI STDOUT]\n{result.stdout}")
print(f"[HDRI STDERR]\n{result.stderr}")
if result.returncode == 0 and os.path.isfile(output_path):
import generate_equirect
print(f"[HDRI] Generating to: {output_path}")
result = generate_equirect.generate_equirect(
prompt,
output_path,
work_dir=APP_SUPPORT_DIR if IS_FROZEN else BASE_DIR,
)
if result and os.path.isfile(output_path):
print(f"[HDRI OK] Created: {output_path}")
return output_path
else:
raise RuntimeError(result.stderr.strip() or f"HDRI generation failed for {output_path}")
raise RuntimeError(f"HDRI generation failed for {output_path}")
def _on_3d_and_hdri_ready(self, glb_path: str, hdri_path: str):
"""