pub struct NodeGraph {
pub root: NodeId,
pub dirty: bool,
pub name: String,
/* private fields */
}Expand description
The full SDF node graph owned by the editor.
Fields§
§root: NodeIdThe node whose output is the final body SDF.
dirty: boolWhether the graph has unsaved changes.
name: StringHuman-readable name of this graph.
Implementations§
Source§impl NodeGraph
impl NodeGraph
pub fn new(name: impl Into<String>) -> Self
Sourcepub fn add_primitive(&mut self, kind: PrimitiveKind) -> NodeId
pub fn add_primitive(&mut self, kind: PrimitiveKind) -> NodeId
Add a primitive node and return its ID.
Sourcepub fn add_combinator(&mut self, kind: CombinatorKind) -> NodeId
pub fn add_combinator(&mut self, kind: CombinatorKind) -> NodeId
Add a combinator node and return its ID.
Sourcepub fn remove_node(&mut self, id: NodeId) -> Option<SdfNode>
pub fn remove_node(&mut self, id: NodeId) -> Option<SdfNode>
Remove a node and all connections that reference it.
pub fn node_count(&self) -> usize
Sourcepub fn connect(
&mut self,
from: NodeId,
to: NodeId,
port: PortId,
) -> Result<(), String>
pub fn connect( &mut self, from: NodeId, to: NodeId, port: PortId, ) -> Result<(), String>
Connect from’s output to to’s input port. Replaces any
existing connection to the same (to, port) pair.
Sourcepub fn disconnect(&mut self, to: NodeId, port: PortId)
pub fn disconnect(&mut self, to: NodeId, port: PortId)
Disconnect all connections to (to, port).
pub fn connections(&self) -> &[Connection]
Sourcepub fn input_of(&self, to: NodeId, port: PortId) -> Option<NodeId>
pub fn input_of(&self, to: NodeId, port: PortId) -> Option<NodeId>
Find which node feeds input port of to.
Sourcepub fn topo_sort(&self) -> Vec<NodeId>
pub fn topo_sort(&self) -> Vec<NodeId>
Return nodes in evaluation order (leaves first, root last).
Sourcepub fn evaluate_at(
&self,
node: NodeId,
p: Vec3,
cache: &mut HashMap<NodeId, f32>,
) -> f32
pub fn evaluate_at( &self, node: NodeId, p: Vec3, cache: &mut HashMap<NodeId, f32>, ) -> f32
Recursively evaluate the SDF tree rooted at node at world point p.
Sourcepub fn gradient(&self, p: Vec3) -> Vec3
pub fn gradient(&self, p: Vec3) -> Vec3
Numerical gradient of the SDF at p (approximated with finite differences).
Sourcepub fn compile_glsl(&self) -> String
pub fn compile_glsl(&self) -> String
Compile the graph to a GLSL float sdf_body(vec3 p) function body.
Sourcepub fn auto_layout(&mut self)
pub fn auto_layout(&mut self)
Assign canvas positions to all nodes using a simple layered layout.
pub fn stats(&self) -> NodeGraphStats
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NodeGraph
impl RefUnwindSafe for NodeGraph
impl Send for NodeGraph
impl Sync for NodeGraph
impl Unpin for NodeGraph
impl UnsafeUnpin for NodeGraph
impl UnwindSafe for NodeGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.