Crates.io | rendersloth |
lib.rs | rendersloth |
version | 0.2.4 |
source | src |
created_at | 2023-03-14 02:37:35.290151 |
updated_at | 2023-03-15 02:58:10.702277 |
description | A 3D Renderer for the CLI |
homepage | |
repository | https://github.com/ecumene/rust-sloth |
max_upload_size | |
id | 809412 |
size | 41,824 |
Render 3D models in your terminal or app. Sloth is a software rasterizer that turns triangles into charxels (a character + a colour). It does this via a simple triangle-grid intersection method to determine if a triangle is in a character. It then uses a really simple shading scale to determine which character to use based on brightness. Colour is determined by the Vertex color for OBJ and the model color for STL.
cargo add rendersloth
use rendersloth::*;
let mut context = Rasterizer::new(40, 40);
// Convert your OBJ to a simpler format for rendering
let mut meshes: Vec<SimpleMesh> = vec![];
let obj_model = tobj::load_obj("file.obj", &tobj::GPU_LOAD_OPTIONS);
let obj_mesh = obj_model.0;
let obj_materials = obj_model.1.expect("Expected to have materials.");
for model in {
meshes.push(model.mesh.to_simple_mesh_with_materials(&materials));
}
// Scale the camera to the model
context.update(&meshes)?;
let transform = Mat4::IDENTITY;
// Draw the meshes to the context's built-in framebuffer
context.draw_all(transform, meshes)?;
// Print the screen's contents
context.flush()?;
cargo install rendersloth --features build-cli
rendersloth --file-name models/Pikachu.obj
Maxgy – Rustfmt lint donbright – STL model loading added, Rustfmt lint jonathandturner – Crossterm port