Skip to content

Commit 48fb945

Browse files
committed
wip: add mesh enum
1 parent 6c5e3c9 commit 48fb945

6 files changed

Lines changed: 82 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
19431943
if let Fill::Gradient(gradient) = fill.clone() {
19441944
let mut row = vec![TextLabel::new("").widget_instance()];
19451945
match gradient.gradient_type {
1946-
GradientType::Linear => add_blank_assist(&mut row),
1946+
GradientType::Linear | GradientType::Mesh => add_blank_assist(&mut row),
19471947
GradientType::Radial => {
19481948
let orientation = if (gradient.end.x - gradient.start.x).abs() > f64::EPSILON * 1e6 {
19491949
gradient.end.x > gradient.start.x

editor/src/messages/tool/tool_messages/gradient_tool.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,14 @@ impl LayoutHolder for GradientTool {
174174
}
175175
.into()
176176
}),
177+
RadioEntryData::new("Mesh").label("Mesh").tooltip_label(" Gradient").on_update(move |_| {
178+
GradientToolMessage::UpdateOptions {
179+
options: GradientOptionsUpdate::Type(GradientType::Mesh),
180+
}
181+
.into()
182+
}),
177183
])
178-
.selected_index(Some((self.options.gradient_type == GradientType::Radial) as u32))
184+
.selected_index(Some(self.options.gradient_type as u32))
179185
.widget_instance();
180186

181187
let reverse_stops = IconButton::new("Reverse", 24)

node-graph/libraries/rendering/src/render_ext.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl RenderExt for Gradient {
7272
gradient_id, start.x, start.y, radius, stop
7373
);
7474
}
75+
_ => (),
7576
}
7677

7778
gradient_id

node-graph/libraries/rendering/src/renderer.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::fmt::Write;
2424
use std::hash::{Hash, Hasher};
2525
use std::ops::Deref;
2626
use std::sync::{Arc, LazyLock};
27-
use vector_types::gradient::GradientSpreadMethod;
27+
use vector_types::gradient::{self, GradientSpreadMethod};
2828
use vello::*;
2929

3030
/// Cached 16x16 transparency checkerboard image data (two 8x8 cells of #ffffff and #cccccc).
@@ -967,6 +967,15 @@ impl Render for Table<Vector> {
967967
}
968968
}
969969

970+
let is_mesh_fill = matches!(
971+
&row.element.style.fill,
972+
Fill::Gradient(g) if g.gradient_type == GradientType::Mesh
973+
);
974+
if is_mesh_fill {
975+
log::debug!("hoge");
976+
return;
977+
}
978+
970979
render.leaf_tag("path", |attributes| {
971980
attributes.push("d", path.clone());
972981
let matrix = format_transform_matrix(element_transform);
@@ -1159,6 +1168,12 @@ impl Render for Table<Vector> {
11591168
}
11601169
.into()
11611170
}
1171+
// TODO!!!!!!!!!!!!!!!!
1172+
GradientType::Mesh => peniko::LinearGradientPosition {
1173+
start: to_point(start),
1174+
end: to_point(end),
1175+
}
1176+
.into(),
11621177
},
11631178
extend: match gradient.spread_method {
11641179
GradientSpreadMethod::Pad => peniko::Extend::Pad,
@@ -1752,6 +1767,15 @@ impl Render for Table<GradientStops> {
17521767
r#"<radialGradient id="{gradient_id}" gradientUnits="userSpaceOnUse" cx="{cx}" cy="{cy}" r="{r}"{gradient_transform_attribute}>{stop_string}</radialGradient>"#
17531768
);
17541769
}
1770+
// TODO!!!!!!!!!!!!!!!!!!!!!!
1771+
GradientType::Mesh => {
1772+
let (x1, y1) = (start.x, start.y);
1773+
let (x2, y2) = (end.x, end.y);
1774+
let _ = write!(
1775+
&mut attributes.0.svg_defs,
1776+
r#"<linearGradient id="{gradient_id}" gradientUnits="userSpaceOnUse" x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}"{gradient_transform_attribute}>{stop_string}</linearGradient>"#
1777+
);
1778+
}
17551779
}
17561780

17571781
attributes.push("fill", format!("url('#{gradient_id}')"));

node-graph/libraries/vector-types/src/gradient.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub enum GradientType {
99
#[default]
1010
Linear,
1111
Radial,
12+
Mesh,
1213
}
1314

1415
// TODO: Someday we could switch this to a Box[T] to avoid over-allocation

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use kurbo::simplify::{SimplifyOptions, simplify_bezpath};
1414
use kurbo::{Affine, BezPath, DEFAULT_ACCURACY, Line, ParamCurve, ParamCurveArclen, PathEl, PathSeg, Shape};
1515
use rand::{Rng, SeedableRng};
1616
use std::collections::hash_map::DefaultHasher;
17+
use std::vec;
1718
use vector_types::subpath::{BezierHandles, ManipulatorGroup};
1819
use vector_types::vector::PointDomain;
1920
use vector_types::vector::algorithms::bezpath_algorithms::{self, TValue, eval_pathseg_euclidean, evaluate_bezpath, split_bezpath, tangent_on_bezpath};
@@ -26,6 +27,7 @@ use vector_types::vector::misc::{
2627
};
2728
use vector_types::vector::style::{Fill, Gradient, GradientStops, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
2829
use vector_types::vector::{FillId, PointId, RegionId, SegmentDomain, SegmentId, StrokeId, VectorExt};
30+
use wasm_bindgen::UnwrapThrowExt;
2931

3032
/// Implemented for types that can be converted to an iterator of vector rows.
3133
/// Used for the fill and stroke node so they can be used on `Table<Graphic>` or `Table<Vector>`.
@@ -107,6 +109,51 @@ where
107109
content
108110
}
109111

112+
// #[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("fill_properties"))]
113+
// async fn mesh_gradient(
114+
// _: impl Ctx,
115+
// /// The content with vector paths to apply the mesh gradient to.
116+
// mut content: Table<Vector>,
117+
// /// The top-left color of the gradient.
118+
// #[default(Color::BLACK)]
119+
// top_left_color: Table<Color>,
120+
// /// The top-right color of the gradient.
121+
// #[default(Color::BLACK)]
122+
// top_right_color: Table<Color>,
123+
// /// The bottom-left color of the gradient.
124+
// #[default(Color::BLACK)]
125+
// bottom_left_color: Table<Color>,
126+
// /// The bottom-right color of the gradient.
127+
// #[default(Color::BLACK)]
128+
// bottom_right_color: Table<Color>,
129+
// _backup_color: Table<Color>,
130+
// _backup_gradient: Gradient,
131+
// ) -> Table<Vector> {
132+
// for vector in content.vector_iter_mut() {
133+
// let grid_num = 8;
134+
// let grid_stride_uv = 1. / grid_num as f64;
135+
136+
// let segments: Vec<_> = vector.element.segment_iter().collect();
137+
// let points = vector.element.point_domain.positions();
138+
// let top_seg = segments.get(0).unwrap_throw().1;
139+
// let right_seg = segments.get(1).unwrap_throw().1;
140+
// let bottom_seg = segments.get(2).unwrap_throw().1;
141+
// let left_seg = segments.get(3).unwrap_throw().1;
142+
143+
// let bilerp = |u: f64, v: f64| points[0] * (1. - u) * (1. - v) + points[1] * u * (1. - v) + points[2] * (1. - u) * v + points[3] * u * v;
144+
145+
// for i in 0..=grid_num {
146+
// for j in 0..=grid_num {
147+
// let u = i as f64 * grid_stride_uv;
148+
// let v = j as f64 * grid_stride_uv;
149+
// let pos = point_to_dvec2(top_seg.eval(u)) + point_to_dvec2(bottom_seg.eval(1. - u)) - bilerp(u, v);
150+
// }
151+
// }
152+
// }
153+
154+
// content
155+
// }
156+
110157
/// Applies a fill style to the vector content, giving an appearance to the area within the interior of the geometry.
111158
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("fill_properties"))]
112159
async fn fill<F: Into<Fill> + 'n + Send, V: VectorTableIterMut + 'n + Send>(

0 commit comments

Comments
 (0)