| 28 | |
| 29 | |
| 30 | def write_ply( |
| 31 | path: Path, |
| 32 | xyz: Float[np.ndarray, "point 3"], |
| 33 | rgb: Float[np.ndarray, "point 3"], |
| 34 | ) -> None: |
| 35 | # Adapted from https://github.com/graphdeco-inria/gaussian-splatting/blob/2eee0e26d2d5fd00ec462df47752223952f6bf4e/scene/dataset_readers.py#L115 |
| 36 | dtype = [ |
| 37 | ("x", "f4"), |
| 38 | ("y", "f4"), |
| 39 | ("z", "f4"), |
| 40 | ("nx", "f4"), |
| 41 | ("ny", "f4"), |
| 42 | ("nz", "f4"), |
| 43 | ("red", "u1"), |
| 44 | ("green", "u1"), |
| 45 | ("blue", "u1"), |
| 46 | ] |
| 47 | normals = np.zeros_like(xyz) |
| 48 | elements = np.empty(xyz.shape[0], dtype=dtype) |
| 49 | attributes = np.concatenate((xyz, normals, rgb * 255), axis=1) |
| 50 | elements[:] = list(map(tuple, attributes)) |
| 51 | vertex_element = PlyElement.describe(elements, "vertex") |
| 52 | ply_data = PlyData([vertex_element]) |
| 53 | ply_data.write(path) |
| 54 | |
| 55 | |
| 56 | def export_to_colmap( |