diff options
author | Charlotte Pabst <charlotte.pabst@stud.tu-darmstadt.de> | 2024-03-23 16:54:20 +0100 |
---|---|---|
committer | Charlotte Pabst <charlotte.pabst@stud.tu-darmstadt.de> | 2024-03-24 17:20:06 +0100 |
commit | 4b7532ca0d6ff21d5531febb749b43112d0451e8 (patch) | |
tree | 32e0edf6ea7e8af90c475262da8007c1b4e15ca8 /examples/pyramid.rs | |
parent | 0a922773a37f6a6a0d73ee0c1fa884e90e5f0f1d (diff) | |
download | dcel-4b7532ca0d6ff21d5531febb749b43112d0451e8.tar.xz |
Diffstat (limited to 'examples/pyramid.rs')
-rw-r--r-- | examples/pyramid.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/pyramid.rs b/examples/pyramid.rs new file mode 100644 index 0000000..9614292 --- /dev/null +++ b/examples/pyramid.rs @@ -0,0 +1,37 @@ +use dcel::{Dcel, Kevvlfs, ObjExport}; + +fn main() { + Dcel::new(|mut dcel| { + let body = dcel.new_body(); + + let [d1, d2, d3, d4] = [ + ((8.0f64 / 9.0).sqrt(), 0.0, -1.0 / 3.0), + (-(2.0f64 / 9.0).sqrt(), (2.0f64 / 3.0).sqrt(), -1.0 / 3.0), + (-(2.0f64 / 9.0).sqrt(), -(2.0f64 / 3.0).sqrt(), -1.0 / 3.0), + (0.0, 0.0, 1.0), + ]; + + let Kevvlfs { + vertices: [v1, v2], + loop_: l1, + .. + } = dcel.mevvlfs(*body, [d1, d2]).unwrap(); + let v3 = dcel.mev(*l1, *v2, d3).unwrap().vertex; + let l2 = dcel.melf([*v1, *v3], *l1).unwrap().loop_; + let v4 = dcel.mev(*l2, *v1, d4).unwrap().vertex; + let mut l3 = dcel.melf([*v4, *v2], *l2).unwrap().loop_; + if v3.find_outgoing(*l3, &dcel).is_none() { + l3 = l2; + } + let _l4 = dcel.melf([*v4, *v3], *l3).unwrap().loop_; + + ObjExport::export( + &mut std::fs::File::create("pyramid.obj").unwrap(), + &dcel, + |&(x, y, z)| (x, y, z, None), + |_, _| None, + |_, _| None, + ) + .unwrap(); + }); +} |