algorithm to cast rays and build an image based on result

This commit is contained in:
CDaut 2023-11-18 01:44:04 +01:00
parent 11ceb6ebc7
commit 6cbd93aad0
7 changed files with 159 additions and 30 deletions

View file

@ -2,31 +2,50 @@ mod renderer;
mod geometry;
use std::string::String;
use std::sync::{Arc, Mutex};
use clap::{Parser};
use easy_gltf::Scene;
use image::{DynamicImage};
use crate::renderer::render;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
pub struct Args {
gltf_file_path: String,
/// which scene to use in the gltf file
#[arg(short, long)]
#[arg(long)]
scene_index: usize,
/// which camera to render from
#[arg(short, long)]
#[arg(long)]
camera_index: usize,
/// image width
#[arg(long)]
width: usize,
/// image height
#[arg(long)]
height: usize,
}
fn main() {
//parse clargs
let args = Args::parse();
let args: Args = Args::parse();
//load gltf scene
let scenes: &Vec<Scene> = &easy_gltf::load(
&args.gltf_file_path)
.expect(&*format!("Failed to load glTF file {}", &args.gltf_file_path));
render(scenes, args.scene_index, args.camera_index)
//build an image
let output_image: Arc<Mutex<DynamicImage>> = Arc::new(Mutex::new(DynamicImage::new_rgba8(
args.width as u32, args.height as u32,
)));
render(scenes, &args, &output_image);
match output_image.lock() {
Ok(image) => {
image.save("result_image.png").expect("Unable to save image!");
}
Err(_) => { panic!("Error aquiring lock on image while saving!") }
};
}