Convert a generated asset to a glb file. Args: app_rep (Union[Strivec, Gaussian]): Appearance representation. mesh (MeshExtractResult): Extracted mesh. simplify (float): Ratio of faces to remove in simplification. fill_holes (bool): Whether to fill holes in
(
app_rep: Union[Strivec, Gaussian],
mesh: MeshExtractResult,
simplify: float = 0.95,
fill_holes: bool = True,
fill_holes_max_size: float = 0.04,
texture_size: int = 1024,
debug: bool = False,
verbose: bool = True,
)
| 397 | |
| 398 | |
| 399 | def to_glb( |
| 400 | app_rep: Union[Strivec, Gaussian], |
| 401 | mesh: MeshExtractResult, |
| 402 | simplify: float = 0.95, |
| 403 | fill_holes: bool = True, |
| 404 | fill_holes_max_size: float = 0.04, |
| 405 | texture_size: int = 1024, |
| 406 | debug: bool = False, |
| 407 | verbose: bool = True, |
| 408 | ) -> trimesh.Trimesh: |
| 409 | """ |
| 410 | Convert a generated asset to a glb file. |
| 411 | |
| 412 | Args: |
| 413 | app_rep (Union[Strivec, Gaussian]): Appearance representation. |
| 414 | mesh (MeshExtractResult): Extracted mesh. |
| 415 | simplify (float): Ratio of faces to remove in simplification. |
| 416 | fill_holes (bool): Whether to fill holes in the mesh. |
| 417 | fill_holes_max_size (float): Maximum area of a hole to fill. |
| 418 | texture_size (int): Size of the texture. |
| 419 | debug (bool): Whether to print debug information. |
| 420 | verbose (bool): Whether to print progress. |
| 421 | """ |
| 422 | vertices = mesh.vertices.cpu().numpy() |
| 423 | faces = mesh.faces.cpu().numpy() |
| 424 | |
| 425 | # mesh postprocess |
| 426 | vertices, faces = postprocess_mesh( |
| 427 | vertices, faces, |
| 428 | simplify=simplify > 0, |
| 429 | simplify_ratio=simplify, |
| 430 | fill_holes=fill_holes, |
| 431 | fill_holes_max_hole_size=fill_holes_max_size, |
| 432 | fill_holes_max_hole_nbe=int(250 * np.sqrt(1-simplify)), |
| 433 | fill_holes_resolution=1024, |
| 434 | fill_holes_num_views=1000, |
| 435 | debug=debug, |
| 436 | verbose=verbose, |
| 437 | ) |
| 438 | |
| 439 | # parametrize mesh |
| 440 | vertices, faces, uvs = parametrize_mesh(vertices, faces) |
| 441 | |
| 442 | # bake texture |
| 443 | observations, extrinsics, intrinsics = render_multiview(app_rep, resolution=1024, nviews=100) |
| 444 | masks = [np.any(observation > 0, axis=-1) for observation in observations] |
| 445 | extrinsics = [extrinsics[i].cpu().numpy() for i in range(len(extrinsics))] |
| 446 | intrinsics = [intrinsics[i].cpu().numpy() for i in range(len(intrinsics))] |
| 447 | texture = bake_texture( |
| 448 | vertices, faces, uvs, |
| 449 | observations, masks, extrinsics, intrinsics, |
| 450 | texture_size=texture_size, mode='opt', |
| 451 | lambda_tv=0.01, |
| 452 | verbose=verbose |
| 453 | ) |
| 454 | texture = Image.fromarray(texture) |
| 455 | |
| 456 | # rotate mesh (from z-up to y-up) |
nothing calls this directly
no test coverage detected