write_ply/
write_ply.rs

1//! This example generates a PLY file containing 3 hardcoded Gaussians.
2//!
3//! Run with:
4//!
5//! ```sh
6//! cargo run --example write_ply -- "path/to/output.ply"
7//! ```
8
9use glam::*;
10use wgpu_3dgs_core::{self as gs, WriteIterGaussian};
11
12fn main() {
13    let model_path = std::env::args()
14        .nth(1)
15        .unwrap_or_else(|| "target/output.ply".to_string());
16
17    let gaussians = [
18        gs::Gaussian {
19            rot: Quat::from_axis_angle((Vec3::X + Vec3::Y / 2.0 + Vec3::Z).normalize(), 0.5),
20            pos: Vec3::ZERO,
21            scale: Vec3::new(0.5, 1.0, 0.75),
22            color: U8Vec4::new(255, 0, 0, 255),
23            sh: [Vec3::ZERO; 15],
24        },
25        gs::Gaussian {
26            rot: Quat::from_axis_angle((Vec3::X + Vec3::Z / 3.0).normalize(), 0.3),
27            pos: Vec3::new(0.0, 8.0, 4.0),
28            scale: Vec3::new(1.0, 1.9, 0.75),
29            color: U8Vec4::new(0, 255, 0, 255),
30            sh: [Vec3::ZERO; 15],
31        },
32        gs::Gaussian {
33            rot: Quat::from_axis_angle((Vec3::X - Vec3::Z).normalize(), 0.2),
34            pos: Vec3::new(4.0, 0.0, 6.0),
35            scale: Vec3::new(1.0, 1.1, 0.8),
36            color: U8Vec4::new(0, 0, 255, 255),
37            sh: [Vec3::ZERO; 15],
38        },
39    ];
40
41    let gaussians = gs::PlyGaussians::from(
42        gaussians
43            .iter()
44            .map(gs::Gaussian::to_ply)
45            .collect::<Vec<_>>(),
46    );
47
48    println!("Writing {} gaussians to {}", gaussians.0.len(), model_path);
49
50    gaussians
51        .write_to_file(&model_path)
52        .expect("write PLY file");
53}