diff --git a/Cargo.lock b/Cargo.lock index 636b359c3..d5e2b91c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -566,6 +566,14 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color" +version = "0.1.0" +dependencies = [ + "cuboid", + "fj", +] + [[package]] name = "color_quant" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 26b18ba89..62a9cea60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "crates/fj-window", "models/all", + "models/color", "models/cuboid", "models/holes", "models/spacer", diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index 790384d17..15c69c85c 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -43,6 +43,7 @@ pub mod holes; pub mod insert; pub mod join; pub mod merge; +pub mod presentation; pub mod replace; pub mod reverse; pub mod split; diff --git a/crates/fj-core/src/operations/presentation.rs b/crates/fj-core/src/operations/presentation.rs new file mode 100644 index 000000000..b2e9c9211 --- /dev/null +++ b/crates/fj-core/src/operations/presentation.rs @@ -0,0 +1,21 @@ +//! Operations to control the presentation of objects + +use fj_interop::Color; + +use crate::objects::Region; + +/// Set the color of an object +pub trait SetColor { + /// Set the color of the object + fn set_color(&self, color: impl Into) -> Self; +} + +impl SetColor for Region { + fn set_color(&self, color: impl Into) -> Self { + Region::new( + self.exterior().clone(), + self.interiors().into_iter().cloned(), + Some(color.into()), + ) + } +} diff --git a/models/color/Cargo.toml b/models/color/Cargo.toml new file mode 100644 index 000000000..ae3797e85 --- /dev/null +++ b/models/color/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "color" +version = "0.1.0" +edition = "2021" + + +[dependencies.cuboid] +path = "../cuboid" + +[dependencies.fj] +path = "../../crates/fj" diff --git a/models/color/src/lib.rs b/models/color/src/lib.rs new file mode 100644 index 000000000..0bae8de02 --- /dev/null +++ b/models/color/src/lib.rs @@ -0,0 +1,28 @@ +use fj::core::{ + objects::Solid, + operations::{ + insert::Insert, + presentation::SetColor, + update::{UpdateFace, UpdateShell, UpdateSolid}, + }, + services::Services, + storage::Handle, +}; + +pub fn model(services: &mut Services) -> Handle { + let size = 1.; + let cuboid = cuboid::model([size, size, size], services); + + cuboid + .update_shell(cuboid.shells().only(), |shell| { + shell + .update_face(shell.faces().first(), |face| { + face.update_region(|region| { + region.set_color([0., 1., 0.]).insert(services) + }) + .insert(services) + }) + .insert(services) + }) + .insert(services) +} diff --git a/models/color/src/main.rs b/models/color/src/main.rs new file mode 100644 index 000000000..5bfd32f15 --- /dev/null +++ b/models/color/src/main.rs @@ -0,0 +1,8 @@ +use fj::{core::services::Services, handle_model}; + +fn main() -> fj::Result { + let mut services = Services::new(); + let model = color::model(&mut services); + handle_model(model, services)?; + Ok(()) +}