Extract gelement-nodes for nodes accepting both vector, raster and graphic element

This commit is contained in:
Firestar99 2025-07-01 17:03:27 +02:00 committed by Keavon Chambers
parent 4c75ddf936
commit 56ac8f3a68
16 changed files with 174 additions and 58 deletions

View file

@ -1,9 +1,7 @@
#[macro_use]
extern crate log;
pub mod animation;
pub mod blending;
pub mod blending_nodes;
pub mod bounds;
pub mod color;
pub mod consts;
@ -14,7 +12,6 @@ pub mod generic;
pub mod gradient;
pub mod graphic_element;
pub mod instances;
pub mod logic;
pub mod math;
pub mod memo;
pub mod misc;
@ -26,7 +23,6 @@ pub mod render_complexity;
pub mod structural;
pub mod text;
pub mod transform;
pub mod transform_nodes;
pub mod uuid;
pub mod value;
pub mod vector;

View file

@ -1,5 +1,4 @@
pub mod bezpath_algorithms;
pub mod instance;
pub mod merge_by_distance;
pub mod offset_subpath;
pub mod poisson_disk;

View file

@ -0,0 +1,32 @@
[package]
name = "graphene-element-nodes"
version = "0.1.0"
edition = "2024"
description = "graphene element nodes"
authors = ["Graphite Authors <contact@graphite.rs>"]
license = "MIT OR Apache-2.0"
[features]
default = ["serde"]
serde = ["dep:serde"]
[dependencies]
# Local dependencies
dyn-any = { workspace = true }
graphene-core = { workspace = true }
node-macro = { workspace = true }
bezier-rs = { workspace = true }
# Workspace dependencies
glam = { workspace = true }
specta = { workspace = true }
rand = { workspace = true }
log = { workspace = true }
# Optional workspace dependencies
serde = { workspace = true, optional = true, features = ["derive"] }
[dev-dependencies]
# Workspace dependencies
tokio = { workspace = true }
graphene-math-nodes = { workspace = true }

View file

@ -1,4 +1,4 @@
use crate::{Ctx, ExtractAnimationTime, ExtractTime};
use graphene_core::context::{Ctx, ExtractAnimationTime, ExtractTime};
const DAY: f64 = 1000. * 3600. * 24.;

View file

@ -1,8 +1,10 @@
use crate::raster::Image;
use crate::raster_types::{CPU, RasterDataTable};
use crate::registry::types::Percentage;
use crate::vector::VectorDataTable;
use crate::{BlendMode, Color, Ctx, GraphicElement, GraphicGroupTable};
use graphene_core::GraphicGroupTable;
use graphene_core::blending::BlendMode;
use graphene_core::color::Color;
use graphene_core::context::Ctx;
use graphene_core::raster_types::{CPU, RasterDataTable};
use graphene_core::registry::types::Percentage;
use graphene_core::vector::VectorDataTable;
pub(super) trait MultiplyAlpha {
fn multiply_alpha(&mut self, factor: f64);
@ -27,10 +29,7 @@ impl MultiplyAlpha for GraphicGroupTable {
}
}
}
impl MultiplyAlpha for RasterDataTable<CPU>
where
GraphicElement: From<Image<Color>>,
{
impl MultiplyAlpha for RasterDataTable<CPU> {
fn multiply_alpha(&mut self, factor: f64) {
for instance in self.instance_mut_iter() {
instance.alpha_blending.opacity *= factor as f32;

View file

@ -1,8 +1,11 @@
use crate::instances::{InstanceRef, Instances};
use crate::raster_types::{CPU, RasterDataTable};
use crate::vector::VectorDataTable;
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, GraphicElement, GraphicGroupTable, OwnedContextImpl};
use glam::DVec2;
use graphene_core::GraphicElement;
use graphene_core::GraphicGroupTable;
use graphene_core::context::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, OwnedContextImpl};
use graphene_core::instances::{InstanceRef, Instances};
use graphene_core::raster_types::{CPU, RasterDataTable};
use graphene_core::vector::VectorDataTable;
use log::warn;
#[node_macro::node(name("Instance on Points"), category("Instancing"), path(graphene_core::vector))]
async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
@ -99,11 +102,11 @@ async fn instance_index(ctx: impl Ctx + ExtractIndex) -> f64 {
#[cfg(test)]
mod test {
use super::*;
use crate::Node;
use crate::extract_xy::{ExtractXyNode, XY};
use crate::vector::VectorData;
use bezier_rs::Subpath;
use glam::DVec2;
use graphene_core::Node;
use graphene_core::extract_xy::{ExtractXyNode, XY};
use graphene_core::vector::VectorData;
use std::pin::Pin;
#[derive(Clone)]
@ -120,7 +123,7 @@ mod test {
#[tokio::test]
async fn instance_on_points_test() {
let owned = OwnedContextImpl::default().into_context();
let rect = crate::vector::generator_nodes::RectangleNode::new(
let rect = graphene_core::vector::generator_nodes::RectangleNode::new(
FutureWrapperNode(()),
ExtractXyNode::new(InstancePositionNode {}, FutureWrapperNode(XY::Y)),
FutureWrapperNode(2_f64),

View file

@ -0,0 +1,5 @@
pub mod animation;
pub mod blending_nodes;
pub mod instance;
pub mod logic;
pub mod transform_nodes;

View file

@ -1,13 +1,13 @@
use crate::ArtboardGroupTable;
use crate::Color;
use crate::GraphicElement;
use crate::GraphicGroupTable;
use crate::gradient::GradientStops;
use crate::graphene_core::registry::types::TextArea;
use crate::raster_types::{CPU, GPU, RasterDataTable};
use crate::vector::VectorDataTable;
use crate::{Context, Ctx};
use glam::{DAffine2, DVec2};
use graphene_core::ArtboardGroupTable;
use graphene_core::GraphicElement;
use graphene_core::GraphicGroupTable;
use graphene_core::color::Color;
use graphene_core::context::{Context, Ctx};
use graphene_core::gradient::GradientStops;
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
use graphene_core::registry::types::TextArea;
use graphene_core::vector::VectorDataTable;
#[node_macro::node(category("Text"))]
fn to_string<T: std::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f64, u32, u64, DVec2, VectorDataTable, DAffine2)] value: T) -> String {

View file

@ -1,10 +1,11 @@
use crate::instances::Instances;
use crate::raster_types::{CPU, GPU, RasterDataTable};
use crate::transform::{ApplyTransform, Footprint, Transform};
use crate::vector::VectorDataTable;
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
use core::f64;
use glam::{DAffine2, DVec2};
use graphene_core::GraphicGroupTable;
use graphene_core::context::{CloneVarArgs, Context, Ctx, ExtractAll, OwnedContextImpl};
use graphene_core::instances::Instances;
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
use graphene_core::transform::{ApplyTransform, Footprint, Transform};
use graphene_core::vector::VectorDataTable;
#[node_macro::node(category(""))]
async fn transform<T: 'n + 'static>(

View file

@ -16,6 +16,7 @@ loading = ["serde_json"]
# Local dependencies
dyn-any = { workspace = true }
graphene-core = { workspace = true }
graphene-element-nodes = { workspace = true }
graphene-path-bool = { workspace = true }
graphene-brush = { workspace = true }
graphene-application-io = { workspace = true }

View file

@ -224,7 +224,7 @@ tagged_value! {
XY(graphene_core::extract_xy::XY),
RedGreenBlue(graphene_raster_nodes::adjustments::RedGreenBlue),
RedGreenBlueAlpha(graphene_raster_nodes::adjustments::RedGreenBlueAlpha),
RealTimeMode(graphene_core::animation::RealTimeMode),
RealTimeMode(graphene_element_nodes::animation::RealTimeMode),
NoiseType(graphene_raster_nodes::adjustments::NoiseType),
FractalType(graphene_raster_nodes::adjustments::FractalType),
CellularDistanceFunction(graphene_raster_nodes::adjustments::CellularDistanceFunction),

View file

@ -34,6 +34,7 @@ graphene-svg-renderer = { workspace = true }
graphene-application-io = { workspace = true }
graphene-raster-nodes = { workspace = true }
graphene-brush = { workspace = true }
graphene-element-nodes = { workspace = true }
# Workspace dependencies
fastnoise-lite = { workspace = true }

View file

@ -8,6 +8,8 @@ pub use graphene_application_io as application_io;
pub use graphene_brush as brush;
pub use graphene_core::vector;
pub use graphene_core::*;
pub use graphene_element_nodes as element_nodes;
pub use graphene_element_nodes::animation;
pub use graphene_math_nodes as math_nodes;
pub use graphene_path_bool as path_bool;
pub use graphene_raster_nodes as raster_nodes;