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§
Sourcefn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
three’s static get type(): the class name, 'RGBShiftNode'. Only
Debug output and panic messages read it.
Sourcefn node_type(&self) -> Type
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.
Sourcefn setup(&self, builder: &NodeBuilder) -> NodeRef
fn setup(&self, builder: &NodeBuilder) -> NodeRef
Provided Methods§
Sourcefn is_cacheable(&self) -> bool
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.
Sourcefn update_before_type(&self) -> NodeUpdateType
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.
Sourcefn update_type(&self) -> NodeUpdateType
fn update_type(&self) -> NodeUpdateType
updateType.
Sourcefn update_after_type(&self) -> NodeUpdateType
fn update_after_type(&self) -> NodeUpdateType
updateAfterType.
Sourcefn update_before(&self, _renderer: &mut Renderer) -> bool
fn update_before(&self, _renderer: &mut Renderer) -> bool
updateBefore( frame ). false leaves the guard untouched, as
three’s === false does. See NodeUpdate.
Sourcefn update_after(&self, _renderer: &mut Renderer) -> bool
fn update_after(&self, _renderer: &mut Renderer) -> bool
updateAfter( frame ).
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".