Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
ffc0d64
·
1 Parent(s): c69515e

Enhance mesh generation in app.py and inference.py with hole filling and color assignment

Browse files

- Integrated trimesh for mesh hole filling after generation.
- Implemented KDTree for efficient nearest vertex color assignment for newly generated vertices.
- Updated remesh iterations in generate3d function to improve mesh quality.

Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -18,6 +18,8 @@ import json
18
  import argparse
19
  import requests
20
  import tempfile
 
 
21
 
22
  from model import CRM
23
  from inference import generate3d
@@ -276,4 +278,19 @@ with gr.Blocks() as demo:
276
  inputs=inputs,
277
  outputs=outputs,
278
  )
279
- demo.queue().launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  import argparse
19
  import requests
20
  import tempfile
21
+ import trimesh
22
+ from scipy.spatial import cKDTree
23
 
24
  from model import CRM
25
  from inference import generate3d
 
278
  inputs=inputs,
279
  outputs=outputs,
280
  )
281
+ demo.queue().launch()
282
+
283
+ # After mesh generation, fill holes
284
+ mesh = trimesh.Trimesh(vertices=verts, faces=faces)
285
+ mesh.fill_holes()
286
+
287
+ # Find new vertices (those not in the original set)
288
+ if mesh.vertices.shape[0] > old_vertices.shape[0]:
289
+ new_vtx = mesh.vertices[old_vertices.shape[0]:]
290
+ # Use KDTree to find nearest old vertex for each new vertex
291
+ tree = cKDTree(old_vertices)
292
+ dists, idxs = tree.query(new_vtx)
293
+ new_colors = old_colors[idxs]
294
+ # Concatenate old and new colors
295
+ all_colors = np.vstack([old_colors, new_colors])
296
+ mesh.visual.vertex_colors = all_colors