mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-10 00:08:03 +00:00
Fix image loading and remove resolve_empty_stacks() function (#1746)
* Fix Image loading and remove `resolve_empty_stacks()` * Revert noise pattern change * Add todo comment
This commit is contained in:
parent
244c8ad10a
commit
1bfbe306be
3 changed files with 67 additions and 45 deletions
|
@ -333,7 +333,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
|||
category: "Structural",
|
||||
implementation: DocumentNodeImplementation::Network(NodeNetwork {
|
||||
imports: vec![NodeId(0), NodeId(0)],
|
||||
exports: vec![NodeOutput::new(NodeId(1), 0)],
|
||||
exports: vec![NodeOutput::new(NodeId(2), 0)],
|
||||
nodes: [
|
||||
DocumentNode {
|
||||
name: "Load Resource".to_string(),
|
||||
|
@ -347,6 +347,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
|||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::DecodeImageNode")),
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNode {
|
||||
name: "Cull".to_string(),
|
||||
inputs: vec![NodeInput::node(NodeId(1), 0)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::transform::CullNode<_>")),
|
||||
manual_composition: Some(concrete!(Footprint)),
|
||||
..Default::default()
|
||||
},
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
|
@ -646,7 +653,65 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
|||
DocumentNodeDefinition {
|
||||
name: "Noise Pattern",
|
||||
category: "General",
|
||||
implementation: DocumentNodeImplementation::proto("graphene_std::raster::NoisePatternNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
|
||||
implementation: DocumentNodeImplementation::Network(NodeNetwork {
|
||||
imports: vec![
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
NodeId(0),
|
||||
],
|
||||
exports: vec![NodeOutput::new(NodeId(1), 0)],
|
||||
nodes: vec![
|
||||
DocumentNode {
|
||||
name: "Noise Pattern".to_string(),
|
||||
inputs: vec![
|
||||
NodeInput::Network(concrete!(())),
|
||||
NodeInput::Network(concrete!(UVec2)),
|
||||
NodeInput::Network(concrete!(u32)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
NodeInput::Network(concrete!(graphene_core::raster::NoiseType)),
|
||||
NodeInput::Network(concrete!(graphene_core::raster::FractalType)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
NodeInput::Network(concrete!(graphene_core::raster::FractalType)),
|
||||
NodeInput::Network(concrete!(u32)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
NodeInput::Network(concrete!(graphene_core::raster::CellularDistanceFunction)),
|
||||
NodeInput::Network(concrete!(graphene_core::raster::CellularReturnType)),
|
||||
NodeInput::Network(concrete!(f64)),
|
||||
],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::raster::NoisePatternNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _>")),
|
||||
..Default::default()
|
||||
},
|
||||
// TODO: Make noise pattern node resolution aware and remove the cull node
|
||||
DocumentNode {
|
||||
name: "Cull".to_string(),
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::transform::CullNode<_>")),
|
||||
manual_composition: Some(concrete!(Footprint)),
|
||||
..Default::default()
|
||||
},
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(id, node)| (NodeId(id as u64), node))
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}),
|
||||
inputs: vec![
|
||||
DocumentInputType::value("None", TaggedValue::None, false),
|
||||
// All
|
||||
|
@ -2752,7 +2817,6 @@ impl DocumentNodeDefinition {
|
|||
pub fn wrap_network_in_scope(mut network: NodeNetwork, hash: u64) -> NodeNetwork {
|
||||
network.generate_node_paths(&[]);
|
||||
|
||||
network.resolve_empty_stacks();
|
||||
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
||||
for id in node_ids {
|
||||
network.flatten(id);
|
||||
|
|
|
@ -1182,47 +1182,6 @@ impl NodeNetwork {
|
|||
self.nodes.extend(extraction_nodes);
|
||||
}
|
||||
|
||||
/// Due to the adaptive resolution system, nodes that take a `GraphicGroup` as input must call the upstream node with the `Footprint` parameter.
|
||||
///
|
||||
/// However, in the case of the default input, we must insert a node that takes an input of `Footprint` and returns `GraphicGroup::Empty`, in order to satisfy the type system.
|
||||
/// This is because the standard value node takes in `()`.
|
||||
pub fn resolve_empty_stacks(&mut self) {
|
||||
for value in [
|
||||
TaggedValue::GraphicGroup(GraphicGroup::EMPTY),
|
||||
TaggedValue::VectorData(VectorData::empty()),
|
||||
TaggedValue::ArtboardGroup(ArtboardGroup::EMPTY),
|
||||
] {
|
||||
const EMPTY_STACK: &str = "Empty Stack";
|
||||
|
||||
let new_id = generate_uuid();
|
||||
let mut used = false;
|
||||
|
||||
// We filter out the newly inserted empty stack in case `resolve_empty_stacks` runs multiple times.
|
||||
for node in self.nodes.values_mut().filter(|node| node.name != EMPTY_STACK) {
|
||||
for input in &mut node.inputs {
|
||||
if let NodeInput::Value { tagged_value, .. } = input {
|
||||
if *tagged_value == value {
|
||||
*input = NodeInput::node(NodeId(new_id), 0);
|
||||
used = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only insert the node if necessary.
|
||||
if used {
|
||||
let new_node = DocumentNode {
|
||||
name: EMPTY_STACK.to_string(),
|
||||
implementation: DocumentNodeImplementation::proto("graphene_core::transform::CullNode<_>"),
|
||||
manual_composition: Some(concrete!(graphene_core::transform::Footprint)),
|
||||
inputs: vec![NodeInput::value(value, false)],
|
||||
..Default::default()
|
||||
};
|
||||
self.nodes.insert(NodeId(new_id), new_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a proto network for evaluating each output of this network.
|
||||
pub fn into_proto_networks(self) -> impl Iterator<Item = ProtoNetwork> {
|
||||
let mut nodes: Vec<_> = self.nodes.into_iter().map(|(id, node)| (id, node.resolve_proto_node())).collect();
|
||||
|
|
|
@ -10,7 +10,6 @@ pub struct Compiler {}
|
|||
impl Compiler {
|
||||
pub fn compile(&self, mut network: NodeNetwork) -> Result<impl Iterator<Item = ProtoNetwork>, String> {
|
||||
println!("flattening");
|
||||
network.resolve_empty_stacks();
|
||||
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
||||
for id in node_ids {
|
||||
network.flatten(id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue