This commit is contained in:
Timon
2026-06-17 11:58:08 +00:00
parent b092ba6751
commit 5df2bc14f0
+43 -74
View File
@@ -1,13 +1,44 @@
use core_types::ProtoNodeIdentifier;
use graph_craft::application_io::PlatformEditorApi; use graph_craft::application_io::PlatformEditorApi;
use graph_craft::concrete; use graph_craft::concrete;
use graph_craft::document::value::TaggedValue; use graph_craft::document::value::TaggedValue;
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeInput, NodeNetwork}; use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeInput, NodeNetwork};
use graph_craft::generic; use graph_craft::generic;
use graphene_std::Context; use graphene_std::Context;
use graphene_std::ContextFeatures; use graphene_std::ContextDependencies;
use graphene_std::registry::{NODE_METADATA, RegistryValueSource};
use graphene_std::uuid::NodeId; use graphene_std::uuid::NodeId;
use std::sync::Arc; use std::sync::Arc;
fn proto_node_template(identifier: ProtoNodeIdentifier, regular_inputs: Vec<NodeInput>) -> DocumentNode {
let metadata_lock = NODE_METADATA.lock().unwrap();
let metadata = metadata_lock
.get(&identifier)
.unwrap_or_else(|| panic!("Node `{}` not registered in NODE_METADATA", identifier.as_str()));
let mut regular_iter = regular_inputs.into_iter();
let inputs: Vec<NodeInput> = metadata
.fields
.iter()
.map(|field| match &field.value_source {
RegistryValueSource::Scope(name) => NodeInput::scope(*name),
_ => regular_iter
.next()
.unwrap_or_else(|| panic!("Not enough non-scope inputs for `{}`", identifier.as_str())),
})
.collect();
assert!(regular_iter.next().is_none(), "Too many non-scope inputs for `{}`", identifier.as_str());
let context_features = ContextDependencies::from(metadata.context_features.as_slice());
DocumentNode {
inputs,
implementation: DocumentNodeImplementation::ProtoNode(identifier),
context_features,
..Default::default()
}
}
pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEditorApi>) -> NodeNetwork { pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEditorApi>) -> NodeNetwork {
let inner_network = DocumentNode { let inner_network = DocumentNode {
implementation: DocumentNodeImplementation::Network(network), implementation: DocumentNodeImplementation::Network(network),
@@ -15,84 +46,22 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
..Default::default() ..Default::default()
}; };
// TODO: Replace with "Output" definition? let output_node = DocumentNode {
// let render_node = resolve_document_node_type("Output")
// .expect("Output node type not found")
// .node_template_input_override(vec![Some(NodeInput::node(NodeId(1), 0)), Some(NodeInput::node(NodeId(0), 1))])
// .document_node;
let render_node = DocumentNode {
inputs: vec![NodeInput::node(NodeId(0), 0)], inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::Network(NodeNetwork { implementation: DocumentNodeImplementation::Network(NodeNetwork {
exports: vec![NodeInput::node(NodeId(5), 0)], exports: vec![NodeInput::node(NodeId(5), 0)],
nodes: [ nodes: [
DocumentNode { proto_node_template(
call_argument: concrete!(Context), graphene_std::render_node::render_intermediate::IDENTIFIER,
inputs: vec![NodeInput::import(core_types::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0)], vec![NodeInput::import(core_types::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render_intermediate::IDENTIFIER), ),
context_features: graphene_std::ContextDependencies { proto_node_template(graphene_std::render_node::render::IDENTIFIER, vec![NodeInput::node(NodeId(0), 0)]),
extract: ContextFeatures::VARARGS, proto_node_template(graphene_std::render_cache::render_output_cache::IDENTIFIER, vec![NodeInput::node(NodeId(1), 0)]),
inject: ContextFeatures::INDEX, proto_node_template(graphene_std::render_pixel_preview::render_pixel_preview::IDENTIFIER, vec![NodeInput::node(NodeId(2), 0)]),
}, proto_node_template(graphene_std::render_background::render_background::IDENTIFIER, vec![NodeInput::node(NodeId(3), 0)]),
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![NodeInput::scope(graphene_std::platform_application_io::try_wgpu_executor::IDENTIFIER), NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
inject: ContextFeatures::empty(),
},
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![
NodeInput::scope(graphene_std::platform_application_io::try_wgpu_executor::IDENTIFIER),
NodeInput::scope(graphene_std::platform_application_io::editor_api::IDENTIFIER),
NodeInput::node(NodeId(1), 0),
],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_cache::render_output_cache::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
inject: ContextFeatures::VARARGS,
},
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![NodeInput::scope(graphene_std::render_pixel_preview::pixel_preview_pipeline::IDENTIFIER), NodeInput::node(NodeId(2), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_pixel_preview::render_pixel_preview::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
inject: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
},
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![
NodeInput::scope(graphene_std::render_background::composite_background_pipeline::IDENTIFIER),
NodeInput::node(NodeId(3), 0),
],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_background::render_background::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
inject: ContextFeatures::empty(),
},
..Default::default()
},
DocumentNode { DocumentNode {
call_argument: concrete!(graphene_std::application_io::RenderConfig), call_argument: concrete!(graphene_std::application_io::RenderConfig),
inputs: vec![NodeInput::node(NodeId(4), 0)], ..proto_node_template(graphene_std::render_node::create_context::IDENTIFIER, vec![NodeInput::node(NodeId(4), 0)])
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::create_context::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
// We add the extract index annotation here to force the compiler to add a context nullification node before this node so the render context is properly nullified so the render cache node can do its's work
extract: ContextFeatures::INDEX,
inject: ContextFeatures::REAL_TIME | ContextFeatures::ANIMATION_TIME | ContextFeatures::POINTER_POSITION | ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
},
..Default::default()
}, },
] ]
.into_iter() .into_iter()
@@ -107,7 +76,7 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
// wrap the inner network in a scope // wrap the inner network in a scope
let nodes = vec![ let nodes = vec![
inner_network, inner_network,
render_node, output_node,
DocumentNode { DocumentNode {
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::ops::passthrough::IDENTIFIER), implementation: DocumentNodeImplementation::ProtoNode(graphene_std::ops::passthrough::IDENTIFIER),
inputs: vec![NodeInput::value(TaggedValue::EditorApi(editor_api), false)], inputs: vec![NodeInput::value(TaggedValue::EditorApi(editor_api), false)],