xinjie.wang commited on
Commit
d7f41a5
·
1 Parent(s): 246589c
Files changed (1) hide show
  1. asset3d_gen/data/backproject_v2.py +9 -8
asset3d_gen/data/backproject_v2.py CHANGED
@@ -266,12 +266,13 @@ class TextureBacker:
266
 
267
  def get_mesh_np_attrs(
268
  self,
 
269
  scale: float = None,
270
  center: np.ndarray = None,
271
  ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
272
- vertices = self.vertices.cpu().numpy()
273
- faces = self.faces.cpu().numpy()
274
- uv_map = self.uv_map.cpu().numpy()
275
  uv_map[:, 1] = 1.0 - uv_map[:, 1]
276
 
277
  if scale is not None:
@@ -400,9 +401,9 @@ class TextureBacker:
400
  return texture_merge, trust_map_merge > 1e-8
401
 
402
  def uv_inpaint(
403
- self, texture: np.ndarray, mask: np.ndarray
404
  ) -> np.ndarray:
405
- vertices, faces, uv_map = self.get_mesh_np_attrs()
406
 
407
  texture, mask = _texture_inpaint_smooth(
408
  texture, mask, vertices, faces, uv_map
@@ -424,7 +425,7 @@ class TextureBacker:
424
  mesh: trimesh.Trimesh,
425
  ) -> trimesh.Trimesh:
426
  self._lazy_init_render(self.camera_params, self.mask_thresh)
427
-
428
  self.vertices = torch.from_numpy(mesh.vertices).to(self.device).float()
429
  self.faces = torch.from_numpy(mesh.faces).to(self.device).to(torch.int)
430
  self.uv_map = torch.from_numpy(mesh.visual.uv).to(self.device).float()
@@ -470,10 +471,10 @@ class TextureBacker:
470
 
471
  texture_np, mask_np = self.cuda_forward(colors, mesh)
472
 
473
- texture_np = self.uv_inpaint(texture_np, mask_np)
474
  texture_np = post_process_texture(texture_np)
475
  vertices, faces, uv_map = self.get_mesh_np_attrs(
476
- self.scale, self.center
477
  )
478
  textured_mesh = save_mesh_with_mtl(
479
  vertices, faces, uv_map, texture_np, output_path
 
266
 
267
  def get_mesh_np_attrs(
268
  self,
269
+ mesh: trimesh.Trimesh,
270
  scale: float = None,
271
  center: np.ndarray = None,
272
  ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
273
+ vertices = mesh.vertices
274
+ faces = mesh.faces
275
+ uv_map = mesh.uv_map
276
  uv_map[:, 1] = 1.0 - uv_map[:, 1]
277
 
278
  if scale is not None:
 
401
  return texture_merge, trust_map_merge > 1e-8
402
 
403
  def uv_inpaint(
404
+ self, mesh: trimesh.Trimesh, texture: np.ndarray, mask: np.ndarray
405
  ) -> np.ndarray:
406
+ vertices, faces, uv_map = self.get_mesh_np_attrs(mesh)
407
 
408
  texture, mask = _texture_inpaint_smooth(
409
  texture, mask, vertices, faces, uv_map
 
425
  mesh: trimesh.Trimesh,
426
  ) -> trimesh.Trimesh:
427
  self._lazy_init_render(self.camera_params, self.mask_thresh)
428
+
429
  self.vertices = torch.from_numpy(mesh.vertices).to(self.device).float()
430
  self.faces = torch.from_numpy(mesh.faces).to(self.device).to(torch.int)
431
  self.uv_map = torch.from_numpy(mesh.visual.uv).to(self.device).float()
 
471
 
472
  texture_np, mask_np = self.cuda_forward(colors, mesh)
473
 
474
+ texture_np = self.uv_inpaint(mesh, texture_np, mask_np)
475
  texture_np = post_process_texture(texture_np)
476
  vertices, faces, uv_map = self.get_mesh_np_attrs(
477
+ mesh, self.scale, self.center
478
  )
479
  textured_mesh = save_mesh_with_mtl(
480
  vertices, faces, uv_map, texture_np, output_path