Skip to main content

CustomNode

Trait CustomNode 

Source
pub trait CustomNode {
    // Required methods
    fn type_name(&self) -> &'static str;
    fn node_type(&self) -> Type;
    fn setup(&self, builder: &NodeBuilder) -> NodeRef;

    // Provided methods
    fn is_cacheable(&self) -> bool { ... }
    fn update_before_type(&self) -> NodeUpdateType { ... }
    fn update_type(&self) -> NodeUpdateType { ... }
    fn update_after_type(&self) -> NodeUpdateType { ... }
    fn update_before(&self, _renderer: &mut Renderer) -> bool { ... }
    fn update(&self, _renderer: &mut Renderer) -> bool { ... }
    fn update_after(&self, _renderer: &mut Renderer) -> bool { ... }
}
Expand description

A node type defined outside the crate: the port of class MyNode extends Node with a setup( builder ) override, the shape every addon in examples/jsm/tsl/ has.

setup composes; it never emits. It returns a graph of the existing Node variants, and the builder builds that graph in its place. It cannot write a WGSL statement of its own, declare a binding, or change how a variant is generated. Three’s addons never override generate either: they override setup (and updateBefore, which is #162). A node that needs a statement shape nothing can compose into belongs in the crate as a variant, where the exhaustive match in the builder and the dump gates see it (#155 decision 2).

The builder calls setup once per build, the first time it reaches the node, and keeps the result as three keeps nodeProperties.outputNode: in the builder’s per-build data, keyed on the node’s identity and scoped by isolate. Two reaches of one Node::Custom share one expansion; two Node::Customs over equal structs are two nodes. See docs/nodes.md §45.

ⓘ
struct Double(NodeRef);

impl CustomNode for Double {
    fn type_name(&self) -> &'static str { "DoubleNode" }
    fn node_type(&self) -> Type { self.0.ty() }
    fn setup(&self, _: &NodeBuilder) -> NodeRef { self.0.clone().mul(2.0) }
}

let doubled = custom(Double(uv().x()));

Required Methods§

Source

fn type_name(&self) -> &'static str

three’s static get type(): the class name, 'RGBShiftNode'. Only Debug output and panic messages read it.

Source

fn node_type(&self) -> Type

Node.getNodeType( builder ): the WGSL type of the value setup returns. The port needs it before the build, because the TSL methods that wrap this node (.mul(), .x(), …) type their result eagerly.

Source

fn setup(&self, builder: &NodeBuilder) -> NodeRef

Node.setup( builder ): the graph this node stands for.

builder is shared, not mutable: the only thing to ask it is context, three’s builder.context, as installed by an enclosing context node. The TSL functions called here see the same context through the crate’s own accessors.

Provided Methods§

Source

fn is_cacheable(&self) -> bool

Node.isCacheable( builder ): whether a node reached more than once is built into a var once and read from there. r187dev’s Node.build() does that for every cacheable node with a value (cacheResult), not only for TempNodes, so the default is true, as three’s is. false builds the output again at every reach.

Source

fn update_before_type(&self) -> NodeUpdateType

updateBeforeType. Anything but None puts the node in the material’s update-before list; see docs/nodes.md §57.

Source

fn update_type(&self) -> NodeUpdateType

updateType.

Source

fn update_after_type(&self) -> NodeUpdateType

updateAfterType.

Source

fn update_before(&self, _renderer: &mut Renderer) -> bool

updateBefore( frame ). false leaves the guard untouched, as three’s === false does. See NodeUpdate.

Source

fn update(&self, _renderer: &mut Renderer) -> bool

update( frame ).

Source

fn update_after(&self, _renderer: &mut Renderer) -> bool

updateAfter( frame ).

Trait Implementations§

Source§

impl Debug for dyn CustomNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§