Skip to main content

Crate model_to_image

Crate model_to_image 

Source
Expand description

§ModelToImage

This library aims to convert a 3d model and spit out an image. This library aims to limit the amount of dependencies used, therefore it uses a software renderer instead of something like OpenGL or DirectX (which would be overkill).

This is an example, and is not completed. It is at a stage where it is usable, however there is a very lacklustre amount of features. So far, I need to implement:

  • Camera movement
  • Shadows
  • Ambient occlusion
  • Optimisations

Here is a sample render:

fish

§Performance

With a software renderer, you may have some concerns about performance. Well, do not fret as under testing of an Intel i7-1165G7 with an SSD and 32GB RAM, here are my results:

Performance chart

This was tested under the release profile using the command cargo run --release and the time command on Git Bash.

§Example

use std::path::PathBuf;
 
fn main() {
    let fish = PathBuf::from("C:\\Users\\thrib\\model_to_image\\src\\fish.glb");
    let mut image = model_to_image::ModelToImageBuilder::new(&fish)
        .with_size((800, 600))
        .with_light_direction([0.0, 0.0, -1.0])
        .with_margin(0.1)
        .build()
        .unwrap();
     
    image.render();
    let image_buffer = image.output();
    image.write_to(Some(&PathBuf::from(output.png")));
    // Writes the image to the path
}

Structs§

ModelToImage
ModelToImageBuilder
Size

Functions§

render