-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(read wavefront obj file)
- Loading branch information
Showing
20 changed files
with
213 additions
and
124 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use ray_tracer_lib::camera::Camera; | ||
use ray_tracer_lib::colors::Color; | ||
use ray_tracer_lib::core::math::PI; | ||
use ray_tracer_lib::core::transform::{rotation_x, rotation_y, rotation_z, view_transform}; | ||
use ray_tracer_lib::core::tuple::{point, vector}; | ||
use ray_tracer_lib::lights::point_light::PointLight; | ||
use ray_tracer_lib::obj_reader::ObjReader; | ||
use ray_tracer_lib::object::Object; | ||
use ray_tracer_lib::world::World; | ||
use crate::scene::Scene; | ||
|
||
pub struct TeaPotScene {} | ||
|
||
impl Scene for TeaPotScene { | ||
fn get_world(&self) -> World { | ||
println!("{}", env::current_dir().unwrap().display()); | ||
let file_path = r"./obj/teapot-low.obj"; | ||
let file = File::open(file_path).unwrap(); | ||
|
||
let mut obj_reader = ObjReader::new(file); | ||
obj_reader.read(); | ||
|
||
let teapot = obj_reader.models; | ||
let teapot_model= teapot.get("Teapot001").unwrap(); | ||
let mut obj_teapot = Object::new_triangle(teapot_model.clone()); | ||
obj_teapot.set_transformation(&rotation_y(-PI/4.0) * &(&rotation_x(-PI/2.0)*&rotation_z(PI/2.0))); | ||
let mut world = World::new(); | ||
world.objects.push(obj_teapot); | ||
let lights = vec!(PointLight::new(point(-100.0, 100.0, -100.0), Color::new(1.0, 1.0, 1.0))); | ||
world.set_lights(lights); | ||
world | ||
} | ||
|
||
fn get_camera(&self, h_size: usize, v_size: usize) -> Camera { | ||
let mut camera = Camera::new(h_size, v_size, PI / 3.0); | ||
camera.set_transform(view_transform(point(-25.0, 25.0, -50.0), | ||
point(0.0, 1.0, 0.0), | ||
vector(0.0, 1.0, 0.0))); | ||
camera | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ pub mod tests; | |
pub mod world; | ||
pub mod canvas; | ||
pub mod camera; | ||
mod obj_reader; | ||
pub mod obj_reader; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,62 @@ | ||
use crate::core::bounds::Bounds; | ||
use crate::core::intersections::Intersections; | ||
use crate::core::math::Float; | ||
use crate::core::matrix::Matrix; | ||
use crate::core::ray::Ray; | ||
use crate::shapes::triangle::Triangle; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TriangleModel { | ||
pub triangles : Vec<Triangle> | ||
pub triangles : Vec<Triangle>, | ||
pub bounds : Bounds, | ||
} | ||
|
||
impl TriangleModel { | ||
pub fn new(triangles : Vec<Triangle>) -> Self { | ||
Self {triangles} | ||
let mut model = Self {triangles, bounds: Bounds::new()}; | ||
model.init(); | ||
model | ||
} | ||
|
||
pub(crate) fn set_transformation(&self, transformation: Matrix<4>) { | ||
todo!() | ||
pub(crate) fn set_transformation(& mut self, transformation: Matrix<4>) { | ||
let transformed_triangles = self.triangles.iter().map( |t| Triangle::new( | ||
&transformation * &t.p1, | ||
&transformation * &t.p2, | ||
&transformation * &t.p3 | ||
)).collect(); | ||
self.triangles = transformed_triangles; | ||
self.init(); | ||
} | ||
|
||
pub(crate) fn bounds(&self) -> Bounds { | ||
todo!() | ||
self.bounds.clone() | ||
} | ||
|
||
pub(crate) fn intersect(&self, ray: &Ray) -> Intersections { | ||
todo!() | ||
pub(crate) fn intersect(&self, ray: &Ray) -> Vec<(Float, Triangle)> { | ||
if self.bounds.intersect(&ray).is_empty() { | ||
return vec![]; | ||
} | ||
let mut xs = vec![]; | ||
|
||
for triangle in self.triangles.iter() { | ||
let child_xs = triangle.intersect(ray); | ||
for t in child_xs.iter() { | ||
let x = (*t, triangle.clone()); | ||
xs.push(x); | ||
} | ||
} | ||
|
||
xs | ||
} | ||
|
||
fn init(&mut self) { | ||
let mut bounds = Bounds::new(); | ||
|
||
for triangle in self.triangles.iter() { | ||
bounds.add(&triangle.p1); | ||
bounds.add(&triangle.p2); | ||
bounds.add(&triangle.p3); | ||
} | ||
|
||
self.bounds = bounds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.