Skip to content

Commit

Permalink
Merge pull request #2135 from hannobraun/models
Browse files Browse the repository at this point in the history
Make improvements to example models
  • Loading branch information
hannobraun authored Dec 12, 2023
2 parents 0dc0bce + b422299 commit 2032e02
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions models/all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ path = "../../crates/fj"
[dependencies.cuboid]
path = "../cuboid"

[dependencies.holes]
path = "../holes"

[dependencies.spacer]
path = "../spacer"

Expand Down
8 changes: 6 additions & 2 deletions models/all/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn model(services: &mut Services) -> Handle<Solid> {
let axis = Vector::from([1., 1., 1.]).normalize();
let angle_rad = Scalar::PI / 6.;

let cuboid = cuboid::model(1., 2., 3., services)
let cuboid = cuboid::model([1., 2., 3.], services)
.translate(offset * 1., services)
.rotate(axis * angle_rad * 1., services);
let spacer = spacer::model(2., 1., 1., services)
Expand All @@ -27,13 +27,17 @@ pub fn model(services: &mut Services) -> Handle<Solid> {
let star = star::model(5, 2., 1., 1., services)
.translate(offset * 3., services)
.rotate(axis * angle_rad * 3., services);
let split = split::model(1., 0.5, services)
let split = split::model(1., 0.2, services)
.translate(offset * 4., services)
.rotate(axis * angle_rad * 4., services);
let holes = holes::model(0.5, services)
.translate(offset * 5., services)
.rotate(axis * angle_rad * 5., services);

cuboid
.merge(&spacer)
.merge(&star)
.merge(&split)
.merge(&holes)
.insert(services)
}
11 changes: 8 additions & 3 deletions models/cuboid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ use fj::{
services::Services,
storage::Handle,
},
math::Vector,
math::{Scalar, Vector},
};

pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle<Solid> {
pub fn model(
size: impl Into<Vector<3>>,
services: &mut Services,
) -> Handle<Solid> {
let [x, y, z] = size.into().components;

let sketch = Sketch::empty().add_region(
Region::polygon(
[
Expand All @@ -28,7 +33,7 @@ pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle<Solid> {
);

let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., z]);
let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]);
sketch
.sweep_sketch(surface, path, services)
.insert(services)
Expand Down
2 changes: 1 addition & 1 deletion models/cuboid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fj::{core::services::Services, handle_model};

fn main() -> fj::Result {
let mut services = Services::new();
let model = cuboid::model(3., 2., 1., &mut services);
let model = cuboid::model([3., 2., 1.], &mut services);
handle_model(model, services)?;
Ok(())
}
39 changes: 23 additions & 16 deletions models/holes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
use fj::core::{
objects::Solid,
operations::{holes::AddHole, insert::Insert, update::UpdateSolid},
services::Services,
storage::Handle,
use fj::{
core::{
objects::Solid,
operations::{holes::AddHole, insert::Insert, update::UpdateSolid},
services::Services,
storage::Handle,
},
math::Scalar,
};

pub fn model(services: &mut Services) -> Handle<Solid> {
let cuboid = cuboid::model(1., 1., 1., services);
pub fn model(
radius: impl Into<Scalar>,
services: &mut Services,
) -> Handle<Solid> {
let radius = radius.into();

let shell = cuboid.shells().first();
let bottom_face = shell.faces().first();

let hole_position = [0., 0.];
let hole_radius = 0.25;
let hole_path = [0., 0., 0.5];
let size = radius * 4.;
let cuboid = cuboid::model([size, size, size], services);

cuboid
.update_shell(shell, |shell| {
.update_shell(cuboid.shells().first(), |shell| {
let bottom_face = shell.faces().first();

let hole_position = [0., 0.];
let depth = size / 2.;

shell
.add_blind_hole(
bottom_face,
hole_position,
hole_radius,
hole_path,
radius,
[Scalar::ZERO, Scalar::ZERO, depth],
services,
)
.insert(services)
Expand Down
2 changes: 1 addition & 1 deletion models/holes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fj::{core::services::Services, handle_model};

fn main() -> fj::Result {
let mut services = Services::new();
let model = holes::model(&mut services);
let model = holes::model(0.25, &mut services);
handle_model(model, services)?;
Ok(())
}

0 comments on commit 2032e02

Please sign in to comment.