mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-19 06:14:03 +08:00
Mesh export (#809)
* start of mesh PR * point cloud export mvp * start of mesh PR * point cloud export mvp * Save out mesh. Poor quality atm * reorganized mesh algorithms and specified CLI * CLI reorg * tsdf algorithm in progress * debugging * tsdf functional but camera distortion params not in * playing with distortion params * TSDF works but texture looks bad * added trimesh * moved to exporter * removed files * saving progress * save texture image * seems to work w/o barycentric * barycentric start * gap between triangles * blocking out diagonal * new barcentric and scaling * meshing working. need to remove extra rows * fixed triangle packing * gitignore changes * removed package * fix Literal import * comments * update .mtl file * poisson mesh with model output normals & resolved some PR comments on git * starting docs. breaking up big function. todo: add xatlas * xatlas and nvdiffrast working * triangle_id * progress on expensive texture coordinates method * pytorch meshing works * removing nvdiffrast * remove trimesh * cleanup * few changes * pred normals by default and add minimum additions to viewer * fix cli in viewer * add xatlas as dependency * make point cloud more dense * reverted viewer changes * turn off normals by default * fix docs * finished todos on github * remove xatlas * xatlas * black Co-authored-by: Matt Tancik <tancik@berkeley.edu>
This commit is contained in:
1 parent
d9395f2576
commit
1052fccec2
15 files changed
+1526
-166
No files matched your search
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
Script to texture an existing mesh file.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import tyro
|
||||
from rich.console import Console
|
||||
from typing_extensions import Literal
|
||||
|
||||
from nerfstudio.exporter import texture_utils
|
||||
from nerfstudio.exporter.exporter_utils import get_mesh_from_filename
|
||||
from nerfstudio.utils.eval_utils import eval_setup
|
||||
|
||||
CONSOLE = Console(width=120)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TextureMesh:
|
||||
"""
|
||||
Export a textured mesh with color computed from the NeRF.
|
||||
"""
|
||||
|
||||
load_config: Path
|
||||
"""Path to the config YAML file."""
|
||||
output_dir: Path
|
||||
"""Path to the output directory."""
|
||||
input_mesh_filename: Path
|
||||
"""Mesh filename to texture."""
|
||||
px_per_uv_triangle: int = 4
|
||||
"""Number of pixels per UV square."""
|
||||
unwrap_method: Literal["xatlas", "custom"] = "xatlas"
|
||||
"""The method to use for unwrapping the mesh."""
|
||||
num_pixels_per_side: int = 2048
|
||||
"""If using xatlas for unwrapping, the pixels per side of the texture image."""
|
||||
target_num_faces: Optional[int] = 50000
|
||||
"""Target number of faces for the mesh to texture."""
|
||||
|
||||
def main(self) -> None:
|
||||
"""Export textured mesh"""
|
||||
# pylint: disable=too-many-statements
|
||||
|
||||
if not self.output_dir.exists():
|
||||
self.output_dir.mkdir(parents=True)
|
||||
|
||||
# load the Mesh
|
||||
mesh = get_mesh_from_filename(str(self.input_mesh_filename), target_num_faces=self.target_num_faces)
|
||||
|
||||
# load the Pipeline
|
||||
_, pipeline, _ = eval_setup(self.load_config, test_mode="inference")
|
||||
|
||||
# texture the mesh with NeRF and export to a mesh.obj file
|
||||
# and a material and texture file
|
||||
texture_utils.export_textured_mesh(
|
||||
mesh,
|
||||
pipeline,
|
||||
self.px_per_uv_triangle,
|
||||
self.output_dir,
|
||||
unwrap_method=self.unwrap_method,
|
||||
num_pixels_per_side=self.num_pixels_per_side,
|
||||
)
|
||||
|
||||
|
||||
def entrypoint():
|
||||
"""Entrypoint for use with pyproject scripts."""
|
||||
tyro.extras.set_accent_color("bright_yellow")
|
||||
tyro.cli(tyro.conf.FlagConversionOff[TextureMesh]).main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
entrypoint()
|
||||
|
||||
# For sphinx docs
|
||||
get_parser_fn = lambda: tyro.extras.get_parser(TextureMesh) # noqa
|
||||
Reference in new issue
Block a user