55// on the dispatcher messaging system and more complex Rust data types.
66//
77use crate :: helpers:: translate_key;
8- use crate :: { EDITOR_HANDLE , EDITOR_HAS_CRASHED , Error , MESSAGE_BUFFER } ;
8+ #[ cfg( not( feature = "native" ) ) ]
9+ use crate :: wasm_node_graph_ui_executor:: WasmNodeGraphUIExecutor ;
10+ use crate :: { EDITOR_HANDLE , EDITOR_HAS_CRASHED , Error , MESSAGE_BUFFER , WASM_NODE_GRAPH_EXECUTOR } ;
911use editor:: consts:: FILE_EXTENSION ;
1012use editor:: messages:: input_mapper:: utility_types:: input_keyboard:: ModifierKeys ;
1113use editor:: messages:: input_mapper:: utility_types:: input_mouse:: { EditorMouseState , ScrollDelta , ViewportBounds } ;
@@ -17,6 +19,7 @@ use editor::messages::tool::tool_messages::tool_prelude::WidgetId;
1719use graph_craft:: document:: NodeId ;
1820use graphene_std:: raster:: Image ;
1921use graphene_std:: raster:: color:: Color ;
22+ use interpreted_executor:: ui_runtime:: CompilationRequest ;
2023use js_sys:: { Object , Reflect } ;
2124use serde:: Serialize ;
2225use serde_wasm_bindgen:: { self , from_value} ;
@@ -149,9 +152,13 @@ impl EditorHandle {
149152 pub fn new ( frontend_message_handler_callback : js_sys:: Function ) -> Self {
150153 let editor = Editor :: new ( ) ;
151154 let editor_handle = EditorHandle { frontend_message_handler_callback } ;
155+ let node_graph_executor = WasmNodeGraphUIExecutor :: new ( ) ;
152156 if EDITOR . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( editor) ) ) . is_none ( ) {
153157 log:: error!( "Attempted to initialize the editor more than once" ) ;
154158 }
159+ if WASM_NODE_GRAPH_EXECUTOR . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( node_graph_executor) ) ) . is_none ( ) {
160+ log:: error!( "Attempted to initialize the editor more than once" ) ;
161+ }
155162 if EDITOR_HANDLE . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( editor_handle. clone ( ) ) ) ) . is_none ( ) {
156163 log:: error!( "Attempted to initialize the editor handle more than once" ) ;
157164 }
@@ -208,6 +215,17 @@ impl EditorHandle {
208215
209216 // Sends a FrontendMessage to JavaScript
210217 fn send_frontend_message_to_js ( & self , mut message : FrontendMessage ) {
218+ // Intercept any requests to render the node graph overlay
219+ if message == FrontendMessage :: RequestNativeNodeGraphRender {
220+ executor_editor_and_handle ( |executor, editor, _handle| {
221+ if let Some ( node_graph_overlay_network) = editor. generate_node_graph_overlay_network ( ) {
222+ let compilation_request = CompilationRequest { network : node_graph_overlay_network } ;
223+ executor. compilation_request ( compilation_request) ;
224+ }
225+ } ) ;
226+ return ;
227+ }
228+
211229 if let FrontendMessage :: UpdateImageData { ref image_data } = message {
212230 let new_hash = calculate_hash ( image_data) ;
213231 let prev_hash = IMAGE_DATA_HASH . load ( Ordering :: Relaxed ) ;
@@ -264,6 +282,18 @@ impl EditorHandle {
264282 #[ cfg( not( feature = "native" ) ) ]
265283 wasm_bindgen_futures:: spawn_local ( poll_node_graph_evaluation ( ) ) ;
266284
285+ // Poll the UI node graph
286+ #[ cfg( not( feature = "native" ) ) ]
287+ executor_editor_and_handle ( |executor, editor, handle| {
288+ for frontend_message in executor
289+ . poll_node_graph_ui_evaluation ( editor)
290+ . into_iter ( )
291+ . flat_map ( |runtime_response| editor. handle_message ( runtime_response) )
292+ {
293+ handle. send_frontend_message_to_js ( frontend_message) ;
294+ }
295+ } ) ;
296+
267297 if !EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
268298 handle ( |handle| {
269299 // Process all messages that have been queued up
@@ -989,6 +1019,31 @@ fn editor<T: Default>(callback: impl FnOnce(&mut editor::application::Editor) ->
9891019 } )
9901020}
9911021
1022+ #[ cfg( not( feature = "native" ) ) ]
1023+ fn executor < T : Default > ( callback : impl FnOnce ( & mut WasmNodeGraphUIExecutor ) -> T ) -> T {
1024+ WASM_NODE_GRAPH_EXECUTOR . with ( |executor| {
1025+ let mut guard = executor. try_lock ( ) ;
1026+ let Ok ( Some ( executor) ) = guard. as_deref_mut ( ) else {
1027+ log:: error!( "Failed to borrow editor" ) ;
1028+ return T :: default ( ) ;
1029+ } ;
1030+
1031+ callback ( executor)
1032+ } )
1033+ }
1034+
1035+ #[ cfg( not( feature = "native" ) ) ]
1036+ pub ( crate ) fn executor_editor_and_handle ( callback : impl FnOnce ( & mut WasmNodeGraphUIExecutor , & mut Editor , & mut EditorHandle ) ) {
1037+ executor ( |executor| {
1038+ handle ( |editor_handle| {
1039+ editor ( |editor| {
1040+ // Call the closure with the editor and its handle
1041+ callback ( executor, editor, editor_handle) ;
1042+ } )
1043+ } ) ;
1044+ } )
1045+ }
1046+
9921047/// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments.
9931048#[ cfg( not( feature = "native" ) ) ]
9941049pub ( crate ) fn editor_and_handle ( callback : impl FnOnce ( & mut Editor , & mut EditorHandle ) ) {
@@ -1046,7 +1101,6 @@ async fn poll_node_graph_evaluation() {
10461101 // If the editor cannot be borrowed then it has encountered a panic - we should just ignore new dispatches
10471102 } ) ;
10481103}
1049-
10501104fn auto_save_all_documents ( ) {
10511105 // Process no further messages after a crash to avoid spamming the console
10521106 if EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
0 commit comments