pub mod glb;
pub mod ply;
pub mod spz;
pub mod tileset;
pub use ply::{SplatCloud, read_splat_ply};
pub use spz::encode_spz;
pub use tileset::{SplatTilesetOptions, SplatTilesetStats, write_splat_tileset};
#[derive(Debug, Clone)]
pub struct SplatJob {
pub ply: std::path::PathBuf,
pub output: std::path::PathBuf,
pub crop_percentile: f64,
pub scale: f32,
pub coverage_boost_scale: f32,
pub emit_scene_spz: bool,
pub options: SplatTilesetOptions,
}
pub fn run(job: &SplatJob) -> Result<(), crate::TilesError> {
tracing::info!(ply = %job.ply.display(), "reading 3DGS PLY");
let mut cloud = read_splat_ply(&job.ply).map_err(|source| crate::TilesError::ReadPly {
path: job.ply.clone(),
source,
})?;
tracing::info!(
splats = cloud.len(),
sh_degree = cloud.sh_degree,
"splat cloud loaded"
);
if job.crop_percentile > 0.0 {
let before = cloud.len();
cloud = cloud.crop_percentile(job.crop_percentile)?;
tracing::info!(
kept = cloud.len(),
dropped = before - cloud.len(),
percentile = job.crop_percentile,
"cropped far-field splats"
);
}
cloud.rescale(job.scale);
if job.coverage_boost_scale > 0.0 {
cloud.coverage_boost(job.coverage_boost_scale);
tracing::info!(boost = job.coverage_boost_scale, "applied coverage boost");
}
let options = &job.options;
let stats = write_splat_tileset(&cloud, &job.output, options)?;
tracing::info!(
output = %job.output.display(),
tiles = stats.tiles,
splats = stats.splats,
max_depth = stats.max_depth,
"3D Tiles tileset written"
);
if job.emit_scene_spz {
let scene = job.output.join("scene.spz");
let mut centered = cloud.clone();
if let Some((min, max)) = cloud.bounds() {
let center = [
(min[0] + max[0]) / 2.0,
(min[1] + max[1]) / 2.0,
(min[2] + max[2]) / 2.0,
];
for position in &mut centered.positions {
position[0] -= center[0];
position[1] -= center[1];
position[2] -= center[2];
}
}
crate::fsio::write_file(&scene, encode_spz(¢ered, options.antialiased)?)?;
tracing::info!(path = %scene.display(), "standalone scene.spz written");
}
Ok(())
}