#ply #obj #stl #trimesh #dae

rs-read-trimesh

A reader for loading 3D meshes from PLY, STL, and OBJ into Parry Trimesh

3 releases

Uses new Rust 2024

0.1.4 Feb 28, 2025
0.1.3 Feb 28, 2025
0.1.2 Feb 28, 2025
0.1.1 Jan 2, 2025
0.1.0 Dec 21, 2024

#1041 in Parser implementations

Download history 93/week @ 2024-12-19 4/week @ 2024-12-26 139/week @ 2025-01-02 3/week @ 2025-01-09 1/week @ 2025-01-30 3/week @ 2025-02-06 1/week @ 2025-02-13 5/week @ 2025-02-20 407/week @ 2025-02-27 10/week @ 2025-03-06

423 downloads per month
Used in rs-opw-kinematics

MIT license

24KB
335 lines

rs-read-trimesh

GitHub crates.io GitHub Workflow Status crates.io crates.io docs.rs

rs-read-trimesh is a Rust library for loading 3D triangular meshes from files in various 3D formats. The main motivation behind this library is that existing readers do not directly output the format we work with (Parry's TriMesh) and require additional boilerplate code, which would be better implemented as a separate dependency.

Features

The library provides a single function that reads a file into a TriMesh given its file path. It supports .ply, .stl, .obj and .dae (Collada) formats, with built-in robustness to handle the diverse data structures found in .ply files, which may use different data types.

Usage

Here’s an example using the load_trimesh function to load a 3D model and apply a scaling factor:

use rs_read_trimesh::load_trimesh;

fn main() {
    let file_path = "example.ply"; 
    let scale = 0.001; // Suppose the mesh is in mm; we want it in meters.

    match load_trimesh(file_path, scale) {
        Ok(mesh) => {
            println!("Successfully loaded and scaled mesh with {} vertices.", mesh.vertices.len());
        }
        Err(e) => {
            eprintln!("Error loading mesh: {}", e);
        }
    }
}

Scaling

The scale parameter allows you to scale all the vertices of the mesh. Setting scale = 1.0 will result in no scaling. Scaling ply files seems quite a frequent case as they are unit-agnostic.

Limitations

For .dae, only triangle meshes are supported (this format may contain lots of other stuff). If the .dae file contains multiple meshes, they are merged.

Dependencies

The following crates are used to power the functionality of this library:

  • ply-rs-bw: A library for reading and writing PLY files.
  • stl_io: A library for reading and writing STL files.
  • tobj: A library for loading OBJ files.
  • dae-parser: A library for loading Collada (DAE) files.
  • parry3d: Provides 3D geometry processing for physical simulations.

Parry is only used as much here as its mesh data structure is involved.

You do not need to add these dependencies manually to your Cargo.toml. They are automatically resolved by Cargo when you include rs-read-trimesh or any of the mentioned libraries.

License

This project is licensed under the MIT License (see the LICENSE file for details). Some testing material is under Apache v 2.0.

Dependencies

~12MB
~225K SLoC