mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Copy to Points node: add scale/rotation randomization parameters (#1592)
* WIP, transforms broken with rot/scale * Transform around bounding box centre * Add units and tooltips --------- Co-authored-by: 0hypercube <0hypercube@gmail.com>
This commit is contained in:
@@ -244,7 +244,7 @@ pub(crate) async fn transform_vector_data<Fut: Future>(
|
||||
where
|
||||
Fut::Output: TransformMut,
|
||||
{
|
||||
// TOOD: This is hack and might break for Vector data because the pivot may be incorrect
|
||||
// TODO: This is hack and might break for Vector data because the pivot may be incorrect
|
||||
let transform = DAffine2::from_scale_angle_translation(scale, rotate as f64, translate) * DAffine2::from_cols_array(&[1., shear.y, shear.x, 1., 0., 0.]);
|
||||
if !footprint.ignore_modifications {
|
||||
let pivot_transform = DAffine2::from_translation(pivot);
|
||||
|
||||
@@ -175,9 +175,12 @@ impl ConcatElement for GraphicGroup {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct CopyToPoints<Points, Instance> {
|
||||
pub struct CopyToPoints<Points, Instance, RandomScaleMin, RandomScaleMax, RandomRotation> {
|
||||
points: Points,
|
||||
instance: Instance,
|
||||
random_scale_min: RandomScaleMin,
|
||||
random_scale_max: RandomScaleMax,
|
||||
random_rotation: RandomRotation,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(CopyToPoints)]
|
||||
@@ -185,19 +188,36 @@ async fn copy_to_points<I: GraphicElementRendered + Default + ConcatElement + Tr
|
||||
footprint: Footprint,
|
||||
points: impl Node<Footprint, Output = FP>,
|
||||
instance: impl Node<Footprint, Output = FI>,
|
||||
random_scale_min: f32,
|
||||
random_scale_max: f32,
|
||||
random_rotation: f32,
|
||||
) -> I {
|
||||
let points = self.points.eval(footprint).await;
|
||||
let instance = self.instance.eval(footprint).await;
|
||||
let random_scale_min = random_scale_min as f64;
|
||||
let random_scale_max = random_scale_max as f64;
|
||||
let random_rotation = random_rotation as f64;
|
||||
|
||||
let points_list = points.subpaths.iter().flat_map(|s| s.anchors());
|
||||
|
||||
let instance_bounding_box = instance.bounding_box(DAffine2::IDENTITY).unwrap_or_default();
|
||||
let instance_center = -0.5 * (instance_bounding_box[0] + instance_bounding_box[1]);
|
||||
|
||||
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
|
||||
|
||||
let mut result = I::default();
|
||||
for point in points_list {
|
||||
let translation = points.transform.transform_point2(point) + instance_center;
|
||||
result.concat(&instance, DAffine2::from_translation(translation));
|
||||
let center_transform = DAffine2::from_translation(instance_center);
|
||||
|
||||
let translation = points.transform.transform_point2(point);
|
||||
|
||||
let rotation = (rng.gen::<f64>() - 0.5) * random_rotation;
|
||||
let rotation = rotation / 360. * std::f64::consts::TAU;
|
||||
|
||||
let scale = random_scale_min + rng.gen::<f64>() * (random_scale_max - random_scale_min);
|
||||
let scale = DVec2::splat(scale);
|
||||
|
||||
result.concat(&instance, DAffine2::from_scale_angle_translation(scale, rotation, translation) * center_transform);
|
||||
}
|
||||
|
||||
result
|
||||
|
||||
@@ -732,8 +732,8 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
)],
|
||||
register_node!(graphene_std::raster::SampleNode<_>, input: Footprint, params: [ImageFrame<Color>]),
|
||||
register_node!(graphene_std::raster::MandelbrotNode, input: Footprint, params: []),
|
||||
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData]),
|
||||
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => VectorData, Footprint => GraphicGroup]),
|
||||
async_node!(graphene_core::vector::CopyToPoints<_, _, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData, () => f32, () => f32, () => f32]),
|
||||
async_node!(graphene_core::vector::CopyToPoints<_, _, _, _, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => VectorData, Footprint => GraphicGroup, () => f32, () => f32, () => f32]),
|
||||
async_node!(graphene_core::vector::SamplePoints<_, _, _, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, () => f32, () => f32, () => f32, () => bool, Footprint => Vec<Vec<f64>>]),
|
||||
register_node!(graphene_core::vector::PoissonDiskPoints<_>, input: VectorData, params: [f32]),
|
||||
register_node!(graphene_core::vector::LengthsOfSegmentsOfSubpaths, input: VectorData, params: []),
|
||||
|
||||
Reference in New Issue
Block a user