Skip to content

Commit e2d85c8

Browse files
committed
Observe the content input of 'Path' nodes instead of special-casing them in the runtime
1 parent 58a3acd commit e2d85c8

3 files changed

Lines changed: 63 additions & 63 deletions

File tree

‎editor/src/messages/portfolio/document/utility_types/network_interface/queries.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ impl NodeNetworkInterface {
6262
layer_paths
6363
}
6464

65+
/// The path of every node in the document's networks made from the definition.
66+
pub fn node_paths_with_reference(&self, reference: &DefinitionIdentifier) -> Vec<Vec<NodeId>> {
67+
let mut node_paths = Vec::new();
68+
self.for_each_network(&mut |network_path, network_metadata| {
69+
for node_id in network_metadata.persistent_metadata.node_metadata.keys() {
70+
if self.reference(node_id, network_path).as_ref() == Some(reference) {
71+
node_paths.push([network_path, &[*node_id]].concat());
72+
}
73+
}
74+
});
75+
node_paths
76+
}
77+
6578
fn for_each_layer(&self, visit: &mut impl FnMut(&[NodeId], NodeId)) {
6679
self.for_each_network(&mut |network_path, network_metadata| {
6780
for (node_id, node_metadata) in &network_metadata.persistent_metadata.node_metadata {

‎editor/src/node_graph_executor.rs‎

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::messages::frontend::utility_types::{ExportBounds, FileType, RasterizedImage, RenderStatus};
2+
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
23
use crate::messages::portfolio::document::node_graph::utility_types::NodeEvaluationError;
34
use crate::messages::portfolio::document::utility_types::layers_in_view::LayersInView;
4-
use crate::messages::portfolio::document::utility_types::network_interface::InputConnector;
5+
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface};
56
use crate::messages::prelude::*;
67
use glam::{DAffine2, DVec2, UVec2};
78
use graph_craft::document::value::{RenderOutput, RenderOutputType, TaggedValue};
@@ -10,12 +11,12 @@ use graph_craft::proto::GraphErrors;
1011
use graphene_std::application_io::{ExportFormat, RenderConfig, TimingInformation};
1112
use graphene_std::bounds::RenderBoundingBox;
1213
use graphene_std::color::SRGBA8;
13-
use graphene_std::list::List;
14+
use graphene_std::list::{Item, List};
1415
use graphene_std::raster::{CPU, Raster};
1516
use graphene_std::renderer::{RenderMetadata, graphic_list_bounding_box};
1617
use graphene_std::transform::Footprint;
17-
use graphene_std::vector::{Vector, VectorGeometry, graphic_types, no_paths, paths_from_list_row_attributes};
18-
use graphene_std::{ATTR_TRANSFORM, ContextOverrides, Graphic};
18+
use graphene_std::vector::{Vector, VectorGeometry, graphic_types, no_paths, path, paths_from_list_row_attributes};
19+
use graphene_std::{ATTR_TRANSFORM, ContextOverrides, Graphic, NodeParameter};
1920
use interpreted_executor::dynamic_executor::ResolvedDocumentNodeTypesDelta;
2021
use std::any::Any;
2122
use std::sync::Arc;
@@ -38,7 +39,6 @@ pub struct ExecutionResponse {
3839
responses: VecDeque<FrontendMessage>,
3940
/// The layers whose thumbnails the runtime let go of, which it renders anew if they have content to show again.
4041
dropped_thumbnails: Vec<NodeId>,
41-
vector_modify: HashMap<NodeId, VectorGeometry>,
4242
/// The latest result of each observation.
4343
observations: HashMap<ObservationKey, InspectResult>,
4444
}
@@ -48,6 +48,8 @@ pub struct ExecutionResponse {
4848
pub enum ObservationKey {
4949
/// The node the Data panel inspects.
5050
DataPanel,
51+
/// The content of a 'Path' node, which is the geometry the Pen and Path tools edit.
52+
PathContent(NodeId),
5153
// TODO: Eventually remove this document upgrade code
5254
/// The "Fill" node whose geometry a gradient migration measures.
5355
FillMeasurement,
@@ -258,7 +260,7 @@ impl NodeGraphExecutor {
258260
resources,
259261
previewed: Vec::new(),
260262
layers: document.network_interface.layer_paths(),
261-
observations: HashMap::new(),
263+
observations: self.observations(&document.network_interface),
262264
}))
263265
.map_err(|e| e.to_string())?;
264266
Ok(instrumented)
@@ -288,7 +290,7 @@ impl NodeGraphExecutor {
288290
resources,
289291
previewed,
290292
layers,
291-
observations: self.observations(),
293+
observations: self.observations(&document.network_interface),
292294
}))
293295
.map_err(|e| e.to_string())?;
294296
} else if inspected_node_changed {
@@ -314,8 +316,9 @@ impl NodeGraphExecutor {
314316
}
315317

316318
/// Every observation a graph update of the document starts with.
317-
fn observations(&self) -> HashMap<ObservationKey, Observation> {
318-
self.data_panel_observation().map(|observation| (ObservationKey::DataPanel, observation)).into_iter().collect()
319+
fn observations(&self, network_interface: &NodeNetworkInterface) -> HashMap<ObservationKey, Observation> {
320+
let data_panel = self.data_panel_observation().map(|observation| (ObservationKey::DataPanel, observation));
321+
data_panel.into_iter().chain(path_content_observations(network_interface)).collect()
319322
}
320323

321324
/// Adds an evaluate request for whatever current network is cached.
@@ -483,7 +486,7 @@ impl NodeGraphExecutor {
483486
resources,
484487
previewed,
485488
layers: document.network_interface.layer_paths(),
486-
observations: self.observations(),
489+
observations: self.observations(&document.network_interface),
487490
}))
488491
.map_err(|e| e.to_string())?;
489492
let execution_id = self.queue_execution(render_config);
@@ -518,7 +521,6 @@ impl NodeGraphExecutor {
518521
result,
519522
responses: existing_responses,
520523
dropped_thumbnails,
521-
vector_modify,
522524
mut observations,
523525
} = *execution_response;
524526
all_dropped_thumbnails.extend(dropped_thumbnails.iter().copied());
@@ -645,7 +647,7 @@ impl NodeGraphExecutor {
645647
None => responses.add(response),
646648
}
647649
}
648-
document.network_interface.update_vector_modify(vector_modify);
650+
document.network_interface.update_vector_modify(path_contents(&observations));
649651

650652
match (node_graph_output, execution_context.export_config) {
651653
(Some(node_graph_output), Some(export_config)) => self.process_export(node_graph_output, export_config, document, responses),
@@ -1179,6 +1181,37 @@ fn measure_fill_geometry(data: &Arc<dyn Any + Send + Sync>) -> Option<(DAffine2,
11791181
None
11801182
}
11811183

1184+
fn path_content_observations(network_interface: &NodeNetworkInterface) -> impl Iterator<Item = (ObservationKey, Observation)> {
1185+
let path_nodes = network_interface.node_paths_with_reference(&DefinitionIdentifier::ProtoNode(path::IDENTIFIER));
1186+
1187+
path_nodes.into_iter().filter_map(|node_path| {
1188+
let key = ObservationKey::PathContent(*node_path.last()?);
1189+
let observation = Observation {
1190+
node_path,
1191+
connector: ObservedConnector::Input(path::ContentInput::INDEX),
1192+
overrides: ContextOverrides::default(),
1193+
};
1194+
Some((key, observation))
1195+
})
1196+
}
1197+
1198+
/// The incoming geometry of each 'Path' node, read from its observed content.
1199+
fn path_contents(observations: &HashMap<ObservationKey, InspectResult>) -> HashMap<NodeId, VectorGeometry> {
1200+
observations
1201+
.iter()
1202+
.filter_map(|(key, result)| {
1203+
let ObservationKey::PathContent(path_node) = *key else { return None };
1204+
let value = result.data.as_ref()?;
1205+
1206+
let geometry = match value.downcast_ref::<List<Vector>>() {
1207+
Some(list) => VectorGeometry::new(list.element(0).cloned().unwrap_or_default(), paths_from_list_row_attributes(list, 0).cloned().unwrap_or_default()),
1208+
None => VectorGeometry::from_item(value.downcast_ref::<Item<Vector>>()?),
1209+
};
1210+
Some((path_node, geometry))
1211+
})
1212+
.collect()
1213+
}
1214+
11821215
// Re-export for usage by tests in other modules
11831216
#[cfg(test)]
11841217
pub use test::Instrumented;

‎editor/src/node_graph_executor/runtime.rs‎

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@ use graph_craft::application_io::{PlatformApplicationIo, PlatformEditorApi};
88
use graph_craft::document::value::{RenderOutput, RenderOutputType, TaggedValue};
99
use graph_craft::document::{NodeId, NodeNetwork};
1010
use graph_craft::graphene_compiler::{CompileError, CompiledNetwork, Compiler};
11-
use graph_craft::proto::{ConstructionArgs, GraphErrors};
11+
use graph_craft::proto::GraphErrors;
1212
use graphene_hash::CacheHash;
1313
use graphene_std::application_io::{ApplicationIo, ExportFormat, Texture};
14-
use graphene_std::list::{Item, List};
1514
use graphene_std::ops::ConvertAsync;
1615
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
1716
use graphene_std::platform_application_io::canvas_utils::{Canvas, CanvasSurface, CanvasSurfaceHandle};
1817
use graphene_std::raster_types::Raster;
1918
use graphene_std::runtime::AsyncRuntime;
2019
use graphene_std::vector::style::RenderMode;
21-
use graphene_std::vector::{Vector, VectorGeometry, path, paths_from_list_row_attributes};
22-
use graphene_std::{Context, NodeError, NodeParameter, Poll};
20+
use graphene_std::{Context, NodeError, Poll};
2321
use interpreted_executor::dynamic_executor::{DynamicExecutor, ResolvedDocumentNodeTypesDelta};
2422
use interpreted_executor::util::wrap_network_in_scope;
2523
use observer::Observer;
@@ -56,18 +54,13 @@ pub struct NodeRuntime {
5654
resources: ResourceRegistry,
5755
node_graph_errors: GraphErrors,
5856
node_graph_warnings: GraphErrors,
59-
/// Each Path node with the proto node feeding its content, which gives the geometry the node's edits apply to.
60-
path_nodes: Vec<(NodeId, NodeId)>,
6157
thumbnails: Thumbnails,
6258
observer: Observer<ObservationKey>,
6359
/// Whether an observation changed since its results were last sent.
6460
observations_changed: bool,
6561

6662
preprocessor: preprocessor::Preprocessor,
6763

68-
vector_modify: HashMap<NodeId, VectorGeometry>,
69-
vector_evaluations: HashMap<NodeId, (NodeId, u64)>,
70-
7164
/// Cached surface for Wasm viewport rendering (reused across frames)
7265
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
7366
wasm_canvas_cache: CanvasSurfaceHandle,
@@ -155,15 +148,12 @@ impl NodeRuntime {
155148

156149
node_graph_errors: Vec::new(),
157150
node_graph_warnings: Vec::new(),
158-
path_nodes: Vec::new(),
159151
thumbnails: Thumbnails::new(),
160152
observer: Observer::default(),
161153
observations_changed: false,
162154

163155
preprocessor: preprocessor::Preprocessor::new(),
164156

165-
vector_modify: Default::default(),
166-
vector_evaluations: Default::default(),
167157
#[cfg(all(target_family = "wasm", feature = "gpu"))]
168158
wasm_canvas_cache: CanvasSurfaceHandle::new(),
169159
#[cfg(all(target_family = "wasm", feature = "gpu"))]
@@ -376,7 +366,6 @@ impl NodeRuntime {
376366
result: ExecutionResult::Panic(payload),
377367
responses: VecDeque::new(),
378368
dropped_thumbnails: Vec::new(),
379-
vector_modify: HashMap::new(),
380369
observations: HashMap::new(),
381370
};
382371
self.sender.send(NodeGraphUpdate::ExecutionResponse(Box::new(response))).expect("Failed to send response");
@@ -388,15 +377,14 @@ impl NodeRuntime {
388377

389378
async fn respond(&mut self, execution_id: u64, result: ExecutionResult) {
390379
let mut responses = VecDeque::new();
391-
let dropped_thumbnails = self.process_path_nodes_and_thumbnails(&mut responses).await;
380+
let dropped_thumbnails = self.update_thumbnails(&mut responses).await;
392381
let observations = self.observer.evaluate(&self.executor, self.old_graph.as_ref());
393382

394383
let response = ExecutionResponse {
395384
execution_id,
396385
result,
397386
responses,
398387
dropped_thumbnails,
399-
vector_modify: self.vector_modify.clone(),
400388
observations,
401389
};
402390
self.sender.send(NodeGraphUpdate::ExecutionResponse(Box::new(response))).expect("Failed to send response");
@@ -429,17 +417,6 @@ impl NodeRuntime {
429417
Err(CompileError::Message(message)) => return Err((ResolvedDocumentNodeTypesDelta::default(), message)),
430418
};
431419
self.node_graph_warnings = warnings;
432-
self.path_nodes = proto_network
433-
.nodes
434-
.iter()
435-
.filter(|(_, node)| node.identifier == path::IDENTIFIER)
436-
.filter_map(|(_, node)| {
437-
let path_node = *node.original_location.path.as_ref()?.last()?;
438-
let ConstructionArgs::Nodes(inputs) = &node.construction_args else { return None };
439-
440-
Some((path_node, *inputs.get(path::ContentInput::INDEX)?))
441-
})
442-
.collect();
443420

444421
assert_ne!(proto_network.nodes.len(), 0, "No proto nodes exist?");
445422
let result = self.executor.update(proto_network).map_err(|(types, e)| {
@@ -470,32 +447,9 @@ impl NodeRuntime {
470447
EvaluationErrors(errors.into())
471448
}
472449

473-
/// Updates state data, giving back the layers whose thumbnails were dropped because they no longer have content to show.
474-
async fn process_path_nodes_and_thumbnails(&mut self, responses: &mut VecDeque<FrontendMessage>) -> Vec<NodeId> {
450+
/// Renders the stale thumbnails, giving back the layers whose thumbnails were dropped because they no longer have content to show.
451+
async fn update_thumbnails(&mut self, responses: &mut VecDeque<FrontendMessage>) -> Vec<NodeId> {
475452
let dropped_thumbnails = self.thumbnails.drop_sourceless();
476-
477-
for &(path_node, content_node) in &self.path_nodes {
478-
let tree = self.executor.tree();
479-
let Ok(Some(context)) = tree.last_context(content_node) else { continue };
480-
let context_hash = context_hash(&context);
481-
if self.vector_evaluations.get(&path_node) == Some(&(content_node, context_hash)) {
482-
continue;
483-
}
484-
485-
let Some(output) = tree.evaluate(content_node, &context).ok().and_then(evaluated_output) else {
486-
continue;
487-
};
488-
let geometry = if let Some(list) = output.downcast_ref::<List<Vector>>() {
489-
VectorGeometry::new(list.element(0).cloned().unwrap_or_default(), paths_from_list_row_attributes(list, 0).cloned().unwrap_or_default())
490-
} else if let Some(item) = output.downcast_ref::<Item<Vector>>() {
491-
VectorGeometry::from_item(item)
492-
} else {
493-
continue;
494-
};
495-
self.vector_modify.insert(path_node, geometry);
496-
self.vector_evaluations.insert(path_node, (content_node, context_hash));
497-
}
498-
499453
self.thumbnails.render_stale(&self.executor, &self.editor_api, responses).await;
500454

501455
dropped_thumbnails

0 commit comments

Comments
 (0)