Add more advanced math nodes (#1383)
Added nodes for the following operations: * Floor * Ceil * Round * Absolute Value * Logarithm * Natural Logarithm * sin * cos * tan
This commit is contained in:
parent
2412a3def6
commit
7558088727
|
|
@ -1758,6 +1758,90 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
|||
properties: node_properties::exponent_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Floor",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::FloorNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Ceil",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::CeilNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Round",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::RoundNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Absolute Value",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::AbsoluteNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Logarithm",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::LogParameterNode<_>"),
|
||||
inputs: vec![
|
||||
DocumentInputType::value("Primary", TaggedValue::F32(0.), true),
|
||||
DocumentInputType::value("Base", TaggedValue::F32(0.), true),
|
||||
],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::log_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Natural Logarithm",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::NaturalLogNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Sine",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::SineNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Cosine",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::CosineNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Tangent",
|
||||
category: "Math",
|
||||
identifier: NodeImplementation::proto("graphene_core::ops::TangentNode"),
|
||||
inputs: vec![DocumentInputType::value("Primary", TaggedValue::F32(0.), true)],
|
||||
outputs: vec![DocumentOutputType::new("Output", FrontendGraphDataType::Number)],
|
||||
properties: node_properties::no_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
name: "Max",
|
||||
category: "Math",
|
||||
|
|
|
|||
|
|
@ -1055,6 +1055,15 @@ pub fn exponent_properties(document_node: &DocumentNode, node_id: NodeId, _conte
|
|||
vec![operand("Power", 1)]
|
||||
}
|
||||
|
||||
pub fn log_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("Base", 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);
|
||||
|
|
|
|||
|
|
@ -83,6 +83,80 @@ where
|
|||
first.pow(second)
|
||||
}
|
||||
|
||||
// Floor
|
||||
pub struct FloorNode;
|
||||
|
||||
#[node_macro::node_fn(FloorNode)]
|
||||
fn floor(input: f32) -> f32 {
|
||||
input.floor()
|
||||
}
|
||||
|
||||
// Ceil
|
||||
pub struct CeilNode;
|
||||
|
||||
#[node_macro::node_fn(CeilNode)]
|
||||
fn ceil(input: f32) -> f32 {
|
||||
input.ceil()
|
||||
}
|
||||
|
||||
// Round
|
||||
pub struct RoundNode;
|
||||
|
||||
#[node_macro::node_fn(RoundNode)]
|
||||
fn round(input: f32) -> f32 {
|
||||
input.round()
|
||||
}
|
||||
|
||||
// Absolute Value
|
||||
pub struct AbsoluteNode;
|
||||
|
||||
#[node_macro::node_fn(AbsoluteNode)]
|
||||
fn abs(input: f32) -> f32 {
|
||||
input.abs()
|
||||
}
|
||||
|
||||
// Log
|
||||
pub struct LogParameterNode<Second> {
|
||||
second: Second,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(LogParameterNode)]
|
||||
fn ln<U: num_traits::float::Float>(first: U, second: U) -> U {
|
||||
first.log(second)
|
||||
}
|
||||
|
||||
// Natural Log
|
||||
pub struct NaturalLogNode;
|
||||
|
||||
#[node_macro::node_fn(NaturalLogNode)]
|
||||
fn ln(input: f32) -> f32 {
|
||||
input.ln()
|
||||
}
|
||||
|
||||
// Sine
|
||||
pub struct SineNode;
|
||||
|
||||
#[node_macro::node_fn(SineNode)]
|
||||
fn ln(input: f32) -> f32 {
|
||||
input.sin()
|
||||
}
|
||||
|
||||
// Cos
|
||||
pub struct CosineNode;
|
||||
|
||||
#[node_macro::node_fn(CosineNode)]
|
||||
fn ln(input: f32) -> f32 {
|
||||
input.cos()
|
||||
}
|
||||
|
||||
// Tan
|
||||
pub struct TangentNode;
|
||||
|
||||
#[node_macro::node_fn(TangentNode)]
|
||||
fn ln(input: f32) -> f32 {
|
||||
input.tan()
|
||||
}
|
||||
|
||||
// Minimum
|
||||
pub struct MinParameterNode<Second> {
|
||||
second: Second,
|
||||
|
|
|
|||
|
|
@ -227,6 +227,15 @@ 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::FloorNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::CeilNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::RoundNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::AbsoluteNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::LogParameterNode<_>, input: f32, params: [f32]),
|
||||
register_node!(graphene_core::ops::NaturalLogNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::SineNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::CosineNode, input: f32, params: []),
|
||||
register_node!(graphene_core::ops::TangentNode, input: f32, params: []),
|
||||
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]),
|
||||
|
|
|
|||
Loading…
Reference in New Issue