mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-20 22:40:59 +01:00
41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
use crate::{Cook, ParameterDefinition, PortDefinition};
|
|
|
|
/// A node in the library
|
|
#[derive(Clone, Debug)]
|
|
pub struct NodeDefinition {
|
|
pub id: &'static str,
|
|
pub label: &'static str,
|
|
/// Library path, e.g. `Filters/Blurs`, `Texture generators/Noises`, `Atomic nodes`
|
|
pub category: &'static str,
|
|
pub description: &'static str,
|
|
pub inputs: Vec<PortDefinition>,
|
|
/// The input supplying inherited base parameters, when it differs from port order
|
|
pub primary_input: Option<&'static str>,
|
|
pub outputs: Vec<PortDefinition>,
|
|
pub params: Vec<ParameterDefinition>,
|
|
/// A generator takes its size from the graph, not from an input
|
|
pub generator: bool,
|
|
/// One of the engine's built-in ("atomic") nodes (shown with a grey header)
|
|
pub atomic: bool,
|
|
pub cook: Cook,
|
|
}
|
|
|
|
impl NodeDefinition {
|
|
pub fn param(&self, id: &str) -> Option<&ParameterDefinition> {
|
|
self.params.iter().find(|p| p.id == id)
|
|
}
|
|
|
|
pub fn input_index(&self, id: &str) -> Option<usize> {
|
|
self.inputs.iter().position(|p| p.id == id)
|
|
}
|
|
|
|
pub fn output_index(&self, id: &str) -> Option<usize> {
|
|
self.outputs.iter().position(|p| p.id == id)
|
|
}
|
|
|
|
/// The last path element of the category ("Blurs")
|
|
pub fn group(&self) -> &'static str {
|
|
self.category.rsplit('/').next().unwrap_or(self.category)
|
|
}
|
|
}
|