further tries

This commit is contained in:
Jonathan Flueren 2022-07-15 15:16:26 +02:00
parent 1157b0e22b
commit 99b4d4b457

View file

@ -17,6 +17,9 @@ use material::{Dielectric, Lambertian, Material, Metal};
use ray::Ray;
use rayon::prelude::*;
use std::env;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;
use tobj;
@ -178,7 +181,16 @@ fn from_obj(path: &str) -> HittableList {
material_ground.clone(),
)));
dbg!(path);
/*
if let Ok(lines) = read_lines(path) {
for line in lines {
if let Ok(text) = line {
dbg!(text);
}
}
}*/
let material = Arc::new(Lambertian::new(&Color::new(0.4, 0.2, 0.1)));
let cornell_box = tobj::load_obj(path, &tobj::GPU_LOAD_OPTIONS);
let (models, materials) = cornell_box.expect("Failed to load OBJ file");
@ -195,11 +207,31 @@ fn from_obj(path: &str) -> HittableList {
next_face = end;
}
todo!("find out how to get triangular faces and build world") // https://docs.rs/tobj/3.2.3/tobj/struct.Mesh.html
// todo!("find out how to get triangular faces and build world"); // https://docs.rs/tobj/3.2.3/tobj/struct.Mesh.html
for i in mesh.indices.iter() {
for v in 0..mesh.indices.len() / 3 {
let indexA = mesh.indices[3 * v];
let indexB = mesh.indices[3 * v + 1];
let indexC = mesh.indices[3 * v + 2];
}
world.add(Box::<Triangle>::new(Triangle::new(
Point3::new(
mesh.positions[3 * indexA] as f64,
mesh.positions[3 * indexA + 1] as f64,
mesh.positions[3 * indexA + 2] as f64
),
Point3::new(
mesh.positions[3 * indexB] as f64,
mesh.positions[3 * indexB + 1] as f64,
mesh.positions[3 * indexB + 2] as f64
),
Point3::new(
mesh.positions[3 * indexC] as f64,
mesh.positions[3 * indexC + 1] as f64,
mesh.positions[3 * indexC + 2] as f64
),
material
)));
for v in 0..mesh.positions.len() / 3 {
println!(
@ -212,9 +244,18 @@ fn from_obj(path: &str) -> HittableList {
}
}
let material = Arc::new(Lambertian::new(&Color::new(0.4, 0.2, 0.1)));
return world;
}
// The output is wrapped in a Result to allow matching on errors
// Returns an Iterator to the Reader of the lines of the file.
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where P: AsRef<Path>, {
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}
/*
@ -249,7 +290,7 @@ fn main() {
let dist_to_focus = 17.0;
let aperture = 0.1;
let world = from_obj("obj/Lowpoly_tree_sample.obj");
let world = from_obj("obj/baum.obj");
// World
let world = random_world();