Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
854cd53
·
1 Parent(s): 9ee53e8

Enhance texture baking logic in generate3d function of inference.py by integrating OpenCV for color map processing. Updated albedo generation to support photorealistic textures and ensure proper format handling, improving overall texture quality in mesh exports.

Browse files
Files changed (1) hide show
  1. inference.py +14 -4
inference.py CHANGED
@@ -5,6 +5,7 @@ import tempfile
5
  import zipfile
6
  import nvdiffrast.torch as dr
7
  import xatlas
 
8
 
9
  from util.utils import get_tri
10
  from mesh import Mesh
@@ -66,10 +67,19 @@ def generate3d(model, rgb, ccm, device):
66
  mesh_f = data_config['faces'].cpu().numpy()
67
  vmapping, ft, vt = xatlas.parametrize(mesh_v, mesh_f)
68
 
69
- # Bake texture (simulate what export_mesh_wt_uv does, but CPU-only)
70
- # Here, we just fill with white for demo; replace with your actual texture baking logic
71
- tex_res = (1024, 1024)
72
- albedo = np.ones((tex_res[0], tex_res[1], 3), dtype=np.float32) # TODO: bake your texture here
 
 
 
 
 
 
 
 
 
73
 
74
  # Create Mesh and export .glb
75
  mesh = Mesh(
 
5
  import zipfile
6
  import nvdiffrast.torch as dr
7
  import xatlas
8
+ import cv2
9
 
10
  from util.utils import get_tri
11
  from mesh import Mesh
 
67
  mesh_f = data_config['faces'].cpu().numpy()
68
  vmapping, ft, vt = xatlas.parametrize(mesh_v, mesh_f)
69
 
70
+ # Load your color map (photorealistic texture)
71
+ # Assume you save the color map as a PNG somewhere, or pass it as a numpy array
72
+ # If rgb is your color map, convert it to the right format:
73
+ if rgb.max() > 1.0:
74
+ color_map = rgb.astype(np.uint8)
75
+ else:
76
+ color_map = (rgb * 255).astype(np.uint8)
77
+ # If rgb is already in HWC, skip transpose; otherwise, transpose as needed
78
+ if color_map.shape[-1] != 3:
79
+ color_map = np.transpose(color_map, (1, 2, 0))
80
+ albedo = cv2.cvtColor(color_map, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
81
+
82
+ tex_res = (albedo.shape[0], albedo.shape[1])
83
 
84
  # Create Mesh and export .glb
85
  mesh = Mesh(