-
-
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 #2167 from hannobraun/color
Add `SetColor` operation
- Loading branch information
Showing
7 changed files
with
78 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
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,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<Color>) -> Self; | ||
} | ||
|
||
impl SetColor for Region { | ||
fn set_color(&self, color: impl Into<Color>) -> Self { | ||
Region::new( | ||
self.exterior().clone(), | ||
self.interiors().into_iter().cloned(), | ||
Some(color.into()), | ||
) | ||
} | ||
} |
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,11 @@ | ||
[package] | ||
name = "color" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[dependencies.cuboid] | ||
path = "../cuboid" | ||
|
||
[dependencies.fj] | ||
path = "../../crates/fj" |
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,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<Solid> { | ||
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) | ||
} |
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,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(()) | ||
} |