Skip to content

Commit 00dc5d4

Browse files
committed
Make Layer > Morph create the Morph Path control layer
1 parent 3a18737 commit 00dc5d4

File tree

4 files changed

+50
-76
lines changed

4 files changed

+50
-76
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,15 +1969,17 @@ impl DocumentMessageHandler {
19691969
});
19701970
}
19711971
}
1972-
GroupFolderType::BlendShapes => {
1973-
let blend_path_id = NodeId(generate_uuid());
1972+
GroupFolderType::BlendShapes | GroupFolderType::Morph => {
1973+
let control_path_id = NodeId(generate_uuid());
19741974
let all_layers_to_group = network_interface.shallowest_unique_layers_sorted(&[]);
1975-
responses.add(GraphOperationMessage::NewBlendShapesLayer {
1975+
let blend_count = matches!(group_folder_type, GroupFolderType::BlendShapes).then(|| all_layers_to_group.len() * 10);
1976+
1977+
responses.add(GraphOperationMessage::NewInterpolationLayer {
19761978
id: folder_id,
1977-
blend_path_id,
1979+
control_path_id,
19781980
parent,
19791981
insert_index,
1980-
count: all_layers_to_group.len() * 10,
1982+
blend_count,
19811983
});
19821984

19831985
let new_group_folder = LayerNodeIdentifier::new_unchecked(folder_id);
@@ -1991,39 +1993,17 @@ impl DocumentMessageHandler {
19911993
});
19921994
}
19931995

1994-
// Connect the child stack to the Blend Path layer as a co-parent
1995-
responses.add(GraphOperationMessage::ConnectBlendPathToChildren {
1996-
blend_shape_id: folder_id,
1997-
blend_path_id,
1996+
// Connect the child stack to the control path layer as a co-parent
1997+
responses.add(GraphOperationMessage::ConnectInterpolationControlPathToChildren {
1998+
interpolation_layer_id: folder_id,
1999+
control_path_id,
19982000
});
19992001

20002002
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![folder_id] });
20012003
responses.add(NodeGraphMessage::RunDocumentGraph);
20022004
responses.add(DocumentMessage::DocumentStructureChanged);
20032005
responses.add(NodeGraphMessage::SendGraph);
20042006

2005-
return folder_id;
2006-
}
2007-
GroupFolderType::Morph => {
2008-
responses.add(GraphOperationMessage::NewMorphLayer { id: folder_id, parent, insert_index });
2009-
2010-
let new_group_folder = LayerNodeIdentifier::new_unchecked(folder_id);
2011-
2012-
// Move selected layers into the group as children
2013-
let all_layers_to_group = network_interface.shallowest_unique_layers_sorted(&[]);
2014-
for layer_to_group in all_layers_to_group.into_iter().rev() {
2015-
responses.add(NodeGraphMessage::MoveLayerToStack {
2016-
layer: layer_to_group,
2017-
parent: new_group_folder,
2018-
insert_index: 0,
2019-
});
2020-
}
2021-
2022-
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![folder_id] });
2023-
responses.add(NodeGraphMessage::RunDocumentGraph);
2024-
responses.add(DocumentMessage::DocumentStructureChanged);
2025-
responses.add(NodeGraphMessage::SendGraph);
2026-
20272007
return folder_id;
20282008
}
20292009
}

editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,16 @@ pub enum GraphOperationMessage {
7474
parent: LayerNodeIdentifier,
7575
insert_index: usize,
7676
},
77-
NewBlendShapesLayer {
77+
NewInterpolationLayer {
7878
id: NodeId,
79-
blend_path_id: NodeId,
79+
control_path_id: NodeId,
8080
parent: LayerNodeIdentifier,
8181
insert_index: usize,
82-
count: usize,
82+
blend_count: Option<usize>,
8383
},
84-
ConnectBlendPathToChildren {
85-
blend_shape_id: NodeId,
86-
blend_path_id: NodeId,
87-
},
88-
NewMorphLayer {
89-
id: NodeId,
90-
parent: LayerNodeIdentifier,
91-
insert_index: usize,
84+
ConnectInterpolationControlPathToChildren {
85+
interpolation_layer_id: NodeId,
86+
control_path_id: NodeId,
9287
},
9388
NewBooleanOperationLayer {
9489
id: NodeId,

editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,51 +172,62 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
172172
network_interface.move_layer_to_stack(layer, parent, insert_index, &[]);
173173
responses.add(NodeGraphMessage::RunDocumentGraph);
174174
}
175-
GraphOperationMessage::NewBlendShapesLayer {
175+
GraphOperationMessage::NewInterpolationLayer {
176176
id,
177-
blend_path_id,
177+
control_path_id,
178178
parent,
179179
insert_index,
180-
count,
180+
blend_count,
181181
} => {
182182
let mut modify_inputs = ModifyInputsContext::new(network_interface, responses);
183183
let layer = modify_inputs.create_layer(id);
184-
let blend_shapes_node_id = modify_inputs.insert_blend_shapes_data(layer, count as f64);
185-
let blend_path_layer = modify_inputs.create_layer(blend_path_id);
186-
let path_node_id = modify_inputs.insert_blend_path_data(blend_path_layer);
184+
185+
// Insert the main chain node (Blend Shapes or Morph) depending on whether a blend count is provided
186+
let (chain_node_id, layer_alias, path_alias) = if let Some(count) = blend_count {
187+
(modify_inputs.insert_blend_shapes_data(layer, count as f64), "Blend Shape", "Blend Path")
188+
} else {
189+
(modify_inputs.insert_morph_data(layer), "Morph", "Morph Path")
190+
};
191+
192+
// Create the control path layer (Path → Auto-Tangents → Origins to Polyline)
193+
let control_path_layer = modify_inputs.create_layer(control_path_id);
194+
let path_node_id = modify_inputs.insert_control_path_data(control_path_layer);
187195

188196
network_interface.move_layer_to_stack(layer, parent, insert_index, &[]);
189-
network_interface.move_layer_to_stack(blend_path_layer, parent, insert_index + 1, &[]);
197+
network_interface.move_layer_to_stack(control_path_layer, parent, insert_index + 1, &[]);
190198

191-
// Connect the Path node's output to the Blend Shapes node's Path parameter input (input 4).
199+
// Connect the Path node's output to the chain node's path parameter input (input 4 for both Morph and Blend Shapes).
192200
// Done after move_layer_to_stack so chain nodes have correct positions when converted to absolute.
193-
network_interface.set_input(&InputConnector::node(blend_shapes_node_id, 4), NodeInput::node(path_node_id, 0), &[]);
201+
network_interface.set_input(&InputConnector::node(chain_node_id, 4), NodeInput::node(path_node_id, 0), &[]);
194202

195203
responses.add(NodeGraphMessage::SetDisplayNameImpl {
196204
node_id: id,
197-
alias: "Blend Shape".to_string(),
205+
alias: layer_alias.to_string(),
198206
});
199207
responses.add(NodeGraphMessage::SetDisplayNameImpl {
200-
node_id: blend_path_id,
201-
alias: "Blend Path".to_string(),
208+
node_id: control_path_id,
209+
alias: path_alias.to_string(),
202210
});
203211
}
204-
GraphOperationMessage::ConnectBlendPathToChildren { blend_shape_id, blend_path_id } => {
205-
// Find the Blend Shapes node (first in chain of the Blend Shape layer)
206-
let Some(OutputConnector::Node { node_id: chain_node, .. }) = network_interface.upstream_output_connector(&InputConnector::node(blend_shape_id, 1), &[]) else {
207-
log::error!("Could not find Blend Shapes chain node for layer {blend_shape_id}");
212+
GraphOperationMessage::ConnectInterpolationControlPathToChildren {
213+
interpolation_layer_id,
214+
control_path_id,
215+
} => {
216+
// Find the chain node (Morph or Blend Shapes, first in chain of the layer)
217+
let Some(OutputConnector::Node { node_id: chain_node, .. }) = network_interface.upstream_output_connector(&InputConnector::node(interpolation_layer_id, 1), &[]) else {
218+
log::error!("Could not find chain node for layer {interpolation_layer_id}");
208219
return;
209220
};
210221

211-
// Get what feeds into the Blend Shapes node's primary input (the children stack)
222+
// Get what feeds into the chain node's primary input (the children stack)
212223
let Some(OutputConnector::Node { node_id: children_id, output_index }) = network_interface.upstream_output_connector(&InputConnector::node(chain_node, 0), &[]) else {
213-
log::error!("Could not find children stack feeding Blend Shapes node {chain_node}");
224+
log::error!("Could not find children stack feeding chain node {chain_node}");
214225
return;
215226
};
216227

217-
// Find the deepest node in the Blend Path layer's chain (Origins to Polyline)
228+
// Find the deepest node in the control path layer's chain (Origins to Polyline)
218229
let mut deepest_chain_node = None;
219-
let mut current_connector = InputConnector::node(blend_path_id, 1);
230+
let mut current_connector = InputConnector::node(control_path_id, 1);
220231
while let Some(OutputConnector::Node { node_id, .. }) = network_interface.upstream_output_connector(&current_connector, &[]) {
221232
deepest_chain_node = Some(node_id);
222233
current_connector = InputConnector::node(node_id, 0);
@@ -225,25 +236,13 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
225236
// Connect children to the deepest chain node's input 0 (or the layer's input 1 if no chain)
226237
let target_connector = match deepest_chain_node {
227238
Some(node_id) => InputConnector::node(node_id, 0),
228-
None => InputConnector::node(blend_path_id, 1),
239+
None => InputConnector::node(control_path_id, 1),
229240
};
230241
network_interface.set_input(&target_connector, NodeInput::node(children_id, output_index), &[]);
231242

232243
// Shift the child stack (topmost child only, the rest follow) down 3 and left 10
233244
network_interface.shift_node(&children_id, IVec2::new(-10, 3), &[]);
234245
}
235-
GraphOperationMessage::NewMorphLayer { id, parent, insert_index } => {
236-
let mut modify_inputs = ModifyInputsContext::new(network_interface, responses);
237-
let layer = modify_inputs.create_layer(id);
238-
modify_inputs.insert_morph_data(layer);
239-
network_interface.move_layer_to_stack(layer, parent, insert_index, &[]);
240-
241-
responses.add(NodeGraphMessage::SetDisplayNameImpl {
242-
node_id: id,
243-
alias: "Morph".to_string(),
244-
});
245-
responses.add(NodeGraphMessage::RunDocumentGraph);
246-
}
247246
GraphOperationMessage::NewBooleanOperationLayer { id, operation, parent, insert_index } => {
248247
let mut modify_inputs = ModifyInputsContext::new(network_interface, responses);
249248
let layer = modify_inputs.create_layer(id);

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a> ModifyInputsContext<'a> {
188188
}
189189

190190
/// Returns the Path node ID (the node closest to the layer's merge node in the chain).
191-
pub fn insert_blend_path_data(&mut self, layer: LayerNodeIdentifier) -> NodeId {
191+
pub fn insert_control_path_data(&mut self, layer: LayerNodeIdentifier) -> NodeId {
192192
// Add Origins to Polyline node first (will be pushed deepest in the chain)
193193
let origins_to_polyline = resolve_network_node_type("Origins to Polyline")
194194
.expect("Origins to Polyline node does not exist")

0 commit comments

Comments
 (0)