Refactor 3D and HDRI generation to use direct function calls instead of subprocess execution
This commit is contained in:
47
main.py
47
main.py
@@ -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():
|
if not self._get_replicate_api_token():
|
||||||
raise RuntimeError("Replicate API token missing. Open settings and add it.")
|
raise RuntimeError("Replicate API token missing. Open settings and add it.")
|
||||||
|
|
||||||
script_path = os.path.join(BASE_DIR, "image_to_3d.py")
|
import image_to_3d
|
||||||
cmd = [sys.executable, script_path, img_path]
|
|
||||||
base, _ = os.path.splitext(img_path)
|
result = image_to_3d.process_image(img_path, self._get_replicate_api_token())
|
||||||
glb_path = base + ".glb"
|
if result and os.path.isfile(result):
|
||||||
previous_mtime = os.path.getmtime(glb_path) if os.path.isfile(glb_path) else None
|
return result
|
||||||
result = subprocess.run(
|
|
||||||
cmd,
|
raise RuntimeError("3D conversion did not produce .glb")
|
||||||
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)
|
|
||||||
|
|
||||||
def _run_equirect_map(self, prompt: str, output_path: str):
|
def _run_equirect_map(self, prompt: str, output_path: str):
|
||||||
"""
|
"""
|
||||||
Calls your equi map generator script.
|
Calls your equi map generator script.
|
||||||
Logs command and full output for debugging.
|
Logs command and full output for debugging.
|
||||||
"""
|
"""
|
||||||
script_path = os.path.join(BASE_DIR, "generate_equirect.py")
|
import generate_equirect
|
||||||
cmd = [sys.executable, script_path, "--prompt", prompt, "--output", output_path]
|
|
||||||
print(f"[HDRI CMD] {' '.join(cmd)}")
|
print(f"[HDRI] Generating to: {output_path}")
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
result = generate_equirect.generate_equirect(
|
||||||
print(f"[HDRI STDOUT]\n{result.stdout}")
|
prompt,
|
||||||
print(f"[HDRI STDERR]\n{result.stderr}")
|
output_path,
|
||||||
if result.returncode == 0 and os.path.isfile(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}")
|
print(f"[HDRI OK] Created: {output_path}")
|
||||||
return output_path
|
return output_path
|
||||||
else:
|
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):
|
def _on_3d_and_hdri_ready(self, glb_path: str, hdri_path: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user