Files
materialcraft/crates/eval/src/graph_output.rs
T
dotCooCoo 9744afda83 Image: use craft-texture's image planes and sampling
Replace the local materialcraft-image crate with craft-texture from
storytold/craft-libs (storytold/craft-libs#1216), with its parallel
feature on. engine re-exports it as `engine::image`. Every craft-libs
dependency moves to the same revision, 29fb8f8e.

The image fields are private in craft-texture. Callers read them through
width(), height(), kind() and data(), and decoders, the pixel processor
and the pattern raster build images with Image::from_data, which rejects
an empty size or a buffer of the wrong length with an error.

This changes some pixels at the edges of the float range:
- a repeated sample far from the origin keeps its phase instead of
  stopping at a clamped texel position
- generate_uv spreads its coordinates over the clamped size
- bilinear samples and box downsampling of values near f32::MAX stay
  finite
- linear_to_srgb(NaN) returns NaN instead of -0.055

The box blur's running sum in nodes/src/ops.rs now uses f64 as well,
so a blur of values near f32::MAX no longer overflows.

#225 fixes the generate_uv fault in the local crate; craft-texture
includes that fix.
2026-11-14 15:59:55 -08:00

18 lines
770 B
Rust

use crate::{Cooked, identifier};
use materialcraft_core::{ComponentUsage, Graph, Node, NodeId, Value};
pub fn output_usage(node: &Node) -> &'static str {
let index = match node.params.get("usage") {
None => 0,
Some(Value::Enum(index)) => *index,
Some(value) => value.as_i32().map_or(ComponentUsage::ANY_INDEX, |index| index.max(0) as u32),
};
ComponentUsage::from_index(index).id
}
use craft_texture::Image;
/// The graph's output nodes with their usage id and image, in node order
pub fn outputs<'c>(graph: &Graph, cooked: &'c Cooked) -> Vec<(NodeId, &'static str, String, Option<&'c Image>)> {
graph.nodes.iter().filter(|n| n.def == "output").map(|n| (n.id, output_usage(n), identifier(n), cooked.image(n.id, 0))).collect()
}