mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Layers: R + click reads each compare mask against the layers below its own layer
This commit is contained in:
1 parent
1f4981ea98
commit
4c2df2a0a0
2 files changed
+41
-11
No files matched your search
@@ -1,8 +1,8 @@
|
||||
//! Which layers lay something down at one texel, for the viewport's Pick layer tool
|
||||
//! Which layers lay something down at one texel, for R + click on the model
|
||||
|
||||
use super::{
|
||||
BlendMode, Channel, Content, EvaluationInputs, Inputs, LayerId, NCH, NO_TRI, Node, ProjectorDepthCache, TILE, Texel, evaluation_channels,
|
||||
evaluation_fields, plan, prepare_generators,
|
||||
Acc, BlendMode, Channel, Content, EvaluationInputs, Inputs, LayerId, NCH, NO_TRI, Node, ProjectorDepthCache, TILE, Texel, evaluation_channels,
|
||||
evaluation_fields, mix_group, plan, prepare_generators,
|
||||
};
|
||||
|
||||
/// Below this weight a layer leaves the texel unchanged (one 16-bit step)
|
||||
@@ -38,12 +38,9 @@ pub fn layers_at(inputs: &Inputs, projectors: &ProjectorDepthCache, (x, y): (u32
|
||||
let offset = ((y % TILE) * TILE + x % TILE) as usize;
|
||||
let mut texel = Texel::new(inputs, x, y, offset, 0.0);
|
||||
|
||||
// The whole stack runs first, so masks and fills that read anchors find them
|
||||
let mut values = Channel::ALL.map(Channel::default_value);
|
||||
texel.eval(&nodes, &mut values);
|
||||
|
||||
let mut stack = Channel::ALL.map(Channel::default_value);
|
||||
let mut found = Vec::new();
|
||||
texel.layers_laying_down(&nodes, [1.0; NCH], shown, &mut found);
|
||||
texel.layers_laying_down(&nodes, &mut stack, [1.0; NCH], shown, &mut found);
|
||||
|
||||
// The stack runs bottom first
|
||||
found.reverse();
|
||||
@@ -51,11 +48,15 @@ pub fn layers_at(inputs: &Inputs, projectors: &ProjectorDepthCache, (x, y): (u32
|
||||
}
|
||||
|
||||
impl Texel<'_, '_> {
|
||||
/// Push the leaf layers among `nodes` (bottom first) that lay something down in a `shown` channel, with those channels, each channel weighted by `weights` (the opacity and mask of the folders holding them)
|
||||
fn layers_laying_down(&mut self, nodes: &[Node], weights: [f32; NCH], shown: &[Channel], found: &mut Vec<(LayerId, Vec<Channel>)>) {
|
||||
/// Composite `nodes` (bottom first) over `stack`, pushing the leaf layers that lay something down in a `shown` channel, with those channels, each channel weighted by `weights` (the opacity and mask of the folders holding them)
|
||||
fn layers_laying_down(&mut self, nodes: &[Node], stack: &mut Acc, weights: [f32; NCH], shown: &[Channel], found: &mut Vec<(LayerId, Vec<Channel>)>) {
|
||||
for node in nodes {
|
||||
// A mask comparing with the layers below reads the stack under its own layer
|
||||
self.below = Some(*stack);
|
||||
let mask = self.node_mask(node);
|
||||
if mask <= 0.0 {
|
||||
// A masked-out layer still records its anchor points
|
||||
self.eval(std::slice::from_ref(node), stack);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -67,7 +68,11 @@ impl Texel<'_, '_> {
|
||||
}
|
||||
|
||||
match &node.content {
|
||||
Content::Group(children) => self.layers_laying_down(children, node_weights, shown, found),
|
||||
Content::Group(children) => {
|
||||
let mut inner = *stack;
|
||||
self.layers_laying_down(children, &mut inner, node_weights, shown, found);
|
||||
mix_group(stack, &inner, &node.chans, mask);
|
||||
}
|
||||
content => {
|
||||
let changed: Vec<Channel> = shown
|
||||
.iter()
|
||||
@@ -87,6 +92,8 @@ impl Texel<'_, '_> {
|
||||
if !changed.is_empty() {
|
||||
found.push((node.draw.0, changed));
|
||||
}
|
||||
|
||||
self.eval(std::slice::from_ref(node), stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,3 +100,26 @@ fn a_pick_opens_the_collapsed_folders_holding_the_picked_layer() {
|
||||
let open = |folder| matches!(s.doc.project.layers[&folder].kind, LayerKind::Group { collapsed: false, .. });
|
||||
assert!(open(inner) && open(outer), "both folders holding the picked layer are open");
|
||||
}
|
||||
|
||||
/// Each height-combination mask compares with the layers below its own layer, not below another's
|
||||
#[test]
|
||||
fn a_height_combination_mask_is_read_against_the_layers_below_its_own_layer() {
|
||||
let (mut s, ..) = stack();
|
||||
let add = |s: &mut Session, height: f32| id(execute(s, "layer.add.fill", &json!({"color": [1.0, 1.0, 1.0], "height": height})).unwrap());
|
||||
let base = add(&mut s, 0.0);
|
||||
let lower = add(&mut s, 0.3);
|
||||
execute(&mut s, "mask.add.heightCombination", &json!({"layer": lower})).unwrap();
|
||||
let raised = add(&mut s, 0.6);
|
||||
let upper = add(&mut s, 0.9);
|
||||
execute(&mut s, "mask.add.heightCombination", &json!({"layer": upper})).unwrap();
|
||||
for layer in [base, raised] {
|
||||
execute(&mut s, "layer.blend", &json!({"layer": layer, "channel": "height", "mode": "Normal"})).unwrap();
|
||||
}
|
||||
execute(&mut s, "layer.blend", &json!({"layer": raised, "channel": "baseColor", "enabled": false})).unwrap();
|
||||
s.update();
|
||||
|
||||
let listed: Vec<u64> = layers_at(&mut s, MIDDLE).into_iter().map(|(layer, _)| layer).collect();
|
||||
|
||||
assert!(listed.contains(&lower), "the lower combination shows over the base: {listed:?}");
|
||||
assert!(listed.contains(&upper), "and so does the upper one: {listed:?}");
|
||||
}
|
||||
Reference in new issue
Block a user