Spaces:
mashroo
/
Runtime error

YoussefAnso commited on
Commit
6ded434
·
1 Parent(s): bb9cdff

Refactor mesh export process in inference.py to directly save as GLB format, removing intermediate OBJ conversion steps. Update return value to reflect new output format.

Browse files
Files changed (1) hide show
  1. inference.py +19 -8
inference.py CHANGED
@@ -73,16 +73,27 @@ def generate3d(model, rgb, ccm, device):
73
 
74
  start_time = time.time()
75
  with torch.no_grad():
76
- # First export to OBJ to get the mesh with textures
77
- mesh_path_obj = tempfile.NamedTemporaryFile(suffix=f"", delete=False).name
78
- model.export_mesh(data_config, mesh_path_obj, tri_fea_2 = triplane_feature2)
79
-
80
- # Load the OBJ mesh and convert to GLB
81
- mesh = Mesh.load(mesh_path_obj+".obj", bound=0.9, front_dir="+z")
82
  mesh_path_glb = tempfile.NamedTemporaryFile(suffix=f"", delete=False).name
83
- mesh.write(mesh_path_glb+".glb")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  end_time = time.time()
86
  elapsed_time = end_time - start_time
87
  print(f"uv takes {elapsed_time}s")
88
- return mesh_path_glb+".glb"
 
73
 
74
  start_time = time.time()
75
  with torch.no_grad():
 
 
 
 
 
 
76
  mesh_path_glb = tempfile.NamedTemporaryFile(suffix=f"", delete=False).name
77
+ model.export_mesh(data_config, mesh_path_glb, tri_fea_2 = triplane_feature2)
78
+
79
+ # glctx = dr.RasterizeGLContext()#dr.RasterizeCudaContext()
80
+ # mesh_path_obj = tempfile.NamedTemporaryFile(suffix=f"", delete=False).name
81
+ # model.export_mesh_wt_uv(glctx, data_config, mesh_path_obj, "", device, res=(1024,1024), tri_fea_2=triplane_feature2)
82
+
83
+ # mesh = Mesh.load(mesh_path_obj+".obj", bound=0.9, front_dir="+z")
84
+ # mesh_path_glb = tempfile.NamedTemporaryFile(suffix=f"", delete=False).name
85
+ # mesh.write(mesh_path_glb+".glb")
86
+
87
+ # # mesh_obj2 = trimesh.load(mesh_path_glb+".glb", file_type='glb')
88
+ # # mesh_path_obj2 = tempfile.NamedTemporaryFile(suffix=f"", delete=False).name
89
+ # # mesh_obj2.export(mesh_path_obj2+".obj")
90
+
91
+ # with zipfile.ZipFile(mesh_path_obj+'.zip', 'w') as myzip:
92
+ # myzip.write(mesh_path_obj+'.obj', mesh_path_obj.split("/")[-1]+'.obj')
93
+ # myzip.write(mesh_path_obj+'.png', mesh_path_obj.split("/")[-1]+'.png')
94
+ # myzip.write(mesh_path_obj+'.mtl', mesh_path_obj.split("/")[-1]+'.mtl')
95
 
96
  end_time = time.time()
97
  elapsed_time = end_time - start_time
98
  print(f"uv takes {elapsed_time}s")
99
+ return mesh_path_glb+".obj"