Skip to content

Commit 4d2e1d5

Browse files
mTvare6Keavon
andauthored
Instance table refactor part 6: remove usage of one_instance_* functions (#2672)
* Refactor the spline node * Refactor the jitter_points node * Refactor the morph node * Refactor the merge_by_distance node * Refactor the area node * Refactor the centroid node * Refactor the bevel node * Refactor the tests * Code review * Refactor the morph node * Refactor the extend_image_to_bounds and sample_image node * Refactor the dehaze node * Refactor the blur node * Refactor the vector_points node * Refactor the blit node * Refactor the blend_gpu_image node * Refactor the path_modify node * Refactor the image_color_palette * Fix copy_to_points * Code review * Partially make progress toward fixing the Draw Canvas node --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent fbefa5b commit 4d2e1d5

File tree

14 files changed

+639
-587
lines changed

14 files changed

+639
-587
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
609609
nodes: [
610610
DocumentNode {
611611
inputs: vec![NodeInput::network(concrete!(ImageFrameTable<Color>), 0)],
612-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, ImageFrameTable>")),
612+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, ImageFrameTable<SRGBA8>>")),
613613
..Default::default()
614614
},
615615
DocumentNode {
@@ -647,7 +647,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
647647
node_metadata: [
648648
DocumentNodeMetadata {
649649
persistent_metadata: DocumentNodePersistentMetadata {
650-
display_name: "Convert Image Frame".to_string(),
650+
display_name: "Into".to_string(),
651651
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
652652
..Default::default()
653653
},

node-graph/gcore/src/graphic_element.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ impl AlphaBlending {
3636
blend_mode: BlendMode::Normal,
3737
}
3838
}
39+
40+
pub fn lerp(&self, other: &Self, t: f32) -> Self {
41+
let lerp = |a: f32, b: f32, t: f32| a + (b - a) * t;
42+
43+
AlphaBlending {
44+
opacity: lerp(self.opacity, other.opacity, t),
45+
blend_mode: if t < 0.5 { self.blend_mode } else { other.blend_mode },
46+
}
47+
}
3948
}
4049

4150
// TODO: Eventually remove this migration document upgrade code

node-graph/gcore/src/instances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct InstanceMut<'a, T> {
204204
pub source_node_id: &'a mut Option<NodeId>,
205205
}
206206

207-
#[derive(Copy, Clone, Debug)]
207+
#[derive(Copy, Clone, Default, Debug)]
208208
pub struct Instance<T> {
209209
pub instance: T,
210210
pub transform: DAffine2,

node-graph/gcore/src/raster/image.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::Color;
22
use super::discrete_srgb::float_to_srgb_u8;
33
use crate::AlphaBlending;
44
use crate::GraphicElement;
5-
use crate::instances::Instances;
5+
use crate::instances::{Instance, Instances};
66
use crate::transform::TransformMut;
77
use alloc::vec::Vec;
88
use core::hash::{Hash, Hasher};
@@ -393,6 +393,23 @@ impl From<Image<Color>> for Image<SRGBA8> {
393393
}
394394
}
395395

396+
impl From<ImageFrameTable<Color>> for ImageFrameTable<SRGBA8> {
397+
fn from(image_frame_table: ImageFrameTable<Color>) -> Self {
398+
let mut result_table = ImageFrameTable::<SRGBA8>::empty();
399+
400+
for image_frame_instance in image_frame_table.instance_iter() {
401+
result_table.push(Instance {
402+
instance: image_frame_instance.instance.into(),
403+
transform: image_frame_instance.transform,
404+
alpha_blending: image_frame_instance.alpha_blending,
405+
source_node_id: image_frame_instance.source_node_id,
406+
});
407+
}
408+
409+
result_table
410+
}
411+
}
412+
396413
impl From<Image<SRGBA8>> for Image<Color> {
397414
fn from(image: Image<SRGBA8>) -> Self {
398415
let data = image.data.into_iter().map(|x| x.into()).collect();

node-graph/gcore/src/vector/vector_data/modification.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::*;
22
use crate::Ctx;
3-
use crate::transform::TransformMut;
43
use crate::uuid::generate_uuid;
54
use bezier_rs::BezierHandles;
65
use core::hash::BuildHasher;
@@ -425,14 +424,10 @@ impl core::hash::Hash for VectorModification {
425424
/// A node that applies a procedural modification to some [`VectorData`].
426425
#[node_macro::node(category(""))]
427426
async fn path_modify(_ctx: impl Ctx, mut vector_data: VectorDataTable, modification: Box<VectorModification>) -> VectorDataTable {
428-
let vector_data_transform = *vector_data.one_instance_ref().transform;
429-
let vector_data = vector_data.one_instance_mut().instance;
430-
431-
modification.apply(vector_data);
432-
433-
let mut result = VectorDataTable::new(vector_data.clone());
434-
*result.transform_mut() = vector_data_transform;
435-
result
427+
for mut vector_data_instance in vector_data.instance_mut_iter() {
428+
modification.apply(&mut vector_data_instance.instance);
429+
}
430+
vector_data
436431
}
437432

438433
#[test]

0 commit comments

Comments
 (0)