Restore the Imaginate node with the full node graph architecture (but a flaky deadlock remains) (#1908)

* Rework imaginate trigger mechanism

* Fix imaginate generation
This commit is contained in:
Dennis Kobert
2024-08-07 03:23:00 -07:00
committed by GitHub
parent 8041b1237c
commit 06a409f1c5
8 changed files with 85 additions and 36 deletions
@@ -71,7 +71,9 @@ pub enum DocumentMessage {
GridOverlays(OverlayContext),
GridVisibility(bool),
GroupSelectedLayers,
ImaginateGenerate,
ImaginateGenerate {
imaginate_node: Vec<NodeId>,
},
ImaginateRandom {
imaginate_node: Vec<NodeId>,
then_generate: bool,
@@ -493,7 +493,17 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
responses.add(DocumentMessage::MoveSelectedLayersToGroup { parent: new_group_folder });
}
DocumentMessage::ImaginateGenerate => responses.add(PortfolioMessage::SubmitGraphRender { document_id, ignore_hash: false }),
DocumentMessage::ImaginateGenerate { imaginate_node } => {
let random_value = generate_uuid();
responses.add(NodeGraphMessage::SetInputValue {
node_id: *imaginate_node.last().unwrap(),
// Needs to match the index of the seed parameter in `pub const IMAGINATE_NODE: DocumentNodeDefinition` in `document_node_type.rs`
input_index: 17,
value: graph_craft::document::value::TaggedValue::U64(random_value),
});
responses.add(PortfolioMessage::SubmitGraphRender { document_id, ignore_hash: false });
}
DocumentMessage::ImaginateRandom { imaginate_node, then_generate } => {
// Generate a random seed. We only want values between -2^53 and 2^53, because integer values
// outside of this range can get rounded in f64
@@ -511,7 +521,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
// Generate the image
if then_generate {
responses.add(DocumentMessage::ImaginateGenerate);
responses.add(DocumentMessage::ImaginateGenerate { imaginate_node });
}
}
DocumentMessage::ImportSvg {
@@ -4272,14 +4272,14 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
DocumentNode {
inputs: vec![NodeInput::network(concrete!(ImageFrame<Color>), 0)],
implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_, _, _>"),
manual_composition: Some(generic!(T)),
manual_composition: Some(concrete!(())),
skip_deduplication: true,
..Default::default()
},
DocumentNode {
inputs: vec![
NodeInput::node(NodeId(0), 0),
NodeInput::scope("editor-api"),
NodeInput::network(concrete!(&WasmEditorApi), 1),
NodeInput::network(concrete!(ImaginateController), 2),
NodeInput::network(concrete!(f64), 3),
NodeInput::network(concrete!(Option<DVec2>), 4),
@@ -4295,8 +4295,9 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
NodeInput::network(concrete!(ImaginateMaskStartingFill), 14),
NodeInput::network(concrete!(bool), 15),
NodeInput::network(concrete!(bool), 16),
NodeInput::network(concrete!(u64), 17),
],
implementation: DocumentNodeImplementation::proto("graphene_std::raster::ImaginateNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
implementation: DocumentNodeImplementation::proto("graphene_std::raster::ImaginateNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
..Default::default()
},
]
@@ -4310,7 +4311,7 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
NodeInput::value(TaggedValue::ImageFrame(ImageFrame::empty()), true),
NodeInput::scope("editor-api"),
NodeInput::value(TaggedValue::ImaginateController(Default::default()), false),
NodeInput::value(TaggedValue::U64(0), false), // Remember to keep index used in `ImaginateRandom` updated with this entry's index
NodeInput::value(TaggedValue::F64(0.), false), // Remember to keep index used in `ImaginateRandom` updated with this entry's index
NodeInput::value(TaggedValue::OptionalDVec2(None), false),
NodeInput::value(TaggedValue::U32(30), false),
NodeInput::value(TaggedValue::ImaginateSamplingMethod(ImaginateSamplingMethod::EulerA), false),
@@ -4324,6 +4325,7 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeDefinition> = Lazy::new(|| DocumentN
NodeInput::value(TaggedValue::ImaginateMaskStartingFill(ImaginateMaskStartingFill::Fill), false),
NodeInput::value(TaggedValue::Bool(false), false),
NodeInput::value(TaggedValue::Bool(false), false),
NodeInput::value(TaggedValue::U64(0), false),
],
..Default::default()
},
@@ -1769,9 +1769,13 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
.tooltip("Fill layer frame by generating a new image")
.on_update({
let controller = controller.clone();
let imaginate_node = imaginate_node.clone();
move |_| {
controller.trigger_regenerate();
DocumentMessage::ImaginateGenerate.into()
DocumentMessage::ImaginateGenerate {
imaginate_node: imaginate_node.clone(),
}
.into()
}
})
.widget_holder(),
@@ -1781,9 +1785,13 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
.disabled(!matches!(imaginate_status, ImaginateStatus::ReadyDone))
.on_update({
let controller = controller.clone();
let imaginate_node = imaginate_node.clone();
move |_| {
controller.set_status(ImaginateStatus::Ready);
DocumentMessage::ImaginateGenerate.into()
DocumentMessage::ImaginateGenerate {
imaginate_node: imaginate_node.clone(),
}
.into()
}
})
.widget_holder(),
@@ -1858,8 +1866,8 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
let mut widgets = start_widgets(document_node, node_id, resolution_index, "Resolution", FrontendGraphDataType::Number, false);
let round = |x: DVec2| {
let (x, y) = pick_safe_imaginate_resolution(x.into());
let round = |size: DVec2| {
let (x, y) = pick_safe_imaginate_resolution(size.into());
DVec2::new(x as f64, y as f64)
};