Spaces:
Running
on
Zero
Running
on
Zero
xinjie.wang
commited on
Commit
·
b62271e
1
Parent(s):
0c450f5
update
Browse files
asset3d_gen/data/backproject_v2.py
CHANGED
@@ -220,8 +220,7 @@ class TextureBacker:
|
|
220 |
bake_angle_thresh: int = 75,
|
221 |
mask_thresh: float = 0.5,
|
222 |
):
|
223 |
-
|
224 |
-
self.camera = camera
|
225 |
self.camera_params = camera_params
|
226 |
self.renderer = None
|
227 |
self.view_weights = view_weights
|
@@ -235,8 +234,9 @@ class TextureBacker:
|
|
235 |
(2 / 512) * max(self.render_wh[0], self.render_wh[1])
|
236 |
)
|
237 |
|
238 |
-
def _lazy_init_render(self,
|
239 |
if self.renderer is None:
|
|
|
240 |
mv = camera.view_matrix() # (n 4 4) world2cam
|
241 |
p = camera.intrinsics.projection_matrix()
|
242 |
# NOTE: add a negative sign at P[0, 2] as the y axis is flipped in `nvdiffrast` output. # noqa
|
@@ -248,7 +248,7 @@ class TextureBacker:
|
|
248 |
context=dr.RasterizeCudaContext(),
|
249 |
mask_thresh=mask_thresh,
|
250 |
grad_db=False,
|
251 |
-
device=
|
252 |
antialias_mask=True,
|
253 |
)
|
254 |
|
@@ -426,6 +426,7 @@ class TextureBacker:
|
|
426 |
self.vertices = torch.from_numpy(mesh.vertices).to(self.device).float()
|
427 |
self.faces = torch.from_numpy(mesh.faces).to(self.device).to(torch.int)
|
428 |
self.uv_map = torch.from_numpy(mesh.visual.uv).to(self.device).float()
|
|
|
429 |
rendered_depth, masks = self.renderer.render_depth(
|
430 |
self.vertices, self.faces
|
431 |
)
|
@@ -436,7 +437,7 @@ class TextureBacker:
|
|
436 |
view_normals = self.compute_enhanced_viewnormal(
|
437 |
self.renderer.mv_mtx, self.vertices, self.faces
|
438 |
)
|
439 |
-
|
440 |
textures, weighted_cos_maps = [], []
|
441 |
for color, mask, dep, normal, uv, weight in zip(
|
442 |
colors,
|
@@ -463,8 +464,9 @@ class TextureBacker:
|
|
463 |
mesh: trimesh.Trimesh,
|
464 |
output_path: str,
|
465 |
) -> trimesh.Trimesh:
|
466 |
-
self._lazy_init_render(self.
|
467 |
mesh = self.load_mesh(mesh)
|
|
|
468 |
texture_np, mask_np = self.cuda_forward(colors, mesh)
|
469 |
|
470 |
texture_np = self.uv_inpaint(texture_np, mask_np)
|
|
|
220 |
bake_angle_thresh: int = 75,
|
221 |
mask_thresh: float = 0.5,
|
222 |
):
|
223 |
+
|
|
|
224 |
self.camera_params = camera_params
|
225 |
self.renderer = None
|
226 |
self.view_weights = view_weights
|
|
|
234 |
(2 / 512) * max(self.render_wh[0], self.render_wh[1])
|
235 |
)
|
236 |
|
237 |
+
def _lazy_init_render(self, camera_params, mask_thresh):
|
238 |
if self.renderer is None:
|
239 |
+
camera = init_kal_camera(camera_params)
|
240 |
mv = camera.view_matrix() # (n 4 4) world2cam
|
241 |
p = camera.intrinsics.projection_matrix()
|
242 |
# NOTE: add a negative sign at P[0, 2] as the y axis is flipped in `nvdiffrast` output. # noqa
|
|
|
248 |
context=dr.RasterizeCudaContext(),
|
249 |
mask_thresh=mask_thresh,
|
250 |
grad_db=False,
|
251 |
+
device=self.device,
|
252 |
antialias_mask=True,
|
253 |
)
|
254 |
|
|
|
426 |
self.vertices = torch.from_numpy(mesh.vertices).to(self.device).float()
|
427 |
self.faces = torch.from_numpy(mesh.faces).to(self.device).to(torch.int)
|
428 |
self.uv_map = torch.from_numpy(mesh.visual.uv).to(self.device).float()
|
429 |
+
|
430 |
rendered_depth, masks = self.renderer.render_depth(
|
431 |
self.vertices, self.faces
|
432 |
)
|
|
|
437 |
view_normals = self.compute_enhanced_viewnormal(
|
438 |
self.renderer.mv_mtx, self.vertices, self.faces
|
439 |
)
|
440 |
+
|
441 |
textures, weighted_cos_maps = [], []
|
442 |
for color, mask, dep, normal, uv, weight in zip(
|
443 |
colors,
|
|
|
464 |
mesh: trimesh.Trimesh,
|
465 |
output_path: str,
|
466 |
) -> trimesh.Trimesh:
|
467 |
+
self._lazy_init_render(self.camera_params, self.mask_thresh)
|
468 |
mesh = self.load_mesh(mesh)
|
469 |
+
|
470 |
texture_np, mask_np = self.cuda_forward(colors, mesh)
|
471 |
|
472 |
texture_np = self.uv_inpaint(texture_np, mask_np)
|