mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Layers: flatten folder and R + click build anchor micro heights as the composite does
This commit is contained in:
1 parent
8b1b432460
commit
1f4981ea98
3 files changed
+35
-6
No files matched your search
@@ -5630,7 +5630,8 @@ pub fn flatten_folder(inputs: &Inputs, id: LayerId, tiles: &[(u32, u32)]) -> Opt
|
||||
}
|
||||
let visible_inputs = Inputs { project: &forced_visible, preview: None, block_scales: inputs.block_scales.clone(), ..*inputs };
|
||||
let projectors = ProjectorDepthCache::default();
|
||||
let visible_inputs = EvaluationInputs::new(&visible_inputs, &projectors);
|
||||
let mut visible_inputs = EvaluationInputs::new(&visible_inputs, &projectors);
|
||||
prepare_generators(&mut visible_inputs, Some(id));
|
||||
let planned_channels = evaluation_channels(&visible_inputs, channels.clone());
|
||||
let fields = evaluation_fields(&visible_inputs, &planned_channels, tiles);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::{
|
||||
BlendMode, Channel, Content, EvaluationInputs, Inputs, LayerId, NCH, NO_TRI, Node, ProjectorDepthCache, TILE, Texel, evaluation_channels,
|
||||
evaluation_fields, plan,
|
||||
evaluation_fields, plan, prepare_generators,
|
||||
};
|
||||
|
||||
/// Below this weight a layer leaves the texel unchanged (one 16-bit step)
|
||||
@@ -19,8 +19,16 @@ pub fn layers_at(inputs: &Inputs, projectors: &ProjectorDepthCache, (x, y): (u32
|
||||
|
||||
// A cache built for another mesh would hand out its depth maps
|
||||
let unbound = ProjectorDepthCache::default();
|
||||
let projectors = if projectors.serves(inputs.mesh) { projectors } else { &unbound };
|
||||
let inputs = &EvaluationInputs::new(inputs, projectors);
|
||||
let served = projectors.serves(inputs.mesh);
|
||||
let mut inputs = EvaluationInputs::new(inputs, if served { projectors } else { &unbound });
|
||||
|
||||
// The viewport's anchor heights are kept for the next query
|
||||
if served {
|
||||
inputs = inputs.of_the_session_stack();
|
||||
}
|
||||
prepare_generators(&mut inputs, None);
|
||||
|
||||
let inputs = &inputs;
|
||||
let channels = evaluation_channels(inputs, set.channel_list());
|
||||
|
||||
// Filters and anchors can read texels outside this one's tile: the fields cover what it reads
|
||||
|
||||
@@ -34,8 +34,8 @@ fn stroke(s: &mut Session, size: u32, points: [[u32; 2]; 2]) {
|
||||
fn composite(s: &mut Session) -> Vec<[f32; 3]> {
|
||||
s.update();
|
||||
let channels = s.doc.project.texture_set(0).unwrap().channel_list();
|
||||
let cache = &s.caches[0];
|
||||
channels.iter().flat_map(|c| (0..RESOLUTION).flat_map(move |y| (0..RESOLUTION).map(move |x| cache.composite.value(*c, x, y)))).collect()
|
||||
let composite = &s.caches[0].composite;
|
||||
channels.iter().flat_map(|c| (0..composite.height).flat_map(move |y| (0..composite.resolution).map(move |x| composite.value(*c, x, y)))).collect()
|
||||
}
|
||||
|
||||
fn largest_difference(a: &[[f32; 3]], b: &[[f32; 3]]) -> f32 {
|
||||
@@ -132,3 +132,23 @@ fn a_hidden_folder_flattens_into_a_hidden_layer() {
|
||||
assert!(!s.doc.project.layer(LayerId(flat)).unwrap().visible, "the new layer is hidden like the folder");
|
||||
assert!(largest_difference(&composite(&mut s), &before) < TOLERANCE, "the image does not change");
|
||||
}
|
||||
|
||||
/// A generator whose micro height reads an anchor point bakes as the viewport shows it
|
||||
#[test]
|
||||
fn a_flattened_folder_keeps_a_generators_anchor_micro_height() {
|
||||
let mut s = texturecraft_engine::sample_session(128, 64).unwrap();
|
||||
let folder = id(execute(&mut s, "layer.add.group", &Value::Null).unwrap());
|
||||
let low = id(execute(&mut s, "layer.add.fill", &json!({"height": 1.0})).unwrap());
|
||||
execute(&mut s, "mask.add.black", &json!({"layer": low})).unwrap();
|
||||
execute(&mut s, "effect.add.fill", &json!({"layer": low, "procedural": "checker", "scale": 4.0})).unwrap();
|
||||
let anchor = execute(&mut s, "effect.add.anchor", &json!({"layer": low})).unwrap()["effect"].as_u64().unwrap();
|
||||
let top = id(execute(&mut s, "layer.add.fill", &json!({"color": [1.0, 1.0, 1.0]})).unwrap());
|
||||
execute(&mut s, "mask.add.black", &json!({"layer": top})).unwrap();
|
||||
let generator = execute(&mut s, "effect.add.generator", &json!({"layer": top, "generator": "curvature"})).unwrap()["effect"].as_u64().unwrap();
|
||||
execute(&mut s, "effect.set", &json!({"effect": generator, "microAnchor": anchor, "microAmount": 1.0})).unwrap();
|
||||
let before = composite(&mut s);
|
||||
|
||||
execute(&mut s, "layer.flatten", &json!({"layer": folder})).unwrap();
|
||||
|
||||
assert!(largest_difference(&composite(&mut s), &before) < TOLERANCE, "{}", largest_difference(&composite(&mut s), &before));
|
||||
}
|
||||
Reference in new issue
Block a user