Skip to content

Instance table refactor part 6: remove usage of one_instance_* functions #2672

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

Merged
merged 22 commits into from
May 29, 2025
Merged
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 @@ -609,7 +609,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
nodes: [
DocumentNode {
inputs: vec![NodeInput::network(concrete!(ImageFrameTable<Color>), 0)],
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, ImageFrameTable>")),
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, ImageFrameTable<SRGBA8>>")),
..Default::default()
},
DocumentNode {
Expand Down Expand Up @@ -647,7 +647,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
node_metadata: [
DocumentNodeMetadata {
persistent_metadata: DocumentNodePersistentMetadata {
display_name: "Convert Image Frame".to_string(),
display_name: "Into".to_string(),
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
..Default::default()
},
Expand Down
9 changes: 9 additions & 0 deletions node-graph/gcore/src/graphic_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ impl AlphaBlending {
blend_mode: BlendMode::Normal,
}
}

pub fn lerp(&self, other: &Self, t: f32) -> Self {
let lerp = |a: f32, b: f32, t: f32| a + (b - a) * t;

AlphaBlending {
opacity: lerp(self.opacity, other.opacity, t),
blend_mode: if t < 0.5 { self.blend_mode } else { other.blend_mode },
}
}
}

// TODO: Eventually remove this migration document upgrade code
Expand Down
2 changes: 1 addition & 1 deletion node-graph/gcore/src/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub struct InstanceMut<'a, T> {
pub source_node_id: &'a mut Option<NodeId>,
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Default, Debug)]
pub struct Instance<T> {
pub instance: T,
pub transform: DAffine2,
Expand Down
19 changes: 18 additions & 1 deletion node-graph/gcore/src/raster/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::Color;
use super::discrete_srgb::float_to_srgb_u8;
use crate::AlphaBlending;
use crate::GraphicElement;
use crate::instances::Instances;
use crate::instances::{Instance, Instances};
use crate::transform::TransformMut;
use alloc::vec::Vec;
use core::hash::{Hash, Hasher};
Expand Down Expand Up @@ -393,6 +393,23 @@ impl From<Image<Color>> for Image<SRGBA8> {
}
}

impl From<ImageFrameTable<Color>> for ImageFrameTable<SRGBA8> {
fn from(image_frame_table: ImageFrameTable<Color>) -> Self {
let mut result_table = ImageFrameTable::<SRGBA8>::empty();

for image_frame_instance in image_frame_table.instance_iter() {
result_table.push(Instance {
instance: image_frame_instance.instance.into(),
transform: image_frame_instance.transform,
alpha_blending: image_frame_instance.alpha_blending,
source_node_id: image_frame_instance.source_node_id,
});
}

result_table
}
}

impl From<Image<SRGBA8>> for Image<Color> {
fn from(image: Image<SRGBA8>) -> Self {
let data = image.data.into_iter().map(|x| x.into()).collect();
Expand Down
13 changes: 4 additions & 9 deletions node-graph/gcore/src/vector/vector_data/modification.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::Ctx;
use crate::transform::TransformMut;
use crate::uuid::generate_uuid;
use bezier_rs::BezierHandles;
use core::hash::BuildHasher;
Expand Down Expand Up @@ -425,14 +424,10 @@ impl core::hash::Hash for VectorModification {
/// A node that applies a procedural modification to some [`VectorData`].
#[node_macro::node(category(""))]
async fn path_modify(_ctx: impl Ctx, mut vector_data: VectorDataTable, modification: Box<VectorModification>) -> VectorDataTable {
let vector_data_transform = *vector_data.one_instance_ref().transform;
let vector_data = vector_data.one_instance_mut().instance;

modification.apply(vector_data);

let mut result = VectorDataTable::new(vector_data.clone());
*result.transform_mut() = vector_data_transform;
result
for mut vector_data_instance in vector_data.instance_mut_iter() {
modification.apply(&mut vector_data_instance.instance);
}
vector_data
}

#[test]
Expand Down
Loading
Loading