Skip to content

Prototype document network level IntoNode insertion #2478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -2689,13 +2689,19 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
let Some(implementations) = &node_registry.get(&id) else { continue };
let valid_inputs: HashSet<_> = implementations.iter().map(|(_, node_io)| node_io.call_argument.clone()).collect();
let first_node_io = implementations.first().map(|(_, node_io)| node_io).unwrap_or(const { &NodeIOTypes::empty() });
let mut node_io_types = vec![HashSet::new(); fields.len()];
for (_, node_io) in implementations.iter() {
for (i, ty) in node_io.inputs.iter().enumerate() {
node_io_types[i].insert(ty.clone());
}
}
let mut input_type = &first_node_io.call_argument;
if valid_inputs.len() > 1 {
input_type = &const { generic!(D) };
}
let output_type = &first_node_io.return_value;

let inputs = fields
let inputs: Vec<_> = fields
.iter()
.zip(first_node_io.inputs.iter())
.enumerate()
Expand All @@ -2715,14 +2721,89 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
NodeInput::value(TaggedValue::None, true)
})
.collect();
let input_count = inputs.len();
let network_inputs = (0..input_count).map(|i| NodeInput::node(NodeId(i as u64), 0)).collect();
let identity_node = ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode");
let into_node_registry = &interpreted_executor::node_registry::NODE_REGISTRY;
let mut nodes: HashMap<_, _, _> = node_io_types
.iter()
.enumerate()
.map(|(i, inputs)| {
(
NodeId(i as u64),
match inputs.len() {
1 => {
let input = inputs.iter().next().unwrap();
let input_ty = input.nested_type();
let into_node_identifier = ProtoNodeIdentifier {
name: format!("graphene_core::ops::IntoNode<{}>", input_ty.clone()).into(),
};
let proto_node = if into_node_registry.iter().any(|(ident, _)| {
let ident = ident.name.as_ref();
// log::debug!("checking: {} against {}", ident, into_node_identifier.name.as_ref());
ident == into_node_identifier.name.as_ref()
}) {
// log::debug!("placing {}", into_node_identifier.name.as_ref());
into_node_identifier
} else {
identity_node.clone()
};
DocumentNode {
inputs: vec![NodeInput::network(input.clone(), i)],
// manual_composition: Some(fn_input.clone()),
implementation: DocumentNodeImplementation::ProtoNode(proto_node),
visible: true,
..Default::default()
}
}
_ => DocumentNode {
inputs: vec![NodeInput::network(generic!(X), i)],
implementation: DocumentNodeImplementation::ProtoNode(identity_node.clone()),
visible: true,
..Default::default()
},
},
)
})
.collect();

let document_node = DocumentNode {
inputs: network_inputs,
manual_composition: Some(input_type.clone()),
implementation: DocumentNodeImplementation::ProtoNode(id.clone().into()),
visible: true,
skip_deduplication: false,
..Default::default()
};
let mut node_names: HashMap<NodeId, String> = nodes
.iter()
.map(|(id, node)| (*id, node.implementation.get_proto_node().unwrap().name.rsplit_once("::").unwrap().1.to_string()))
.collect();
nodes.insert(NodeId(input_count as u64), document_node);
node_names.insert(NodeId(input_count as u64), display_name.to_string());
let node_type_metadata = |id: NodeId| {
NodeTypePersistentMetadata::Node(NodePersistentMetadata::new(NodePosition::Absolute(if id.0 == input_count as u64 {
IVec2::default()
} else {
IVec2 { x: -10, y: id.0 as i32 }
})))
};

let node = DocumentNodeDefinition {
identifier: display_name,
node_template: NodeTemplate {
document_node: DocumentNode {
inputs,
manual_composition: Some(input_type.clone()),
implementation: DocumentNodeImplementation::ProtoNode(id.clone().into()),
implementation: DocumentNodeImplementation::Network(NodeNetwork {
exports: vec![NodeInput::Node {
node_id: NodeId(input_count as u64),
output_index: 0,
lambda: false,
}],
nodes,
scope_injections: Default::default(),
}),
visible: true,
skip_deduplication: false,
..Default::default()
Expand All @@ -2742,6 +2823,30 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
has_primary_output: true,
locked: false,

network_metadata: Some(NodeNetworkMetadata {
persistent_metadata: NodeNetworkPersistentMetadata {
node_metadata: node_names
.into_iter()
.map(|(id, display_name)| {
let node_type_metadata = node_type_metadata(id);
(
id,
DocumentNodeMetadata {
persistent_metadata: DocumentNodePersistentMetadata {
display_name,
node_type_metadata,
..Default::default()
},
..Default::default()
},
)
})
.collect(),
..Default::default()
},
..Default::default()
}),

..Default::default()
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6438,6 +6438,12 @@ pub struct NodePersistentMetadata {
position: NodePosition,
}

impl NodePersistentMetadata {
pub fn new(position: NodePosition) -> Self {
Self { position }
}
}

/// A layer can either be position as Absolute or in a Stack
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum LayerPosition {
Expand Down
Loading