Triangle mesh working

This commit is contained in:
Jonathan Flueren 2022-07-17 02:00:32 +02:00
parent 99b4d4b457
commit 36cf9c10c5
2 changed files with 1322 additions and 34 deletions

File diff suppressed because it is too large Load diff

View file

@ -207,45 +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
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];
let index_a = mesh.indices[3 * v] as usize;
let index_b = mesh.indices[3 * v + 1] as usize;
let index_c = mesh.indices[3 * v + 2] as usize;
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
mesh.positions[3 * index_a] as f64,
mesh.positions[3 * index_a + 1] as f64,
mesh.positions[3 * index_a + 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
mesh.positions[3 * index_b] as f64,
mesh.positions[3 * index_b + 1] as f64,
mesh.positions[3 * index_b + 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
mesh.positions[3 * index_c] as f64,
mesh.positions[3 * index_c + 1] as f64,
mesh.positions[3 * index_c + 2] as f64
),
material
material.clone()
)));
for v in 0..mesh.positions.len() / 3 {
println!(
" v[{}] = ({}, {}, {})",
v,
mesh.positions[3 * v],
mesh.positions[3 * v + 1],
mesh.positions[3 * v + 2]
);
}
}
return world;
}
@ -281,19 +267,19 @@ fn main() {
let image_width = 200;
let image_height = (image_width as f64 / aspect_ratio) as u32;
let samples_per_pixel = 100_u32;
let max_depth = 50;
let max_depth = 5;
let vfov = 40.0;
let lookfrom = Point3::new(10.0, 4.0, 13.0);
let lookat = Point3::new(0.0, 0.0, 0.0);
let vfov = 50.0;
let lookfrom = Point3::new(30.0, 20.0, 30.0);
let lookat = Point3::new(0.0, 15.0, 0.0);
let vup = Vec3::new(0.0, 1.0, 0.0);
let dist_to_focus = 17.0;
let dist_to_focus = 40.0;
let aperture = 0.1;
let world = from_obj("obj/baum.obj");
let world = from_obj("obj/Lowpoly_tree_sample copy.obj");
// World
let world = random_world();
// let world = random_world();
// Camera
let cam = Camera::new(