1717
1818from dataclasses import dataclass , field
1919from pathlib import Path
20- from typing import Type
20+ from typing import Optional , Type
2121
2222import imageio
2323import numpy as np
24+ import open3d as o3d
2425import torch
2526
2627from nerfstudio .cameras .cameras import Cameras , CameraType
@@ -42,6 +43,9 @@ class BlenderDataParserConfig(DataParserConfig):
4243 """How much to scale the camera origins by."""
4344 alpha_color : str = "white"
4445 """alpha color of background"""
46+ ply_path : Optional [Path ] = None
47+ """Path to PLY file to load 3D points from, defined relative to the dataset directory. This is helpful for
48+ Gaussian splatting and generally unused otherwise. If `None`, points are initialized randomly."""
4549
4650
4751@dataclass
@@ -94,12 +98,29 @@ def _generate_dataparser_outputs(self, split="train"):
9498 camera_type = CameraType .PERSPECTIVE ,
9599 )
96100
101+ metadata = {}
102+ if self .config .ply_path is not None :
103+ metadata .update (self ._load_3D_points (self .config .data / self .config .ply_path ))
104+
97105 dataparser_outputs = DataparserOutputs (
98106 image_filenames = image_filenames ,
99107 cameras = cameras ,
100108 alpha_color = self .alpha_color_tensor ,
101109 scene_box = scene_box ,
102110 dataparser_scale = self .scale_factor ,
111+ metadata = metadata ,
103112 )
104113
105114 return dataparser_outputs
115+
116+ def _load_3D_points (self , ply_file_path : Path ):
117+ pcd = o3d .io .read_point_cloud (str (ply_file_path ))
118+
119+ points3D = torch .from_numpy (np .asarray (pcd .points , dtype = np .float32 ) * self .config .scale_factor )
120+ points3D_rgb = torch .from_numpy ((np .asarray (pcd .colors ) * 255 ).astype (np .uint8 ))
121+
122+ out = {
123+ "points3D_xyz" : points3D ,
124+ "points3D_rgb" : points3D_rgb ,
125+ }
126+ return out
0 commit comments