7 releases (4 stable)

1.0.3 Apr 12, 2024
0.2.0 Apr 21, 2023
0.1.1 Apr 20, 2023
0.1.0 Apr 18, 2023

#649 in Parser implementations

Download history 7/week @ 2024-09-18 8/week @ 2024-09-25

205 downloads per month

MIT license

125KB
1.5K SLoC

picocadrs

Test Status Crates.io Version docs.rs

This is a crate for working with picoCAD project files. It supports de-/serialization of picoCAD projects and some other helpful methods and function.

Example

use std::ffi::OsString;
use picocadrs::assets::{Color, Model, Point3D}; // Point3D required for point macro
use picocadrs::point;

// Loads the file "test.txt" located in the picoCAD project folder as a model.
// This model now can access any part of that project.
// For this example test.txt is a new picoCAD project that has a single plane added without
// modifying it saved under the name "test".
let model = Model::load(OsString::from("test")).unwrap();

println!("Model name: {}", model.header.name);          // "Model name: test"
println!("Amount of meshes: {}", model.meshes.len());   // "Amount of meshes: 1"

let mesh = model.meshes.get(0).unwrap();
println!("Mesh name: {}", mesh.name);           // "Mesh name: plane"
println!("Mesh position: {}", mesh.position);   // "Mesh position: 0,0,0"

let face = mesh.faces.get(0).unwrap();
println!("Face color: {}", face.color.as_i32()); // "Face color: 6"
println!("Double sided: {}", face.double_sided); // "Double sided: true"
println!("No texture: {}", face.no_texture);     // "No texture: false"

print!("\n");

// Of course, you can change these values too.
let mut model = Model::load(OsString::from("test")).unwrap();

model.header.name = "model_name".to_string();
println!("Model name: {}", model.header.name);          // "Model name: model_name"
println!("Amount of meshes: {}", model.meshes.len());   // "Amount of meshes: 1"

let mesh = model.meshes.get_mut(0).unwrap();
mesh.name = "some_plane".to_string();
mesh.position = point!(1.5, -1.0, 2.0);
println!("Mesh name: {}", mesh.name);           // "Mesh name: some_plane"
println!("Mesh position: {}", mesh.position);   // "Mesh position: 1.5,-1,2"

let face = mesh.faces.get_mut(0).unwrap();
face.color = Color::Lavender;
face.double_sided = false;
face.no_texture = true;
println!("Face color: {}", face.color.as_i32()); // "Face color: 13"
println!("Double sided: {}", face.double_sided); // "Double sided: false"
println!("No texture: {}", face.no_texture);     // "No texture: true"

Dependencies

~1–12MB
~79K SLoC