Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
3d787d3
·
1 Parent(s): 38006c2

Add color assignment to new vertices in generate3d function

Browse files

- Integrated cKDTree for efficient nearest neighbor search to assign colors to newly generated vertices.
- Created a new mesh using trimesh with updated vertex colors based on nearest old vertices.
- Enhanced overall mesh generation process by incorporating color information into the output.

Files changed (1) hide show
  1. inference.py +13 -0
inference.py CHANGED
@@ -6,6 +6,8 @@ import tempfile
6
  from util.renderer import Renderer
7
  import os
8
  from PIL import Image
 
 
9
 
10
 
11
  def generate3d(model, rgb, ccm, device):
@@ -77,4 +79,15 @@ def generate3d(model, rgb, ccm, device):
77
 
78
  model.export_mesh(data_config, base_path, tri_fea_2=triplane_feature2) # writes .obj
79
 
 
 
 
 
 
 
 
 
 
 
 
80
  return obj_path
 
6
  from util.renderer import Renderer
7
  import os
8
  from PIL import Image
9
+ import trimesh
10
+ from scipy.spatial import cKDTree
11
 
12
 
13
  def generate3d(model, rgb, ccm, device):
 
79
 
80
  model.export_mesh(data_config, base_path, tri_fea_2=triplane_feature2) # writes .obj
81
 
82
+ # Build KDTree for nearest neighbor search
83
+ tree = cKDTree(data_config['verts'].squeeze().cpu().numpy())
84
+
85
+ # For each new vertex, find the nearest old vertex and copy its color
86
+ k = 3 # or 5, etc.
87
+ dists, idxs = tree.query(verts.cpu().numpy(), k=k)
88
+ new_colors = np.mean(color_tri[idxs], axis=1)
89
+
90
+ # Create the new mesh with colors
91
+ mesh = trimesh.Trimesh(vertices=verts.cpu().numpy(), faces=faces.cpu().numpy(), vertex_colors=new_colors)
92
+
93
  return obj_path