-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
l: add facet object so that we can reder triangles, thus meshes!
- Loading branch information
1 parent
018d301
commit 3f498eb
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,33 @@ | ||
use std::{path::Path, sync::Arc}; | ||
|
||
use geo::{mesh::load_mesh, util::opener, Vec3}; | ||
|
||
use l::*; | ||
|
||
pub fn main() -> opener::Result<()> { | ||
let mesh = load_mesh( | ||
Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("..") | ||
.join("data") | ||
.join("t-rex-skull.stl"), | ||
) | ||
.expect("cannot load t-rex-skull.stl"); | ||
|
||
let scene = Scene::new( | ||
mesh.triangles() | ||
.map(|f| Arc::new(Facet::new(f)) as Arc<dyn Object>) | ||
.collect::<Vec<_>>(), | ||
); | ||
|
||
let camera = Camera::look_at( | ||
Vec3::new(-30.0, -10.0, 10.0), | ||
Vec3::zero(), | ||
Vec3::new(0.0, 0.0, -1.0), | ||
) | ||
.with_perspective_projection(60.0, 1.0, 0.01, 10000.0); | ||
|
||
let paths = render(camera, &scene, &Settings { eps: 0.001 }); | ||
dump_svg("trex.svg", &paths, (1024.0, 1024.0)).expect("cannot save trex.svg"); | ||
|
||
opener::open("trex.svg") | ||
} |
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,38 @@ | ||
use geo::{spatial_index::Shape, triangle, Vec3}; | ||
|
||
use crate::Object; | ||
|
||
#[derive(Debug)] | ||
pub struct Facet { | ||
a: Vec3, | ||
b: Vec3, | ||
c: Vec3, | ||
} | ||
|
||
impl Facet { | ||
pub fn new(triangle: [Vec3; 3]) -> Self { | ||
Self { | ||
a: triangle[0], | ||
b: triangle[1], | ||
c: triangle[2], | ||
} | ||
} | ||
} | ||
|
||
impl Shape for Facet { | ||
type Intersection = f64; | ||
|
||
fn intersection(&self, ray: &geo::ray::Ray) -> Option<Self::Intersection> { | ||
triangle::ray_intersection((self.a, self.b, self.c), ray) | ||
} | ||
|
||
fn bbox(&self) -> geo::Aabb { | ||
triangle::bbox(self.a, self.b, self.c) | ||
} | ||
} | ||
|
||
impl Object for Facet { | ||
fn paths(&self) -> Vec<crate::Polyline> { | ||
vec![vec![self.a, self.b, self.c]] | ||
} | ||
} |
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,3 +1,5 @@ | ||
mod cube; | ||
mod facet; | ||
|
||
pub use cube::Cube; | ||
pub use facet::Facet; |