Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions editor/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::dispatcher::Dispatcher;
use crate::messages::portfolio::document::node_graph::generate_node_graph_overlay::generate_node_graph_overlay;
use crate::messages::prelude::*;
use graph_craft::document::{NodeInput, NodeNetwork};
use graphene_std::node_graph_overlay::types::NodeGraphOverlayData;
pub use graphene_std::uuid::*;

// TODO: serialize with serde to save the current editor state
Expand Down Expand Up @@ -30,6 +33,33 @@ impl Editor {
pub fn poll_node_graph_evaluation(&mut self, responses: &mut VecDeque<Message>) -> Result<(), String> {
self.dispatcher.poll_node_graph_evaluation(responses)
}

pub fn generate_node_graph_overlay_network(&mut self) -> Option<NodeNetwork> {
let Some(active_document) = self.dispatcher.message_handlers.portfolio_message_handler.active_document_mut() else {
return None;
};
let breadcrumb_network_path = &active_document.breadcrumb_network_path;
let nodes_to_render = active_document.network_interface.collect_nodes(
&active_document.node_graph_handler.node_graph_errors,
self.dispatcher.message_handlers.preferences_message_handler.graph_wire_style,
breadcrumb_network_path,
);
let previewed_node = active_document.network_interface.previewed_node(breadcrumb_network_path);
let node_graph_render_data = NodeGraphOverlayData {
nodes_to_render,
open: active_document.graph_view_overlay_open,
in_selected_network: &active_document.selection_network_path == breadcrumb_network_path,
previewed_node,
};
let opacity = active_document.graph_fade_artwork_percentage;
let font_cache = self.dispatcher.message_handlers.portfolio_message_handler.persistent_data.font_cache.clone();
let node_graph_overlay_node = generate_node_graph_overlay(node_graph_render_data, opacity, font_cache);
Some(NodeNetwork {
exports: vec![NodeInput::node(NodeId(0), 0)],
nodes: vec![(NodeId(0), node_graph_overlay_node)].into_iter().collect(),
..Default::default()
})
}
}

impl Default for Editor {
Expand Down
4 changes: 2 additions & 2 deletions editor/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub struct DispatcherMessageHandlers {
defer_message_handler: DeferMessageHandler,
dialog_message_handler: DialogMessageHandler,
globals_message_handler: GlobalsMessageHandler,
input_preprocessor_message_handler: InputPreprocessorMessageHandler,
pub input_preprocessor_message_handler: InputPreprocessorMessageHandler,
key_mapping_message_handler: KeyMappingMessageHandler,
layout_message_handler: LayoutMessageHandler,
pub portfolio_message_handler: PortfolioMessageHandler,
preferences_message_handler: PreferencesMessageHandler,
pub preferences_message_handler: PreferencesMessageHandler,
tool_message_handler: ToolMessageHandler,
}

Expand Down
19 changes: 12 additions & 7 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::utility_types::{FrontendDocumentDetails, MouseCursorIcon};
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::node_graph::utility_types::{
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendExports, FrontendImport, FrontendNodeToRender, FrontendNodeType, FrontendXY, Transform,
};
use crate::messages::portfolio::document::node_graph::utility_types::{BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendNodeType};
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
use crate::messages::portfolio::document::utility_types::wires::WirePathInProgress;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::HintData;
use graph_craft::document::NodeId;
use graphene_std::node_graph_overlay::types::{FrontendExports, FrontendImport, FrontendNodeToRender, FrontendXY, NodeGraphTransform};
use graphene_std::raster::Image;
use graphene_std::raster::color::Color;
use graphene_std::text::{Font, TextAlign};
Expand Down Expand Up @@ -268,7 +267,7 @@ pub enum FrontendMessage {
UpdateMouseCursor {
cursor: MouseCursorIcon,
},
UpdateNodeGraphRender {
UpdateNodeGraphSvelteRender {
#[serde(rename = "nodesToRender")]
nodes_to_render: Vec<FrontendNodeToRender>,
open: bool,
Expand All @@ -278,8 +277,14 @@ pub enum FrontendMessage {
// Displays a dashed border around the node
#[serde(rename = "previewedNode")]
previewed_node: Option<NodeId>,
#[serde(rename = "nativeNodeGraphRender")]
native_node_graph_render: bool,
},
UpdateShouldRenderSvelteNodes {
#[serde(rename = "shouldRenderSvelteNodes")]
should_render_svelte_nodes: bool,
},
UpdateNativeNodeGraphSVG {
#[serde(rename = "svgString")]
svg_string: String,
},
UpdateVisibleNodes {
nodes: Vec<NodeId>,
Expand All @@ -290,7 +295,7 @@ pub enum FrontendMessage {
diff: Vec<WidgetDiff>,
},
UpdateNodeGraphTransform {
transform: Transform,
transform: NodeGraphTransform,
},
UpdateNodeThumbnail {
id: NodeId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
use crate::messages::tool::tool_messages::tool_prelude::WidgetCallback;
use derivative::*;
use graphene_std::node_graph_overlay::types::FrontendGraphDataType;
use graphene_std::vector::style::FillChoice;
use graphite_proc_macros::WidgetBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::node_graph::document_node_definitions;
use super::node_graph::utility_types::Transform;
use super::overlays::utility_types::Pivot;
use super::utility_types::error::EditorError;
use super::utility_types::misc::{GroupFolderType, SNAP_FUNCTIONS_FOR_BOUNDING_BOXES, SNAP_FUNCTIONS_FOR_PATHS, SnappingOptions, SnappingState};
Expand Down Expand Up @@ -31,6 +30,7 @@ use glam::{DAffine2, DVec2, IVec2};
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
use graphene_std::math::quad::Quad;
use graphene_std::node_graph_overlay::types::NodeGraphTransform;
use graphene_std::path_bool::{boolean_intersect, path_bool_lib};
use graphene_std::raster::BlendMode;
use graphene_std::raster_types::Raster;
Expand Down Expand Up @@ -119,10 +119,10 @@ pub struct DocumentMessageHandler {
pub(crate) path: Option<PathBuf>,
/// Path to network currently viewed in the node graph overlay. This will eventually be stored in each panel, so that multiple panels can refer to different networks
#[serde(skip)]
breadcrumb_network_path: Vec<NodeId>,
pub breadcrumb_network_path: Vec<NodeId>,
/// Path to network that is currently selected. Updated based on the most recently clicked panel.
#[serde(skip)]
selection_network_path: Vec<NodeId>,
pub selection_network_path: Vec<NodeId>,
/// Stack of document network snapshots for previous history states.
#[serde(skip)]
document_undo_history: VecDeque<NodeNetworkInterface>,
Expand Down Expand Up @@ -1481,7 +1481,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
responses.add(NodeGraphMessage::UpdateImportsExports);

responses.add(FrontendMessage::UpdateNodeGraphTransform {
transform: Transform {
transform: NodeGraphTransform {
scale: transform.matrix2.x_axis.x,
x: transform.translation.x,
y: transform.translation.y,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
use std::sync::Arc;

use graph_craft::{
concrete,
document::{DocumentNode, DocumentNodeImplementation, NodeInput, NodeNetwork, value::TaggedValue},
};
use graphene_std::{
node_graph_overlay::{types::NodeGraphOverlayData, ui_context::UIContext},
table::Table,
text::FontCache,
uuid::NodeId,
};

/// https://excalidraw.com/#json=LgKS6I4lQvGPmke06ZJyp,D9aON9vVZJAjNnZWfwy_SQ
pub fn generate_node_graph_overlay(node_graph_overlay_data: NodeGraphOverlayData, opacity: f64, font_cache: Arc<FontCache>) -> DocumentNode {
let font_cache_id = NodeId::new();

let generate_nodes_id = NodeId::new();
let cache_nodes_id = NodeId::new();
let transform_nodes_id = NodeId::new();

let generate_node_graph_bg = NodeId::new();
let cache_node_graph_bg = NodeId::new();

let merge_nodes_and_bg_id = NodeId::new();
let render_overlay_id = NodeId::new();
let send_overlay_id = NodeId::new();
let _cache_output_id = NodeId::new();
// TODO: Replace with new cache node
let memo_implementation = DocumentNodeImplementation::ProtoNode(graphene_std::ops::identity::IDENTIFIER);

DocumentNode {
inputs: vec![
NodeInput::value(TaggedValue::Vector(Table::new()), true),
NodeInput::value(TaggedValue::NodeGraphOverlayData(node_graph_overlay_data), true),
NodeInput::value(TaggedValue::F64(opacity), true),
],

implementation: DocumentNodeImplementation::Network(NodeNetwork {
exports: vec![NodeInput::node(send_overlay_id, 0)],
nodes: vec![
(
font_cache_id,
DocumentNode {
inputs: vec![NodeInput::value(TaggedValue::FontCache(font_cache), false)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::ops::identity::IDENTIFIER),
..Default::default()
},
),
// Create the nodes
(
generate_nodes_id,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::network(concrete!(UIContext), 1), NodeInput::node(font_cache_id, 0)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::node_graph_overlay::GenerateNodesNode".into()),
..Default::default()
},
),
// Cache the nodes
(
cache_nodes_id,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::node(generate_nodes_id, 0)],
implementation: memo_implementation.clone(),
..Default::default()
},
),
// Transform the nodes based on the Context
(
transform_nodes_id,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::node(cache_nodes_id, 0)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::node_graph_overlay::TransformNodesNode".into()),
..Default::default()
},
),
// Generate the dot grid background
(
generate_node_graph_bg,
DocumentNode {
inputs: vec![NodeInput::network(concrete!(UIContext), 2)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::node_graph_overlay::DotGridBackgroundNode".into()),
call_argument: concrete!(UIContext),
..Default::default()
},
),
// Cache the dot grid background
(
cache_node_graph_bg,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::node(generate_node_graph_bg, 0)],
implementation: memo_implementation.clone(),
..Default::default()
},
),
// Merge the nodes on top of the dot grid background
(
merge_nodes_and_bg_id,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::node(transform_nodes_id, 0), NodeInput::node(cache_node_graph_bg, 0)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::node_graph_overlay::NodeGraphUiExtendNode".into()),
..Default::default()
},
),
// Render the node graph UI graphic to an SVG
(
render_overlay_id,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::node(merge_nodes_and_bg_id, 0)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_std::wasm_application_io::RenderNodeGraphUiNode".into()),
..Default::default()
},
),
// Send the overlay to the frontend
(
send_overlay_id,
DocumentNode {
call_argument: concrete!(UIContext),
inputs: vec![NodeInput::node(render_overlay_id, 0)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::node_graph_overlay::SendRenderNode".into()),
..Default::default()
},
),
// Cache the full node graph so its not rerendered when the artwork changes
// (
// cache_nodes_id,
// DocumentNode {
// call_argument: concrete!(UIContext),
// inputs: vec![NodeInput::node(send_overlay_id, 0)],
// implementation: memo_implementation.clone(),
// ..Default::default()
// },
// ),
]
.into_iter()
.collect(),
..Default::default()
}),
call_argument: concrete!(UIContext),
..Default::default()
}
}
1 change: 1 addition & 0 deletions editor/src/messages/portfolio/document/node_graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod document_node_definitions;
pub mod generate_node_graph_overlay;
mod node_graph_message;
mod node_graph_message_handler;
pub mod node_properties;
Expand Down
Loading
Loading