nksr-wrapper / examples /quickstart.py
bdck's picture
Upload examples/quickstart.py
eb5ca20 verified
"""
Quick-start example — reconstruct a mesh from a PLY point cloud.
Prerequisites
-------------
pip install nksr-wrapper
Or, from the repo root:
pip install -e .
"""
from pathlib import Path
from nksr_wrapper import NKSRMeshReconstructor, load_point_cloud, save_mesh
# ------------------------------------------------------------------ #
# 1. Load your point cloud #
# ------------------------------------------------------------------ #
# Replace with your own .ply or .pcd file.
ply_path = Path("assets/my_scan.ply")
points, normals = load_point_cloud(ply_path)
# ------------------------------------------------------------------ #
# 2. Reconstruct #
# ------------------------------------------------------------------ #
# Use the "ks" (kitchen-sink) pretrained model — it generalises to
# objects, indoor scenes, and outdoor LiDAR scans.
recon = NKSRMeshReconstructor(device="cuda:0", config="ks")
mesh = recon.reconstruct(
points=points,
normals=normals, # optional — will estimate if None
detail_level=1.0, # 0.0 = smooth, 1.0 = max detail
mise_iter=1, # 1 or 2 for higher-res mesh
)
# ------------------------------------------------------------------ #
# 3. Save / inspect #
# ------------------------------------------------------------------ #
save_mesh("output_mesh.ply", mesh.vertices, mesh.faces)
# Or use Trimesh / Open3D for visualisation
import trimesh
vis = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces)
vis.show()