Imaginate fixes (#1200)

This commit is contained in:
0HyperCube 2023-05-07 11:23:16 +01:00 committed by Keavon Chambers
parent c79cf41c28
commit d7c5658852
3 changed files with 10 additions and 7 deletions

View File

@ -981,7 +981,7 @@ impl DocumentMessageHandler {
// Check if we use the "Input Frame" node.
// TODO: Remove once rasterization is moved into a node.
let input_frame_node_id = node_network.nodes.iter().find(|(_, node)| node.name == "Input Frame").map(|(&id, _)| id);
let input_frame_connected_to_graph_output = input_frame_node_id.map_or(false, |target_node_id| node_network.connected_to_output(target_node_id, true));
let input_frame_connected_to_graph_output = input_frame_node_id.map_or(false, |target_node_id| node_network.connected_to_output(target_node_id, imaginate_node_path.is_none()));
// If the Input Frame node is connected upstream, rasterize the artwork below this layer by calling into JS
let response = if input_frame_connected_to_graph_output {

View File

@ -131,12 +131,14 @@ impl NodeGraphExecutor {
imaginate_node_path: Vec<NodeId>,
(document, document_id): (&mut DocumentMessageHandler, u64),
layer_path: Vec<LayerId>,
editor_api: EditorApi<'_>,
mut editor_api: EditorApi<'_>,
(preferences, persistent_data): (&PreferencesMessageHandler, &PersistentData),
) -> Result<Message, String> {
use crate::messages::portfolio::document::node_graph::IMAGINATE_NODE;
use graph_craft::imaginate_input::*;
let image = editor_api.image_frame.take();
let get = |name: &str| IMAGINATE_NODE.inputs.iter().position(|input| input.name == name).unwrap_or_else(|| panic!("Input {name} not found"));
// Get the node graph layer
@ -166,6 +168,7 @@ impl NodeGraphExecutor {
};
let use_base_image = self.compute_input::<bool>(&network, &imaginate_node_path, get("Adapt Input Image"), Cow::Borrowed(&editor_api))?;
editor_api.image_frame = image;
let input_image_frame: Option<ImageFrame<Color>> = if use_base_image {
Some(self.compute_input::<ImageFrame<Color>>(&network, &imaginate_node_path, get("Input Image"), Cow::Borrowed(&editor_api))?)
} else {
@ -257,7 +260,7 @@ impl NodeGraphExecutor {
let transform = DAffine2::IDENTITY;
let image_frame = ImageFrame { image, transform };
let editor_api = EditorApi {
image_frame: Some(&image_frame),
image_frame: Some(image_frame),
font_cache: Some(&persistent_data.1.font_cache),
};

View File

@ -245,7 +245,7 @@ impl<P: Copy + Pixel> ImageFrame<P> {
pub const fn empty() -> Self {
Self {
image: Image::empty(),
transform: DAffine2::ZERO,
transform: DAffine2::IDENTITY,
}
}
@ -281,7 +281,7 @@ use crate::text::FontCache;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EditorApi<'a> {
#[cfg_attr(feature = "serde", serde(skip))]
pub image_frame: Option<&'a ImageFrame<Color>>,
pub image_frame: Option<ImageFrame<Color>>,
#[cfg_attr(feature = "serde", serde(skip))]
pub font_cache: Option<&'a FontCache>,
}
@ -306,8 +306,8 @@ pub struct ExtractImageFrame;
impl<'a: 'input, 'input> Node<'input, EditorApi<'a>> for ExtractImageFrame {
type Output = ImageFrame<Color>;
fn eval(&'input self, editor_api: EditorApi<'a>) -> Self::Output {
editor_api.image_frame.cloned().unwrap_or(ImageFrame::empty())
fn eval(&'input self, mut editor_api: EditorApi<'a>) -> Self::Output {
editor_api.image_frame.take().unwrap_or(ImageFrame::empty())
}
}