Spaces:
Paused
Paused
Polish: preset loading, quota recording, coacd fallback
Browse files- app.py: add ui_load_preset() — loads a saved preset and applies
gr.update() to all 26 UI components across Stage 1-4 tabs.
Add 'Load selected' button to Presets tab wired to all target components.
Preset load/save/delete now fully symmetric.
- stage1_generate.py: record elapsed wall-clock time to quota tracker
after each generate call so the status bar stays accurate.
- stage2_finalize.py: broaden coacd except clause from ImportError to
Exception so any runtime failure (e.g. version mismatch) falls back
to convex_hull gracefully.
- app.py +68 -1
- src/stages/stage1_generate.py +5 -0
- src/stages/stage2_finalize.py +3 -4
app.py
CHANGED
|
@@ -312,6 +312,57 @@ def ui_save_preset(
|
|
| 312 |
return f"✅ Saved preset: `{name}`", ui_refresh_presets()
|
| 313 |
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
def ui_delete_preset(name: str) -> tuple[str, gr.Dropdown]:
|
| 316 |
if not name:
|
| 317 |
return "❌ Select a preset to delete.", ui_refresh_presets()
|
|
@@ -566,9 +617,25 @@ def build_ui() -> gr.Blocks:
|
|
| 566 |
with gr.Row():
|
| 567 |
pr_name = gr.Textbox(label="New preset name", scale=2)
|
| 568 |
pr_save = gr.Button("Save current settings", variant="primary", scale=1)
|
| 569 |
-
|
|
|
|
|
|
|
| 570 |
pr_status = gr.Markdown()
|
| 571 |
pr_refresh.click(fn=ui_refresh_presets, outputs=pr_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
pr_save.click(
|
| 573 |
fn=ui_save_preset,
|
| 574 |
inputs=[
|
|
|
|
| 312 |
return f"✅ Saved preset: `{name}`", ui_refresh_presets()
|
| 313 |
|
| 314 |
|
| 315 |
+
def ui_load_preset(name: str):
|
| 316 |
+
"""Apply a saved preset to all UI components."""
|
| 317 |
+
_no_op = gr.update()
|
| 318 |
+
n = 26 # number of component outputs after pr_status
|
| 319 |
+
if not name:
|
| 320 |
+
return ("❌ Select a preset first.",) + (_no_op,) * n
|
| 321 |
+
try:
|
| 322 |
+
cfg = workspace.load_preset(name)
|
| 323 |
+
except FileNotFoundError:
|
| 324 |
+
return (f"❌ Preset '{name}' not found.",) + (_no_op,) * n
|
| 325 |
+
|
| 326 |
+
s1 = cfg.get("stage1", {})
|
| 327 |
+
s2 = cfg.get("stage2", {})
|
| 328 |
+
s3 = cfg.get("stage3", {})
|
| 329 |
+
s4 = cfg.get("stage4", {})
|
| 330 |
+
|
| 331 |
+
return (
|
| 332 |
+
f"✅ Loaded preset: `{name}`",
|
| 333 |
+
# Stage 1
|
| 334 |
+
gr.update(value=s1.get("model", "TRELLIS.2 (Hard Surface)")),
|
| 335 |
+
gr.update(value=s1.get("quality", "Balanced (~60s)")),
|
| 336 |
+
gr.update(value=s1.get("seed", 42)),
|
| 337 |
+
gr.update(value=s1.get("tex_size", 2048)),
|
| 338 |
+
# Stage 2
|
| 339 |
+
gr.update(value=s2.get("repair", True)),
|
| 340 |
+
gr.update(value=s2.get("cleanup", True)),
|
| 341 |
+
gr.update(value=s2.get("decimate", True)),
|
| 342 |
+
gr.update(value=s2.get("target_faces", 25000)),
|
| 343 |
+
gr.update(value=s2.get("symmetry", False)),
|
| 344 |
+
gr.update(value=s2.get("unwrap", True)),
|
| 345 |
+
gr.update(value=s2.get("normal_bake", True)),
|
| 346 |
+
gr.update(value=s2.get("normal_format", "DirectX (UE5)")),
|
| 347 |
+
gr.update(value=s2.get("albedo_bake", True)),
|
| 348 |
+
gr.update(value=s2.get("material_bake", True)),
|
| 349 |
+
gr.update(value=s2.get("ao", True)),
|
| 350 |
+
gr.update(value=s2.get("ao_quality", "Standard")),
|
| 351 |
+
gr.update(value=s2.get("inpaint", False)),
|
| 352 |
+
gr.update(value=s2.get("lods", True)),
|
| 353 |
+
gr.update(value=s2.get("collision", True)),
|
| 354 |
+
gr.update(value=s2.get("pivot", "bottom_center")),
|
| 355 |
+
gr.update(value=s2.get("scale_m", 1.8)),
|
| 356 |
+
# Stage 3
|
| 357 |
+
gr.update(value=s3.get("rig_type", "Humanoid")),
|
| 358 |
+
gr.update(value=s3.get("seed", 0)),
|
| 359 |
+
gr.update(value=s3.get("format", "FBX (UE5 recommended)")),
|
| 360 |
+
# Stage 4
|
| 361 |
+
gr.update(value=s4.get("engine", "UE5")),
|
| 362 |
+
gr.update(value=s4.get("asset_type", "Prop (SM_)")),
|
| 363 |
+
)
|
| 364 |
+
|
| 365 |
+
|
| 366 |
def ui_delete_preset(name: str) -> tuple[str, gr.Dropdown]:
|
| 367 |
if not name:
|
| 368 |
return "❌ Select a preset to delete.", ui_refresh_presets()
|
|
|
|
| 617 |
with gr.Row():
|
| 618 |
pr_name = gr.Textbox(label="New preset name", scale=2)
|
| 619 |
pr_save = gr.Button("Save current settings", variant="primary", scale=1)
|
| 620 |
+
with gr.Row():
|
| 621 |
+
pr_load = gr.Button("Load selected", variant="secondary", scale=1)
|
| 622 |
+
pr_delete = gr.Button("Delete selected", variant="stop", scale=1)
|
| 623 |
pr_status = gr.Markdown()
|
| 624 |
pr_refresh.click(fn=ui_refresh_presets, outputs=pr_list)
|
| 625 |
+
pr_load.click(
|
| 626 |
+
fn=ui_load_preset,
|
| 627 |
+
inputs=pr_list,
|
| 628 |
+
outputs=[
|
| 629 |
+
pr_status,
|
| 630 |
+
gen_model, gen_quality, gen_seed, gen_tex_size,
|
| 631 |
+
pp_repair, pp_cleanup, pp_decimate, pp_target_faces,
|
| 632 |
+
pp_symmetry, pp_unwrap, pp_normal_bake, pp_normal_format,
|
| 633 |
+
pp_albedo_bake, pp_material_bake, pp_ao, pp_ao_quality,
|
| 634 |
+
pp_inpaint, pp_lods, pp_collision, pp_pivot, pp_scale_m,
|
| 635 |
+
rig_type, rig_seed, rig_format,
|
| 636 |
+
ex_engine, ex_type,
|
| 637 |
+
],
|
| 638 |
+
)
|
| 639 |
pr_save.click(
|
| 640 |
fn=ui_save_preset,
|
| 641 |
inputs=[
|
src/stages/stage1_generate.py
CHANGED
|
@@ -143,6 +143,11 @@ def generate_trellis(
|
|
| 143 |
ws.vertex_count = vertex_count
|
| 144 |
|
| 145 |
elapsed = time.time() - t0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
return (
|
| 147 |
f"✅ **Generated with TRELLIS.2** · {quality}\n\n"
|
| 148 |
f"- Faces: {face_count:,} · Vertices: {vertex_count:,}\n"
|
|
|
|
| 143 |
ws.vertex_count = vertex_count
|
| 144 |
|
| 145 |
elapsed = time.time() - t0
|
| 146 |
+
|
| 147 |
+
# Record approximate GPU time consumed on the remote Space for quota display
|
| 148 |
+
from src import quota as _quota
|
| 149 |
+
_quota.record_usage(f"generate_trellis_{quality.split()[0].lower()}", elapsed)
|
| 150 |
+
|
| 151 |
return (
|
| 152 |
f"✅ **Generated with TRELLIS.2** · {quality}\n\n"
|
| 153 |
f"- Faces: {face_count:,} · Vertices: {vertex_count:,}\n"
|
src/stages/stage2_finalize.py
CHANGED
|
@@ -111,16 +111,15 @@ def generate_collision(input_glb: Path) -> tuple[Path, str]:
|
|
| 111 |
"""Generate convex decomposition collision mesh via CoACD."""
|
| 112 |
import trimesh
|
| 113 |
|
|
|
|
| 114 |
try:
|
| 115 |
import coacd
|
| 116 |
-
mesh = trimesh.load(str(input_glb), force="mesh")
|
| 117 |
m = coacd.Mesh(mesh.vertices, mesh.faces)
|
| 118 |
parts = coacd.run_coacd(m)
|
| 119 |
hulls = [trimesh.Trimesh(p[0], p[1]) for p in parts]
|
| 120 |
collision = trimesh.util.concatenate(hulls)
|
| 121 |
-
except
|
| 122 |
-
# Fallback: single convex hull
|
| 123 |
-
mesh = trimesh.load(str(input_glb), force="mesh")
|
| 124 |
collision = mesh.convex_hull
|
| 125 |
|
| 126 |
out_path = CURRENT / "collision.glb"
|
|
|
|
| 111 |
"""Generate convex decomposition collision mesh via CoACD."""
|
| 112 |
import trimesh
|
| 113 |
|
| 114 |
+
mesh = trimesh.load(str(input_glb), force="mesh")
|
| 115 |
try:
|
| 116 |
import coacd
|
|
|
|
| 117 |
m = coacd.Mesh(mesh.vertices, mesh.faces)
|
| 118 |
parts = coacd.run_coacd(m)
|
| 119 |
hulls = [trimesh.Trimesh(p[0], p[1]) for p in parts]
|
| 120 |
collision = trimesh.util.concatenate(hulls)
|
| 121 |
+
except Exception:
|
| 122 |
+
# Fallback: single convex hull (no coacd or runtime error)
|
|
|
|
| 123 |
collision = mesh.convex_hull
|
| 124 |
|
| 125 |
out_path = CURRENT / "collision.glb"
|