mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 03:48:11 +08:00
Imaginate fixes (#1200)
This commit is contained in:
@@ -981,7 +981,7 @@ impl DocumentMessageHandler {
|
|||||||
// Check if we use the "Input Frame" node.
|
// Check if we use the "Input Frame" node.
|
||||||
// TODO: Remove once rasterization is moved into a 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_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
|
// 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 {
|
let response = if input_frame_connected_to_graph_output {
|
||||||
|
|||||||
@@ -131,12 +131,14 @@ impl NodeGraphExecutor {
|
|||||||
imaginate_node_path: Vec<NodeId>,
|
imaginate_node_path: Vec<NodeId>,
|
||||||
(document, document_id): (&mut DocumentMessageHandler, u64),
|
(document, document_id): (&mut DocumentMessageHandler, u64),
|
||||||
layer_path: Vec<LayerId>,
|
layer_path: Vec<LayerId>,
|
||||||
editor_api: EditorApi<'_>,
|
mut editor_api: EditorApi<'_>,
|
||||||
(preferences, persistent_data): (&PreferencesMessageHandler, &PersistentData),
|
(preferences, persistent_data): (&PreferencesMessageHandler, &PersistentData),
|
||||||
) -> Result<Message, String> {
|
) -> Result<Message, String> {
|
||||||
use crate::messages::portfolio::document::node_graph::IMAGINATE_NODE;
|
use crate::messages::portfolio::document::node_graph::IMAGINATE_NODE;
|
||||||
use graph_craft::imaginate_input::*;
|
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"));
|
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
|
// 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))?;
|
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 {
|
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))?)
|
Some(self.compute_input::<ImageFrame<Color>>(&network, &imaginate_node_path, get("Input Image"), Cow::Borrowed(&editor_api))?)
|
||||||
} else {
|
} else {
|
||||||
@@ -257,7 +260,7 @@ impl NodeGraphExecutor {
|
|||||||
let transform = DAffine2::IDENTITY;
|
let transform = DAffine2::IDENTITY;
|
||||||
let image_frame = ImageFrame { image, transform };
|
let image_frame = ImageFrame { image, transform };
|
||||||
let editor_api = EditorApi {
|
let editor_api = EditorApi {
|
||||||
image_frame: Some(&image_frame),
|
image_frame: Some(image_frame),
|
||||||
font_cache: Some(&persistent_data.1.font_cache),
|
font_cache: Some(&persistent_data.1.font_cache),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ impl<P: Copy + Pixel> ImageFrame<P> {
|
|||||||
pub const fn empty() -> Self {
|
pub const fn empty() -> Self {
|
||||||
Self {
|
Self {
|
||||||
image: Image::empty(),
|
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))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct EditorApi<'a> {
|
pub struct EditorApi<'a> {
|
||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[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))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
pub font_cache: Option<&'a FontCache>,
|
pub font_cache: Option<&'a FontCache>,
|
||||||
}
|
}
|
||||||
@@ -306,8 +306,8 @@ pub struct ExtractImageFrame;
|
|||||||
|
|
||||||
impl<'a: 'input, 'input> Node<'input, EditorApi<'a>> for ExtractImageFrame {
|
impl<'a: 'input, 'input> Node<'input, EditorApi<'a>> for ExtractImageFrame {
|
||||||
type Output = ImageFrame<Color>;
|
type Output = ImageFrame<Color>;
|
||||||
fn eval(&'input self, editor_api: EditorApi<'a>) -> Self::Output {
|
fn eval(&'input self, mut editor_api: EditorApi<'a>) -> Self::Output {
|
||||||
editor_api.image_frame.cloned().unwrap_or(ImageFrame::empty())
|
editor_api.image_frame.take().unwrap_or(ImageFrame::empty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user