-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1838 from hannobraun/cuboid
Add `cuboid` example model
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
[package] | ||
name = "cuboid" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
anyhow = "1.0.71" | ||
itertools = "0.10.5" | ||
|
||
[dependencies.fj-kernel] | ||
path = "../../crates/fj-kernel" | ||
|
||
[dependencies.fj-math] | ||
path = "../../crates/fj-math" | ||
|
||
[dependencies.fj-window] | ||
path = "../../crates/fj-window" |
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,52 @@ | ||
use fj_kernel::{ | ||
algorithms::sweep::Sweep, | ||
geometry::region::Region, | ||
objects::{Cycle, HalfEdge, Sketch, Solid}, | ||
operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle}, | ||
services::Services, | ||
storage::Handle, | ||
}; | ||
use fj_math::{Point, Vector}; | ||
use itertools::Itertools; | ||
|
||
pub fn cuboid(x: f64, y: f64, z: f64) -> Handle<Solid> { | ||
let mut services = Services::new(); | ||
|
||
let sketch = { | ||
let exterior = { | ||
#[rustfmt::skip] | ||
let rectangle = [ | ||
[-x / 2., -y / 2.], | ||
[ x / 2., -y / 2.], | ||
[ x / 2., y / 2.], | ||
[-x / 2., y / 2.], | ||
]; | ||
|
||
let mut cycle = Cycle::empty(); | ||
|
||
let segments = rectangle | ||
.into_iter() | ||
.map(Point::from) | ||
.circular_tuple_windows(); | ||
|
||
for (start, end) in segments { | ||
let half_edge = | ||
HalfEdge::line_segment([start, end], None, &mut services) | ||
.insert(&mut services); | ||
|
||
cycle = cycle.add_half_edges([half_edge]); | ||
} | ||
|
||
cycle.insert(&mut services) | ||
}; | ||
|
||
let region = Region::new(exterior, Vec::new(), None); | ||
|
||
Sketch::new([region]).insert(&mut services) | ||
}; | ||
|
||
let surface = services.objects.surfaces.xy_plane(); | ||
|
||
let path = Vector::from([0., 0., z]); | ||
(sketch, surface).sweep(path, &mut services) | ||
} |
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,16 @@ | ||
use std::ops::Deref; | ||
|
||
use fj_kernel::algorithms::{approx::Tolerance, triangulate::Triangulate}; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let cuboid = cuboid::cuboid(3., 2., 1.); | ||
|
||
// The tolerance makes no difference for this model, as there aren't any | ||
// curves. | ||
let tolerance = Tolerance::from_scalar(1.)?; | ||
|
||
let mesh = (cuboid.deref(), tolerance).triangulate(); | ||
fj_window::run(mesh, false)?; | ||
|
||
Ok(()) | ||
} |