rayli commited on
Commit
e22a80a
·
verified ·
1 Parent(s): 834fa67

Show large OBJ warning before full mesh processing

Browse files
Files changed (1) hide show
  1. app.py +37 -2
app.py CHANGED
@@ -3550,8 +3550,7 @@ def _spaces_gpu(fn):
3550
  return spaces.GPU(duration=duration)(fn)
3551
 
3552
 
3553
- def _mesh_face_warning_update(mesh: Any):
3554
- face_count = len(getattr(mesh, "faces", []))
3555
  if face_count <= HIGH_FACE_COUNT_WARNING_THRESHOLD:
3556
  return gr.update(value="", visible=False)
3557
  return gr.update(
@@ -3570,6 +3569,28 @@ def _mesh_face_warning_update(mesh: Any):
3570
  )
3571
 
3572
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3573
  class InstructParticulateApp:
3574
  def __init__(
3575
  self,
@@ -3687,6 +3708,20 @@ class InstructParticulateApp:
3687
  gr.update(value=None, interactive=False),
3688
  )
3689
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3690
  try:
3691
  mesh_hash = _mesh_file_sha256(mesh_path)
3692
  mesh = load_trimesh(mesh_path)
 
3550
  return spaces.GPU(duration=duration)(fn)
3551
 
3552
 
3553
+ def _mesh_face_warning_update_from_face_count(face_count: int):
 
3554
  if face_count <= HIGH_FACE_COUNT_WARNING_THRESHOLD:
3555
  return gr.update(value="", visible=False)
3556
  return gr.update(
 
3569
  )
3570
 
3571
 
3572
+ def _count_obj_faces(path: Path) -> int:
3573
+ face_count = 0
3574
+ with Path(path).open(encoding="utf-8", errors="ignore") as file:
3575
+ for line in file:
3576
+ if not line.startswith("f "):
3577
+ continue
3578
+ face_vertex_count = len(line[2:].strip().split())
3579
+ if face_vertex_count >= 3:
3580
+ face_count += face_vertex_count - 2
3581
+ return face_count
3582
+
3583
+
3584
+ def _mesh_face_warning_update_from_path(path: Path):
3585
+ if Path(path).suffix.lower() != ".obj":
3586
+ return gr.update(value="", visible=False)
3587
+ return _mesh_face_warning_update_from_face_count(_count_obj_faces(Path(path)))
3588
+
3589
+
3590
+ def _mesh_face_warning_update(mesh: Any):
3591
+ return _mesh_face_warning_update_from_face_count(len(getattr(mesh, "faces", [])))
3592
+
3593
+
3594
  class InstructParticulateApp:
3595
  def __init__(
3596
  self,
 
3708
  gr.update(value=None, interactive=False),
3709
  )
3710
  return
3711
+ early_mesh_face_warning = _mesh_face_warning_update_from_path(mesh_path)
3712
+ yield (
3713
+ str(mesh_path),
3714
+ None,
3715
+ early_mesh_face_warning,
3716
+ default_tree_json,
3717
+ default_point_prompt_json,
3718
+ "",
3719
+ *empty_orientation_previews,
3720
+ "",
3721
+ None,
3722
+ gr.update(interactive=False),
3723
+ gr.update(value=None, interactive=False),
3724
+ )
3725
  try:
3726
  mesh_hash = _mesh_file_sha256(mesh_path)
3727
  mesh = load_trimesh(mesh_path)