Spaces:
Running
on
A100
Running
on
A100
tokenid
commited on
Commit
•
0afca08
1
Parent(s):
73abb7c
glb export
Browse files- app.py +17 -7
- src/utils/mesh_util.py +11 -2
app.py
CHANGED
@@ -19,7 +19,7 @@ from src.utils.camera_util import (
|
|
19 |
get_zero123plus_input_cameras,
|
20 |
get_circular_camera_poses,
|
21 |
)
|
22 |
-
from src.utils.mesh_util import save_obj
|
23 |
from src.utils.infer_util import remove_background, resize_foreground, images_to_video
|
24 |
|
25 |
import tempfile
|
@@ -190,6 +190,7 @@ def make3d(images):
|
|
190 |
mesh_basename = os.path.basename(mesh_fpath).split('.')[0]
|
191 |
mesh_dirname = os.path.dirname(mesh_fpath)
|
192 |
video_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.mp4")
|
|
|
193 |
|
194 |
with torch.no_grad():
|
195 |
# get triplane
|
@@ -237,10 +238,11 @@ def make3d(images):
|
|
237 |
faces = faces[:, [2, 1, 0]]
|
238 |
|
239 |
save_obj(vertices, faces, vertex_colors, mesh_fpath)
|
|
|
240 |
|
241 |
print(f"Mesh saved to {mesh_fpath}")
|
242 |
|
243 |
-
return mesh_fpath
|
244 |
|
245 |
|
246 |
_HEADER_ = '''
|
@@ -336,10 +338,18 @@ with gr.Blocks() as demo:
|
|
336 |
# )
|
337 |
|
338 |
with gr.Row():
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
|
344 |
with gr.Row():
|
345 |
gr.Markdown('''Try a different <b>seed value</b> if the result is unsatisfying (Default: 42).''')
|
@@ -361,7 +371,7 @@ with gr.Blocks() as demo:
|
|
361 |
).success(
|
362 |
fn=make3d,
|
363 |
inputs=[mv_images],
|
364 |
-
outputs=[output_model_obj]
|
365 |
)
|
366 |
|
367 |
demo.launch()
|
|
|
19 |
get_zero123plus_input_cameras,
|
20 |
get_circular_camera_poses,
|
21 |
)
|
22 |
+
from src.utils.mesh_util import save_obj, save_glb
|
23 |
from src.utils.infer_util import remove_background, resize_foreground, images_to_video
|
24 |
|
25 |
import tempfile
|
|
|
190 |
mesh_basename = os.path.basename(mesh_fpath).split('.')[0]
|
191 |
mesh_dirname = os.path.dirname(mesh_fpath)
|
192 |
video_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.mp4")
|
193 |
+
mesh_glb_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.glb")
|
194 |
|
195 |
with torch.no_grad():
|
196 |
# get triplane
|
|
|
238 |
faces = faces[:, [2, 1, 0]]
|
239 |
|
240 |
save_obj(vertices, faces, vertex_colors, mesh_fpath)
|
241 |
+
save_glb(vertices, faces, vertex_colors, mesh_glb_fpath)
|
242 |
|
243 |
print(f"Mesh saved to {mesh_fpath}")
|
244 |
|
245 |
+
return mesh_fpath, mesh_glb_fpath
|
246 |
|
247 |
|
248 |
_HEADER_ = '''
|
|
|
338 |
# )
|
339 |
|
340 |
with gr.Row():
|
341 |
+
with gr.Tab("OBJ"):
|
342 |
+
output_model_obj = gr.Model3D(
|
343 |
+
label="Output Model (OBJ Format)",
|
344 |
+
width=768,
|
345 |
+
interactive=False,
|
346 |
+
)
|
347 |
+
with gr.Tab("GLB"):
|
348 |
+
output_model_glb = gr.Model3D(
|
349 |
+
label="Output Model (GLB Format)",
|
350 |
+
width=768,
|
351 |
+
interactive=False,
|
352 |
+
)
|
353 |
|
354 |
with gr.Row():
|
355 |
gr.Markdown('''Try a different <b>seed value</b> if the result is unsatisfying (Default: 42).''')
|
|
|
371 |
).success(
|
372 |
fn=make3d,
|
373 |
inputs=[mv_images],
|
374 |
+
outputs=[output_model_obj, output_model_glb]
|
375 |
)
|
376 |
|
377 |
demo.launch()
|
src/utils/mesh_util.py
CHANGED
@@ -15,13 +15,22 @@ import nvdiffrast.torch as dr
|
|
15 |
from PIL import Image
|
16 |
|
17 |
|
18 |
-
def save_obj(pointnp_px3, facenp_fx3, colornp_px3,
|
19 |
mesh = trimesh.Trimesh(
|
20 |
vertices=pointnp_px3,
|
21 |
faces=facenp_fx3,
|
22 |
vertex_colors=colornp_px3,
|
23 |
)
|
24 |
-
mesh.export(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
def save_obj_with_mtl(pointnp_px3, tcoords_px2, facenp_fx3, facetex_fx3, texmap_hxwx3, fname):
|
|
|
15 |
from PIL import Image
|
16 |
|
17 |
|
18 |
+
def save_obj(pointnp_px3, facenp_fx3, colornp_px3, fpath):
|
19 |
mesh = trimesh.Trimesh(
|
20 |
vertices=pointnp_px3,
|
21 |
faces=facenp_fx3,
|
22 |
vertex_colors=colornp_px3,
|
23 |
)
|
24 |
+
mesh.export(fpath, 'obj')
|
25 |
+
|
26 |
+
|
27 |
+
def save_glb(pointnp_px3, facenp_fx3, colornp_px3, fpath):
|
28 |
+
mesh = trimesh.Trimesh(
|
29 |
+
vertices=pointnp_px3,
|
30 |
+
faces=facenp_fx3,
|
31 |
+
vertex_colors=colornp_px3,
|
32 |
+
)
|
33 |
+
mesh.export(fpath, 'glb')
|
34 |
|
35 |
|
36 |
def save_obj_with_mtl(pointnp_px3, tcoords_px2, facenp_fx3, facetex_fx3, texmap_hxwx3, fname):
|