File size: 1,670 Bytes
eb5ca20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
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()