gaussian-splatting/scene/xy_utils.py
2025-05-19 09:10:15 +08:00

21 lines
706 B
Python

from plyfile import PlyData, PlyElement
import numpy as np
def storePly(path, xyz, rgb):
# Define the dtype for the structured array
# RGB should be 0-255
dtype = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'),
('nx', 'f4'), ('ny', 'f4'), ('nz', 'f4'),
('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]
normals = np.zeros_like(xyz)
elements = np.empty(xyz.shape[0], dtype=dtype)
attributes = np.concatenate((xyz, normals, rgb), axis=1)
elements[:] = list(map(tuple, attributes))
# Create the PlyData object and write to file
vertex_element = PlyElement.describe(elements, 'vertex')
ply_data = PlyData([vertex_element])
ply_data.write(path)