mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-30 01:53:54 +01:00
Add 548 native library packages and 11 original resource substitutes, with rewritten descriptions/layouts, shared resource references and bundled assets for desktop and browser builds. Retain supplied graph implementations; presentation changes are not an independent rewrite. Preserve baseline SBS formatVersion and refresh updaterVersion on saves. Fix foreign resource bindings, native parameter/port mappings, scalar channel functions, FX-Map roughness and bounded graph expansion. Validation: release core/formats/nodes/eval/engine tests, converter tests, strict Clippy on Rust 1.96, layering, WASM, formatting and diff checks passed during this work. All 560 library files reproduce exactly. Bricks cooks without errors; the full library audit still reports 308 warning entries and 10 standalone function compilation failures. Work in progress: node-local Set scope, remaining native parameter support, primitive numerical parity and external save/reopen validation. The motionblur identifier needs reference-runtime investigation. Refs #191
34 lines
1.4 KiB
Rust
34 lines
1.4 KiB
Rust
use materialcraft_core::{FunctionGraph, Value, ValueType};
|
|
use materialcraft_nodes::function::{EvaluationContext, EvaluationState, compile};
|
|
use std::collections::BTreeMap;
|
|
|
|
pub(crate) fn evaluate(
|
|
function: &FunctionGraph,
|
|
expected: ValueType,
|
|
variables: &BTreeMap<String, Value>,
|
|
seed: u32,
|
|
size: [u32; 2],
|
|
allow_scalar: bool,
|
|
) -> Result<Value, String> {
|
|
let program = compile(function, seed)?;
|
|
let scalar_channel = allow_scalar && expected == ValueType::Float4 && program.output_type() == ValueType::Float as u32;
|
|
if program.output_type() != expected as u32 && !scalar_channel {
|
|
return Err(format!("output must be {}", expected.label()));
|
|
}
|
|
|
|
let context = EvaluationContext { scope: Default::default(), position: [0.5; 2], size: size.map(|side| side as f32), images: &[], tile: true, variables };
|
|
let value = program.evaluate(&context, &mut EvaluationState::default())?;
|
|
let finite = match &value {
|
|
Value::Float(value) => value.is_finite(),
|
|
Value::Float2(values) => values.iter().all(|value| value.is_finite()),
|
|
Value::Float3(values) => values.iter().all(|value| value.is_finite()),
|
|
Value::Float4(values) | Value::Color(values) => values.iter().all(|value| value.is_finite()),
|
|
_ => true,
|
|
};
|
|
if !finite {
|
|
return Err("function returned a non-finite value".into());
|
|
}
|
|
|
|
Ok(value)
|
|
}
|