From 1bfbe306be1cd3aa14d77f78b8208fd9be753086 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Wed, 8 May 2024 10:31:41 +0200 Subject: [PATCH] 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 --- .../node_graph/document_node_types.rs | 70 ++++++++++++++++++- node-graph/graph-craft/src/document.rs | 41 ----------- .../graph-craft/src/graphene_compiler.rs | 1 - 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/editor/src/messages/portfolio/document/node_graph/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/document_node_types.rs index 00c646feb..5aba0fa1c 100644 --- a/editor/src/messages/portfolio/document/node_graph/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/document_node_types.rs @@ -333,7 +333,7 @@ fn static_nodes() -> Vec { 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 { 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 { 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::>(); for id in node_ids { network.flatten(id); diff --git a/node-graph/graph-craft/src/document.rs b/node-graph/graph-craft/src/document.rs index e5972ab90..86823b019 100644 --- a/node-graph/graph-craft/src/document.rs +++ b/node-graph/graph-craft/src/document.rs @@ -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 { let mut nodes: Vec<_> = self.nodes.into_iter().map(|(id, node)| (id, node.resolve_proto_node())).collect(); diff --git a/node-graph/graph-craft/src/graphene_compiler.rs b/node-graph/graph-craft/src/graphene_compiler.rs index c4eabab90..31332d88c 100644 --- a/node-graph/graph-craft/src/graphene_compiler.rs +++ b/node-graph/graph-craft/src/graphene_compiler.rs @@ -10,7 +10,6 @@ pub struct Compiler {} impl Compiler { pub fn compile(&self, mut network: NodeNetwork) -> Result, String> { println!("flattening"); - network.resolve_empty_stacks(); let node_ids = network.nodes.keys().copied().collect::>(); for id in node_ids { network.flatten(id);