First mesh render
This commit is contained in:
parent
36cf9c10c5
commit
e09b0a9e1d
1 changed files with 16 additions and 10 deletions
26
src/main.rs
26
src/main.rs
|
@ -171,7 +171,6 @@ fn random_world() -> HittableList {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_obj(path: &str) -> HittableList {
|
fn from_obj(path: &str) -> HittableList {
|
||||||
|
|
||||||
let mut world = HittableList::new();
|
let mut world = HittableList::new();
|
||||||
|
|
||||||
let material_ground = Arc::new(Lambertian::new(&Color::new(0.05, 0.05, 0.05)));
|
let material_ground = Arc::new(Lambertian::new(&Color::new(0.05, 0.05, 0.05)));
|
||||||
|
@ -216,30 +215,31 @@ fn from_obj(path: &str) -> HittableList {
|
||||||
Point3::new(
|
Point3::new(
|
||||||
mesh.positions[3 * index_a] as f64,
|
mesh.positions[3 * index_a] as f64,
|
||||||
mesh.positions[3 * index_a + 1] as f64,
|
mesh.positions[3 * index_a + 1] as f64,
|
||||||
mesh.positions[3 * index_a + 2] as f64
|
mesh.positions[3 * index_a + 2] as f64,
|
||||||
),
|
),
|
||||||
Point3::new(
|
Point3::new(
|
||||||
mesh.positions[3 * index_b] as f64,
|
mesh.positions[3 * index_b] as f64,
|
||||||
mesh.positions[3 * index_b + 1] as f64,
|
mesh.positions[3 * index_b + 1] as f64,
|
||||||
mesh.positions[3 * index_b + 2] as f64
|
mesh.positions[3 * index_b + 2] as f64,
|
||||||
),
|
),
|
||||||
Point3::new(
|
Point3::new(
|
||||||
mesh.positions[3 * index_c] as f64,
|
mesh.positions[3 * index_c] as f64,
|
||||||
mesh.positions[3 * index_c + 1] as f64,
|
mesh.positions[3 * index_c + 1] as f64,
|
||||||
mesh.positions[3 * index_c + 2] as f64
|
mesh.positions[3 * index_c + 2] as f64,
|
||||||
),
|
),
|
||||||
material.clone()
|
material.clone(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return world;
|
return world;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The output is wrapped in a Result to allow matching on errors
|
// The output is wrapped in a Result to allow matching on errors
|
||||||
// Returns an Iterator to the Reader of the lines of the file.
|
// 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>>>
|
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
||||||
where P: AsRef<Path>, {
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
let file = File::open(filename)?;
|
let file = File::open(filename)?;
|
||||||
Ok(io::BufReader::new(file).lines())
|
Ok(io::BufReader::new(file).lines())
|
||||||
}
|
}
|
||||||
|
@ -264,10 +264,10 @@ fn main() {
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
let aspect_ratio = 16.0 / 9.0;
|
let aspect_ratio = 16.0 / 9.0;
|
||||||
let image_width = 200;
|
let image_width = 600;
|
||||||
let image_height = (image_width as f64 / aspect_ratio) as u32;
|
let image_height = (image_width as f64 / aspect_ratio) as u32;
|
||||||
let samples_per_pixel = 100_u32;
|
let samples_per_pixel = 50_u32;
|
||||||
let max_depth = 5;
|
let max_depth = 50;
|
||||||
|
|
||||||
let vfov = 50.0;
|
let vfov = 50.0;
|
||||||
let lookfrom = Point3::new(30.0, 20.0, 30.0);
|
let lookfrom = Point3::new(30.0, 20.0, 30.0);
|
||||||
|
@ -276,6 +276,12 @@ fn main() {
|
||||||
let dist_to_focus = 40.0;
|
let dist_to_focus = 40.0;
|
||||||
let aperture = 0.1;
|
let aperture = 0.1;
|
||||||
|
|
||||||
|
// limit rayon multithreading thread count
|
||||||
|
let thread_count = 4; // if 0, for each logical cpu core a thread wil be created
|
||||||
|
if thread_count > 0 {
|
||||||
|
env::set_var("RAYON_NUM_THREADS", "4");
|
||||||
|
}
|
||||||
|
|
||||||
let world = from_obj("obj/Lowpoly_tree_sample copy.obj");
|
let world = from_obj("obj/Lowpoly_tree_sample copy.obj");
|
||||||
|
|
||||||
// World
|
// World
|
||||||
|
|
Loading…
Reference in a new issue