mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 05:18:19 +00:00
Add more math nodes (#1378)
* Adds Max, Min and Equal Nodes * Add LogToConsoleNode Logs the data given as the input to the browser console and returns it as the output
This commit is contained in:
parent
e820cf48f6
commit
2377240d07
6 changed files with 133 additions and 1 deletions
|
@ -1745,6 +1745,42 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
|||
properties: node_properties::exponent_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Max",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::MaxParameterNode<_>"),
|
||||
inputs: vec![
|
||||
DocumentInputType::value("First", TaggedValue::F32(0.), true),
|
||||
DocumentInputType::value("Second", TaggedValue::F32(0.), true),
|
||||
],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::max_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Min",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::MinParameterNode<_>"),
|
||||
inputs: vec![
|
||||
DocumentInputType::value("First", TaggedValue::F32(0.), true),
|
||||
DocumentInputType::value("Second", TaggedValue::F32(0.), true),
|
||||
],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::min_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Equality",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::EqParameterNode<_>"),
|
||||
inputs: vec![
|
||||
DocumentInputType::value("First", TaggedValue::F32(0.), true),
|
||||
DocumentInputType::value("Second", TaggedValue::F32(0.), true),
|
||||
],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::eq_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Modulo",
|
||||
category: "Math",
|
||||
|
@ -1757,6 +1793,15 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
|||
properties: node_properties::modulo_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Log to Console",
|
||||
category: "Logic",
|
||||
identifier: NodeImplementation::proto("graphene_core::logic::LogToConsoleNode"),
|
||||
inputs: vec![DocumentInputType::value("First", TaggedValue::String("Not Connected to a value yet".into()), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::General)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
(*IMAGINATE_NODE).clone(),
|
||||
DocumentNodeType {
|
||||
name: "Unit Circle Generator",
|
||||
|
|
|
@ -1022,6 +1022,33 @@ pub fn exponent_properties(document_node: &DocumentNode, node_id: NodeId, _conte
|
|||
vec![operand("Power", 1)]
|
||||
}
|
||||
|
||||
pub fn max_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
|
||||
let operand = |name: &str, index| {
|
||||
let widgets = number_widget(document_node, node_id, index, name, NumberInput::default(), true);
|
||||
|
||||
LayoutGroup::Row { widgets }
|
||||
};
|
||||
vec![operand("Maximum", 1)]
|
||||
}
|
||||
|
||||
pub fn min_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
|
||||
let operand = |name: &str, index| {
|
||||
let widgets = number_widget(document_node, node_id, index, name, NumberInput::default(), true);
|
||||
|
||||
LayoutGroup::Row { widgets }
|
||||
};
|
||||
vec![operand("Minimum", 1)]
|
||||
}
|
||||
|
||||
pub fn eq_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
|
||||
let operand = |name: &str, index| {
|
||||
let widgets = number_widget(document_node, node_id, index, name, NumberInput::default(), true);
|
||||
|
||||
LayoutGroup::Row { widgets }
|
||||
};
|
||||
vec![operand("Equality", 1)]
|
||||
}
|
||||
|
||||
pub fn modulo_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
|
||||
let operand = |name: &str, index| {
|
||||
let widgets = number_widget(document_node, node_id, index, name, NumberInput::default(), true);
|
||||
|
|
|
@ -9,6 +9,7 @@ extern crate log;
|
|||
|
||||
pub mod consts;
|
||||
pub mod generic;
|
||||
pub mod logic;
|
||||
pub mod ops;
|
||||
pub mod structural;
|
||||
#[cfg(feature = "std")]
|
||||
|
|
9
node-graph/gcore/src/logic.rs
Normal file
9
node-graph/gcore/src/logic.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use crate::Node;
|
||||
|
||||
pub struct LogToConsoleNode;
|
||||
|
||||
#[node_macro::node_fn(LogToConsoleNode)]
|
||||
fn log_to_console<T: core::fmt::Debug>(value: T) -> T {
|
||||
debug!("{:#?}", value);
|
||||
value
|
||||
}
|
|
@ -83,6 +83,42 @@ where
|
|||
first.pow(second)
|
||||
}
|
||||
|
||||
// Minimum
|
||||
pub struct MinParameterNode<Second> {
|
||||
second: Second,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(MinParameterNode)]
|
||||
fn min<T: core::cmp::PartialOrd>(first: T, second: T) -> T {
|
||||
match first < second {
|
||||
true => first,
|
||||
false => second,
|
||||
}
|
||||
}
|
||||
|
||||
// Maximum
|
||||
pub struct MaxParameterNode<Second> {
|
||||
second: Second,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(MaxParameterNode)]
|
||||
fn max<T: core::cmp::PartialOrd>(first: T, second: T) -> T {
|
||||
match first > second {
|
||||
true => first,
|
||||
false => second,
|
||||
}
|
||||
}
|
||||
|
||||
// Equality
|
||||
pub struct EqParameterNode<Second> {
|
||||
second: Second,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(EqParameterNode)]
|
||||
fn eq<T: core::cmp::PartialEq>(first: T, second: T) -> bool {
|
||||
first == second
|
||||
}
|
||||
|
||||
// Modulo
|
||||
pub struct ModuloParameterNode<Second> {
|
||||
second: Second,
|
||||
|
|
|
@ -227,7 +227,12 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
|
|||
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: f32, params: [f32]),
|
||||
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: &f32, params: [f32]),
|
||||
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: f32, params: [&f32]),
|
||||
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: &f32, params: [&f32]),
|
||||
register_node!(graphene_core::ops::MaxParameterNode<_>, input: u32, params: [u32]),
|
||||
register_node!(graphene_core::ops::MaxParameterNode<_>, input: f32, params: [f32]),
|
||||
register_node!(graphene_core::ops::MinParameterNode<_>, input: u32, params: [u32]),
|
||||
register_node!(graphene_core::ops::MinParameterNode<_>, input: f32, params: [f32]),
|
||||
register_node!(graphene_core::ops::EqParameterNode<_>, input: u32, params: [u32]),
|
||||
register_node!(graphene_core::ops::EqParameterNode<_>, input: f32, params: [f32]),
|
||||
register_node!(graphene_core::ops::ModuloParameterNode<_>, input: u32, params: [u32]),
|
||||
register_node!(graphene_core::ops::ModuloParameterNode<_>, input: &u32, params: [u32]),
|
||||
register_node!(graphene_core::ops::ModuloParameterNode<_>, input: u32, params: [&u32]),
|
||||
|
@ -237,6 +242,15 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
|
|||
register_node!(graphene_core::ops::ModuloParameterNode<_>, input: f32, params: [&f32]),
|
||||
register_node!(graphene_core::ops::ModuloParameterNode<_>, input: &f32, params: [&f32]),
|
||||
register_node!(graphene_core::ops::SomeNode, input: WasmEditorApi, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: bool, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: f32, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: f64, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: u32, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: u64, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: String, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: DVec2, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: VectorData, params: []),
|
||||
register_node!(graphene_core::logic::LogToConsoleNode, input: DAffine2, params: []),
|
||||
async_node!(graphene_core::ops::IntoNode<_, ImageFrame<SRGBA8>>, input: ImageFrame<Color>, output: ImageFrame<SRGBA8>, params: []),
|
||||
async_node!(graphene_core::ops::IntoNode<_, ImageFrame<Color>>, input: ImageFrame<SRGBA8>, output: ImageFrame<Color>, params: []),
|
||||
#[cfg(feature = "gpu")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue