Introduce the new brush stroke data types (#4467)

* Add the brush stroke format types

* Route brush strokes through the node graph

* Store brush style as per-item attributes instead of a struct
This commit is contained in:
Timon
2026-08-27 15:19:01 +00:00
committed by GitHub
parent 96cc520c4b
commit 10256dd22c
19 changed files with 317 additions and 6 deletions

View File

@@ -13,8 +13,10 @@ serde = ["dep:serde", "core-types/serde", "raster-types/serde", "raster-nodes/se
[dependencies]
# Local dependencies
dyn-any = { workspace = true }
brush-types = { workspace = true }
core-types = { workspace = true }
graphene-hash = { workspace = true }
graphic-types = { workspace = true }
raster-types = { workspace = true }
raster-nodes = { workspace = true }
node-macro = { workspace = true }

View File

@@ -1,7 +1,33 @@
use core_types::list::{ATTR_COLOR, ATTR_DIAMETER, ATTR_FLOW, ATTR_HARDNESS, Item, List};
use core_types::registry::types::Percentage;
use core_types::{Color, Ctx};
use graphic_types::Graphic;
pub mod brush;
mod brush_cache;
pub mod brush_stroke;
pub use brush_types::*;
#[node_macro::node(category("Raster: Brush"))]
fn brush_strokes(
_: impl Ctx,
strokes: List<Stroke>,
color: List<Color>,
#[default(40.)] diameter: Item<f64>,
#[default(0.)] hardness: Item<Percentage>,
#[default(100.)] flow: Item<Percentage>,
) -> List<Graphic> {
let (diameter, hardness, flow) = (diameter.into_element(), hardness.into_element(), flow.into_element());
List::new_from_item(
Item::new_from_element(Graphic::from(strokes))
.with_attribute(ATTR_COLOR, color.element(0).copied().unwrap_or_default())
.with_attribute(ATTR_DIAMETER, diameter.max(0.))
.with_attribute(ATTR_HARDNESS, (hardness / 100.).clamp(0., 1.))
.with_attribute(ATTR_FLOW, (flow / 100.).clamp(0., 1.)),
)
}
pub mod migrations {
use crate::brush_stroke::BrushStroke;

View File

@@ -8,6 +8,7 @@ authors.workspace = true
[dependencies]
# Local dependencies
core-types = { workspace = true }
brush-types = { workspace = true }
graphic-types = { workspace = true }
vector-types = { workspace = true }
raster-types = { workspace = true }

View File

@@ -1,3 +1,4 @@
use brush_types::Stroke;
use core_types::bounds::{BoundingBox, RenderBoundingBox};
use core_types::list::{AttributeValueDyn, Item, List, ListDyn, NodeIdPath};
use core_types::registry::types::{Angle, SeedValue, SignedInteger};
@@ -870,6 +871,7 @@ pub async fn extend<T: 'n + Send + Clone>(
List<Color>,
List<Gradient>,
List<Artboard>,
List<Stroke>,
)]
base: List<T>,
/// The list whose items will appear at the end of the extended list.
@@ -890,6 +892,7 @@ pub async fn extend<T: 'n + Send + Clone>(
List<Color>,
List<Gradient>,
List<Artboard>,
List<Stroke>,
)]
new: List<T>,
) -> List<T> {
@@ -942,6 +945,7 @@ pub async fn into_group<T: Into<Graphic> + 'n>(
List<String>,
List<DVec2>,
Item<DAffine2>, // TODO: Remove this
List<Stroke>,
)]
content: T,
) -> Item<Graphic> {

View File

@@ -268,6 +268,8 @@ fn flatten_vector(graphic_list: &List<Graphic>) -> List<Vector> {
// Rasters, colors, and gradients bound no region, so they contribute no operand
Graphic::None(_) | Graphic::NoneList(_) | Graphic::RasterCPU(_) | Graphic::RasterGPU(_) | Graphic::Color(_) | Graphic::Gradient(_) => Vec::new(),
Graphic::RasterCPUList(_) | Graphic::RasterGPUList(_) | Graphic::ColorList(_) | Graphic::GradientList(_) => Vec::new(),
// Strokes have no vector outline representation; a brush node renders them to rasters
Graphic::StrokeList(_) => Vec::new(),
// Normalized to GraphicList above
Graphic::Graphic(_) => Vec::new(),
}