opsiclear-admin commited on
Commit
6b7910c
·
verified ·
1 Parent(s): 4615b8c

Fix dark texture: revert tex_mode default to stochastic and restore alpha preprocessing

Browse files
Files changed (1) hide show
  1. app.py +5 -20
app.py CHANGED
@@ -29,22 +29,12 @@ import o_voxel
29
  import importlib.util
30
  import sys
31
  _local_postprocess = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'o-voxel', 'o_voxel', 'postprocess.py')
32
- print(f"[PATCH] Looking for local postprocess at: {_local_postprocess}")
33
- print(f"[PATCH] File exists: {os.path.exists(_local_postprocess)}")
34
  if os.path.exists(_local_postprocess):
35
  _spec = importlib.util.spec_from_file_location('o_voxel.postprocess', _local_postprocess)
36
  _mod = importlib.util.module_from_spec(_spec)
37
  _spec.loader.exec_module(_mod)
38
- _has_fix = hasattr(_mod, '_clean_invalid_vertices')
39
- print(f"[PATCH] Loaded local postprocess, has _clean_invalid_vertices: {_has_fix}")
40
- print(f"[PATCH] Old module file: {getattr(o_voxel.postprocess, '__file__', 'unknown')}")
41
- print(f"[PATCH] New module file: {getattr(_mod, '__file__', 'unknown')}")
42
  o_voxel.postprocess = _mod
43
  sys.modules['o_voxel.postprocess'] = _mod
44
- print(f"[PATCH] Monkey-patch applied successfully")
45
- else:
46
- print(f"[PATCH] WARNING: Local postprocess.py not found, using installed version")
47
- print(f"[PATCH] Installed has _clean_invalid_vertices: {hasattr(o_voxel.postprocess, '_clean_invalid_vertices')}")
48
 
49
 
50
  MAX_SEED = np.iinfo(np.int32).max
@@ -380,13 +370,10 @@ def preprocess_image(input: Image.Image) -> Image.Image:
380
  size = int(size * 1)
381
  bbox = center[0] - size // 2, center[1] - size // 2, center[0] + size // 2, center[1] + size // 2
382
  output = output.crop(bbox) # type: ignore
383
- output_np = np.array(output).astype(np.float32)
384
- rgb = output_np[:, :, :3]
385
- alpha = output_np[:, :, 3:4] / 255.0
386
- # Keep full RGB for visible pixels, zero out transparent background
387
- mask = (alpha > 0.05).astype(np.float32)
388
- rgb = rgb * mask
389
- output = Image.fromarray(rgb.astype(np.uint8))
390
  return output
391
 
392
 
@@ -660,8 +647,6 @@ def extract_glb(
660
  shape_slat, tex_slat, res = unpack_state(state)
661
  mesh = pipeline.decode_latent(shape_slat, tex_slat, res)[0]
662
  mesh.simplify(16777216) # nvdiffrast limit
663
- print(f"[EXTRACT] Using postprocess from: {getattr(o_voxel.postprocess, '__file__', 'unknown')}")
664
- print(f"[EXTRACT] Has _clean_invalid_vertices: {hasattr(o_voxel.postprocess, '_clean_invalid_vertices')}")
665
  glb = o_voxel.postprocess.to_glb(
666
  vertices=mesh.vertices,
667
  faces=mesh.faces,
@@ -734,7 +719,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", neutral_hue="slate"))
734
  tex_slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
735
  tex_slat_rescale_t = gr.Slider(1.0, 6.0, label="Rescale T", value=3.0, step=0.1)
736
  multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Structure Algorithm", value="stochastic")
737
- tex_multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Texture Algorithm", value="multidiffusion")
738
 
739
  with gr.Column(scale=10):
740
  preview_output = gr.HTML(empty_html, label="3D Asset Preview", show_label=True, container=True)
 
29
  import importlib.util
30
  import sys
31
  _local_postprocess = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'o-voxel', 'o_voxel', 'postprocess.py')
 
 
32
  if os.path.exists(_local_postprocess):
33
  _spec = importlib.util.spec_from_file_location('o_voxel.postprocess', _local_postprocess)
34
  _mod = importlib.util.module_from_spec(_spec)
35
  _spec.loader.exec_module(_mod)
 
 
 
 
36
  o_voxel.postprocess = _mod
37
  sys.modules['o_voxel.postprocess'] = _mod
 
 
 
 
38
 
39
 
40
  MAX_SEED = np.iinfo(np.int32).max
 
370
  size = int(size * 1)
371
  bbox = center[0] - size // 2, center[1] - size // 2, center[0] + size // 2, center[1] + size // 2
372
  output = output.crop(bbox) # type: ignore
373
+ output_np = np.array(output)
374
+ alpha = output_np[:, :, 3]
375
+ output_np[:, :, :3][alpha < 0.5 * 255] = [0, 0, 0]
376
+ output = Image.fromarray(output_np[:, :, :3])
 
 
 
377
  return output
378
 
379
 
 
647
  shape_slat, tex_slat, res = unpack_state(state)
648
  mesh = pipeline.decode_latent(shape_slat, tex_slat, res)[0]
649
  mesh.simplify(16777216) # nvdiffrast limit
 
 
650
  glb = o_voxel.postprocess.to_glb(
651
  vertices=mesh.vertices,
652
  faces=mesh.faces,
 
719
  tex_slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
720
  tex_slat_rescale_t = gr.Slider(1.0, 6.0, label="Rescale T", value=3.0, step=0.1)
721
  multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Structure Algorithm", value="stochastic")
722
+ tex_multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Texture Algorithm", value="stochastic")
723
 
724
  with gr.Column(scale=10):
725
  preview_output = gr.HTML(empty_html, label="3D Asset Preview", show_label=True, container=True)