diff --git a/.gitattributes b/.gitattributes index 24a8e87..a29a031 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.png filter=lfs diff=lfs merge=lfs -text +test_data/stanford_bunny.obj filter=lfs diff=lfs merge=lfs -text diff --git a/src/main.rs b/src/main.rs index eabec2b..d1899c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,6 +67,22 @@ pub fn main() -> Result<(), Box> { image_height as u32, )?; + let model_file_path = + Path::new(env!("CARGO_MANIFEST_DIR")).join("test_data/stanford_bunny.obj"); + println!("Loading object..."); + let model_object = load_obj( + &model_file_path, + Arc::new(PhongMaterial { + colour: ColourRgbF::from_named(NamedColour::Blue), + diffuse_strength: 0.05, + smoothness: 100.0, + specular_strength: 1.0, + }), + )?; + println!("Building BVH..."); + let model_bvh = Box::new(BoundingVolumeHierarchy::build(&model_object)); + println!("Constructing Scene..."); + let scene = Scene { camera_location: Point3::new(-2.0, 1.0, -5.0), objects: vec![ @@ -105,26 +121,17 @@ pub fn main() -> Result<(), Box> { specular_strength: 1.0, }), )), - Box::new(BoundingVolumeHierarchy::build( - &load_obj( - Path::new("/home/matthew/Downloads/bunny.obj"), - Arc::new(ReflectiveMaterial { - colour: ColourRgbF::from_named(NamedColour::Yellow), - diffuse_strength: 0.05, - reflection_strength: 0.9, - }), - ) - .unwrap(), - )), + model_bvh, ], }; + println!("Done."); let mut event_pump = sdl_context.event_pump()?; let (tile_tx, tile_rx) = mpsc::channel(); let mut tile_rx = Some(tile_rx); - let worker_boss = std::thread::spawn(move|| { + let worker_boss = std::thread::spawn(move || { TileIterator::new(image_width as usize, image_height as usize, 32) .map(move |tile| (tile, tile_tx.clone())) .par_bridge() diff --git a/test_data/Readme.md b/test_data/Readme.md new file mode 100644 index 0000000..48001d2 --- /dev/null +++ b/test_data/Readme.md @@ -0,0 +1,2 @@ +Thanks to the Stanford Computer Graphics Laboratory (https://graphics.stanford.edu/data/3Dscanrep/) +for the famous Stanford Bunny model. diff --git a/test_data/stanford_bunny.obj b/test_data/stanford_bunny.obj new file mode 100644 index 0000000..d3667bc --- /dev/null +++ b/test_data/stanford_bunny.obj @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ee71a949c270c53226056a0ad120e8a8dcdba54d36c2420f987dd1cdd4e302f +size 4858404