4 releases

0.1.3 Aug 27, 2020
0.1.2 Jan 14, 2019
0.1.1 Oct 30, 2017
0.1.0 Jun 21, 2017

#600 in Parser implementations

Download history 824/week @ 2023-12-13 444/week @ 2023-12-20 291/week @ 2023-12-27 1159/week @ 2024-01-03 917/week @ 2024-01-10 1109/week @ 2024-01-17 1055/week @ 2024-01-24 950/week @ 2024-01-31 1456/week @ 2024-02-07 3303/week @ 2024-02-14 4232/week @ 2024-02-21 4767/week @ 2024-02-28 4816/week @ 2024-03-06 5405/week @ 2024-03-13 4361/week @ 2024-03-20 2305/week @ 2024-03-27

17,666 downloads per month
Used in 36 crates (9 directly)

MIT license

84KB
1.5K SLoC

Ply-rs

Documentation | Build Status crates.io

Ply-rs is a small library built to read and write the PLY file format (also Polygon File Format, Standford Triangle Format). The library supports all three subformats: ascii, big endian, and little endian.

It focuses on two main points:

  • An easy and fast start.
  • High performance if you're willing to do some things yourself.

Getting started

Dependency

Add to your Cargo.toml:

[dependencies]
ply-rs = "0.1.3"

Add to your root:

extern crate ply_rs;

fn main() {}

Read a ply file

This is the easiest way to read a ply file:

extern crate ply_rs;
use ply_rs as ply;

/// Demonstrates simplest use case for reading from a file.
fn main() {
    // set up a reader, in this case a file.
    let path = "example_plys/greg_turk_example1_ok_ascii.ply";
    let mut f = std::fs::File::open(path).unwrap();

    // create a parser
    let p = ply::parser::Parser::<ply::ply::DefaultElement>::new();

    // use the parser: read the entire file
    let ply = p.read_ply(&mut f);

    // make sure it did work
    assert!(ply.is_ok());
    let ply = ply.unwrap();

    // proof that data has been read
    println!("Ply header: {:#?}", ply.header);
    println!("Ply data: {:?}", ply.payload);
}

Write ply file

The simplest case of writing a ply file:

extern crate ply_rs;
use ply_rs::ply::{ Ply, DefaultElement };
use ply_rs::writer::{ Writer };

/// Demonstrates simplest use case for reading from a file.
fn main() {
    // set up a target, could also be a file
    let mut buf = Vec::<u8>::new();

    // crete a ply objet
    let mut ply = Ply::<DefaultElement>::new();

    // set up a writer
    let w = Writer::new();
    let written = w.write_ply(&mut buf, &mut ply).unwrap();
    println!("{} bytes written", written);
    println!("buffer size: {}", buf.len());

    // proof that data has been read

    // We can use `from_utf8` since PLY files only contain ascii characters
    let output = String::from_utf8(buf).unwrap();
    println!("Written data:\n{}", output);
}

For more complicated examples, please see the examples.

This implementation is mainly based on these specifications with additions from here.

Dependencies

~0.2–1.7MB
~22K SLoC