mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-28 17:19:17 +01:00
Use export parameter overrides when resolving graph aspect ratio
This commit is contained in:
1 parent
b33b76fc43
commit
ca578b967c
2 files changed
+34
No files matched your search
@@ -435,6 +435,38 @@ fn published_disabled_and_typed_instance_cooks_match_source() {
|
||||
assert!((restored[0] - 0.2).abs() < 0.01, "disabled levels must preserve its input: {restored:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn material_resize_uses_overridden_size_expression_without_editing_the_document() {
|
||||
use materialcraft_core::{ExposedParameter, FunctionGraph, ValueType};
|
||||
|
||||
let mut session = fixture();
|
||||
let graph = session.graph_mut().unwrap();
|
||||
graph.exposed.push(ExposedParameter {
|
||||
id: "axes".into(),
|
||||
label: "Axes".into(),
|
||||
default: Value::Int2([4, 5]),
|
||||
connectable: false,
|
||||
min: 0.0,
|
||||
max: 13.0,
|
||||
clamp: false,
|
||||
step: None,
|
||||
editor: None,
|
||||
description: String::new(),
|
||||
group: String::new(),
|
||||
options: Vec::new(),
|
||||
});
|
||||
graph.absolute_output_size = Some([4, 5]);
|
||||
graph.output_size_function = Some(FunctionGraph::input("axes", ValueType::Integer2));
|
||||
let before = session.pkg.clone();
|
||||
let options =
|
||||
MaterialOptions { size: Some(crate::ExportSize::LargerSide(64)), values: [("axes".into(), Value::Int2([6, 4]))].into(), ..Default::default() };
|
||||
let cooked = options.cook(&session, session.graph, None, None).unwrap();
|
||||
let output = session.graph().unwrap().nodes.iter().find(|node| node.def == "output").unwrap();
|
||||
let image = cooked.image(output.id, 0).unwrap();
|
||||
assert_eq!((image.width(), image.height()), (64, 16), "resize must preserve the overridden aspect ratio");
|
||||
assert_eq!(session.pkg, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn material_options_ignore_stale_presets_but_validate_explicit_values() {
|
||||
let mut session = fixture();
|
||||
|
||||
@@ -84,6 +84,8 @@ impl MaterialOptions {
|
||||
let graph = package.to_mut().graph_mut(index)?;
|
||||
let basis = match size {
|
||||
ExportSize::LargerSide(_) => {
|
||||
// Size expressions must see the same exposed values as the export cook.
|
||||
graph.inputs.extend(self.values.clone());
|
||||
materialcraft_eval::graph_output_size(graph, session.environment).map_err(|error| bad("material.cook", error))?.map(u32::ilog2)
|
||||
}
|
||||
ExportSize::Exact(_) => graph.size,
|
||||
|
||||
Reference in new issue
Block a user