Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make improvements to example models #2135

Merged
merged 15 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}