Skip to content

Commit

Permalink
Migrate to point id
Browse files Browse the repository at this point in the history
  • Loading branch information
0HyperCube committed Mar 11, 2024
1 parent 56ee332 commit fa96cbc
Show file tree
Hide file tree
Showing 34 changed files with 172,162 additions and 422 deletions.
33,959 changes: 33,958 additions & 1 deletion demo-artwork/just-a-potted-cactus.graphite

Large diffs are not rendered by default.

9,289 changes: 9,288 additions & 1 deletion demo-artwork/procedural-string-lights.graphite

Large diffs are not rendered by default.

63,084 changes: 63,083 additions & 1 deletion demo-artwork/red-dress.graphite

Large diffs are not rendered by default.

65,425 changes: 65,424 additions & 1 deletion demo-artwork/valley-of-spires.graphite

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use graph_craft::document::NodeId;
use graphene_core::raster::BlendMode;
use graphene_core::raster::ImageFrame;
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::brush_stroke::BrushStroke;
use graphene_core::vector::style::{Fill, Stroke};
use graphene_core::vector::ManipulatorPointId;
use graphene_core::vector::PointId;
use graphene_core::{Artboard, Color};

use glam::{DAffine2, DVec2, IVec2};
Expand Down Expand Up @@ -85,7 +85,7 @@ pub enum GraphOperationMessage {
},
NewVectorLayer {
id: NodeId,
subpaths: Vec<Subpath<ManipulatorGroupId>>,
subpaths: Vec<Subpath<PointId>>,
parent: LayerNodeIdentifier,
insert_index: isize,
},
Expand Down Expand Up @@ -122,18 +122,18 @@ pub enum TransformIn {
Viewport,
}

type ManipulatorGroup = bezier_rs::ManipulatorGroup<ManipulatorGroupId>;
type ManipulatorGroup = bezier_rs::ManipulatorGroup<PointId>;

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum VectorDataModification {
AddEndManipulatorGroup { subpath_index: usize, manipulator_group: ManipulatorGroup },
AddManipulatorGroup { manipulator_group: ManipulatorGroup, after_id: ManipulatorGroupId },
AddManipulatorGroup { manipulator_group: ManipulatorGroup, after_id: PointId },
AddStartManipulatorGroup { subpath_index: usize, manipulator_group: ManipulatorGroup },
RemoveManipulatorGroup { id: ManipulatorGroupId },
RemoveManipulatorGroup { id: PointId },
RemoveManipulatorPoint { point: ManipulatorPointId },
SetClosed { index: usize, closed: bool },
SetManipulatorHandleMirroring { id: ManipulatorGroupId, mirror_angle: bool },
SetManipulatorHandleMirroring { id: PointId, mirror_angle: bool },
SetManipulatorPosition { point: ManipulatorPointId, position: DVec2 },
ToggleManipulatorHandleMirroring { id: ManipulatorGroupId },
UpdateSubpaths { subpaths: Vec<Subpath<ManipulatorGroupId>> },
ToggleManipulatorHandleMirroring { id: PointId },
UpdateSubpaths { subpaths: Vec<Subpath<PointId>> },
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use graph_craft::document::{generate_uuid, DocumentNode, NodeId, NodeInput, Node
use graphene_core::raster::{BlendMode, ImageFrame};
use graphene_core::renderer::Quad;
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::brush_stroke::BrushStroke;
use graphene_core::vector::style::{Fill, FillType, Gradient, GradientType, LineCap, LineJoin, Stroke};
use graphene_core::vector::PointId;
use graphene_core::{Artboard, Color};
use transform_utils::LayerBounds;

Expand Down Expand Up @@ -186,7 +186,7 @@ impl<'a> ModifyInputsContext<'a> {
self.insert_node_before(NodeId(generate_uuid()), layer, 0, artboard_node, IVec2::new(-8, 0))
}

fn insert_vector_data(&mut self, subpaths: Vec<Subpath<ManipulatorGroupId>>, layer: NodeId) {
fn insert_vector_data(&mut self, subpaths: Vec<Subpath<PointId>>, layer: NodeId) {
let shape = {
let node_type = resolve_document_node_type("Shape").expect("Shape node does not exist");
node_type.to_document_node_default_inputs([Some(NodeInput::value(TaggedValue::Subpaths(subpaths), false))], Default::default())
Expand Down Expand Up @@ -461,7 +461,7 @@ impl<'a> ModifyInputsContext<'a> {
let [mut new_bounds_min, mut new_bounds_max] = [DVec2::ZERO, DVec2::ONE];
let mut empty = false;

self.modify_inputs("Shape", false, |inputs, _node_id, _metadata| {
self.modify_inputs("Vector Modify", false, |inputs, _node_id, _metadata| {
let [subpaths, mirror_angle_groups] = inputs.as_mut_slice() else {
panic!("Shape does not have subpath and mirror angle inputs");
};
Expand All @@ -474,7 +474,7 @@ impl<'a> ModifyInputsContext<'a> {
return;
};
let NodeInput::Value {
tagged_value: TaggedValue::ManipulatorGroupIds(mirror_angle_groups),
tagged_value: TaggedValue::PointIds(mirror_angle_groups),
..
} = mirror_angle_groups
else {
Expand Down Expand Up @@ -943,7 +943,7 @@ fn apply_usvg_fill(fill: &Option<usvg::Fill>, modify_inputs: &mut ModifyInputsCo
}
}

fn convert_usvg_path(path: &usvg::Path) -> Vec<Subpath<ManipulatorGroupId>> {
fn convert_usvg_path(path: &usvg::Path) -> Vec<Subpath<PointId>> {
let mut subpaths = Vec::new();
let mut groups = Vec::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::{Doc

use bezier_rs::{ManipulatorGroup, Subpath};
use graph_craft::document::{value::TaggedValue, NodeInput};
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::PointId;
use graphene_core::vector::{ManipulatorPointId, SelectedType};

use glam::{DAffine2, DVec2};
Expand Down Expand Up @@ -183,7 +183,7 @@ fn clamp_bounds(bounds_min: DVec2, mut bounds_max: DVec2) -> [DVec2; 2] {
[bounds_min, bounds_max]
}
/// Returns corners of all subpaths
fn subpath_bounds(subpaths: &[Subpath<ManipulatorGroupId>]) -> [DVec2; 2] {
fn subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
subpaths
.iter()
.filter_map(|subpath| subpath.bounding_box())
Expand All @@ -192,26 +192,26 @@ fn subpath_bounds(subpaths: &[Subpath<ManipulatorGroupId>]) -> [DVec2; 2] {
}

/// Returns corners of all subpaths (but expanded to avoid division-by-zero errors)
pub fn nonzero_subpath_bounds(subpaths: &[Subpath<ManipulatorGroupId>]) -> [DVec2; 2] {
pub fn nonzero_subpath_bounds(subpaths: &[Subpath<PointId>]) -> [DVec2; 2] {
let [bounds_min, bounds_max] = subpath_bounds(subpaths);
clamp_bounds(bounds_min, bounds_max)
}

pub struct VectorModificationState<'a> {
pub subpaths: &'a mut Vec<Subpath<ManipulatorGroupId>>,
pub mirror_angle_groups: &'a mut Vec<ManipulatorGroupId>,
pub subpaths: &'a mut Vec<Subpath<PointId>>,
pub mirror_angle_groups: &'a mut Vec<PointId>,
}
impl<'a> VectorModificationState<'a> {
fn insert_start(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<ManipulatorGroupId>) {
fn insert_start(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<PointId>) {
self.subpaths[subpath_index].insert_manipulator_group(0, manipulator_group)
}

fn insert_end(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<ManipulatorGroupId>) {
fn insert_end(&mut self, subpath_index: usize, manipulator_group: ManipulatorGroup<PointId>) {
let subpath = &mut self.subpaths[subpath_index];
subpath.insert_manipulator_group(subpath.len(), manipulator_group)
}

fn insert(&mut self, manipulator_group: ManipulatorGroup<ManipulatorGroupId>, after_id: ManipulatorGroupId) {
fn insert(&mut self, manipulator_group: ManipulatorGroup<PointId>, after_id: PointId) {
for subpath in self.subpaths.iter_mut() {
if let Some(index) = subpath.manipulator_index_from_id(after_id) {
subpath.insert_manipulator_group(index + 1, manipulator_group);
Expand All @@ -220,7 +220,7 @@ impl<'a> VectorModificationState<'a> {
}
}

fn remove_group(&mut self, id: ManipulatorGroupId) {
fn remove_group(&mut self, id: PointId) {
for subpath in self.subpaths.iter_mut() {
if let Some(index) = subpath.manipulator_index_from_id(id) {
subpath.remove_manipulator_group(index);
Expand All @@ -246,15 +246,15 @@ impl<'a> VectorModificationState<'a> {
}
}

fn set_mirror(&mut self, id: ManipulatorGroupId, mirror_angle: bool) {
fn set_mirror(&mut self, id: PointId, mirror_angle: bool) {
if !mirror_angle {
self.mirror_angle_groups.retain(|&mirrored_id| mirrored_id != id);
} else if !self.mirror_angle_groups.contains(&id) {
self.mirror_angle_groups.push(id);
}
}

fn toggle_mirror(&mut self, id: ManipulatorGroupId) {
fn toggle_mirror(&mut self, id: PointId) {
if self.mirror_angle_groups.contains(&id) {
self.mirror_angle_groups.retain(|&mirrored_id| mirrored_id != id);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2420,8 +2420,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
name: "Path Generator".to_string(),
inputs: vec![
NodeInput::Network(concrete!(Vec<bezier_rs::Subpath<graphene_core::uuid::ManipulatorGroupId>>)),
NodeInput::Network(concrete!(Vec<graphene_core::uuid::ManipulatorGroupId>)),
NodeInput::Network(concrete!(Vec<bezier_rs::Subpath<graphene_core::vector::PointId>>)),
NodeInput::Network(concrete!(Vec<graphene_core::vector::PointId>)),
],
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::vector::generator_nodes::PathGenerator<_>")),
..Default::default()
Expand All @@ -2442,7 +2442,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
}),
inputs: vec![
DocumentInputType::value("Path Data", TaggedValue::Subpaths(vec![]), false),
DocumentInputType::value("Mirror", TaggedValue::ManipulatorGroupIds(vec![]), false),
DocumentInputType::value("Mirror", TaggedValue::PointIds(vec![]), false),
],
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
..Default::default()
Expand All @@ -2451,8 +2451,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Path Modify",
category: "Vector",
implementation: DocumentNodeImplementation::Network(NodeNetwork {
inputs: vec![NodeId(0), NodeId(1)],
outputs: vec![NodeOutput::new(NodeId(1), 0)],
imports: vec![NodeId(0), NodeId(1)],
exports: vec![NodeOutput::new(NodeId(1), 0)],
nodes: vec![
DocumentNode {
inputs: vec![NodeInput::Network(concrete!(VectorData))],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn path_overlays(document: &DocumentMessageHandler, shape_editor: &mut Shape
let is_selected = |selected: Option<&SelectedLayerState>, point: ManipulatorPointId| selected.is_some_and(|selected| selected.is_selected(point));
overlay_context.outline(vector_data.stroke_bezier_paths(), transform);

let mut manipulator_overlay = |manipulator_group: &bezier_rs::ManipulatorGroup<graphene_std::vector::PointId>| {
for manipulator_group in vector_data.manipulator_groups() {
let anchor = manipulator_group.anchor;
let anchor_position = transform.transform_point2(anchor);

Expand All @@ -51,12 +51,6 @@ pub fn path_overlays(document: &DocumentMessageHandler, shape_editor: &mut Shape
}

overlay_context.manipulator_anchor(anchor_position, is_selected(selected, ManipulatorPointId::new(manipulator_group.id.into(), SelectedType::Anchor)), None);
};

for subpath in vector_data.stroke_bezier_paths() {
for manipulator in subpath.manipulator_groups() {
manipulator_overlay(manipulator);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::messages::prelude::Message;

use bezier_rs::Subpath;
use graphene_core::renderer::Quad;
use graphene_std::vector::PointId;

use core::borrow::Borrow;
use core::f64::consts::PI;
Expand Down Expand Up @@ -114,7 +115,7 @@ impl OverlayContext {
self.render_context.stroke();
}

pub fn outline<'a, Id: bezier_rs::Identifier>(&mut self, subpaths: impl Iterator<Item = impl Borrow<Subpath<Id>>>, transform: DAffine2) {
pub fn outline<'a>(&mut self, subpaths: impl Iterator<Item = impl Borrow<Subpath<PointId>>>, transform: DAffine2) {
self.render_context.begin_path();
for subpath in subpaths {
let subpath = subpath.borrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use bezier_rs::{ManipulatorGroup, Subpath};
use graph_craft::document::{value::TaggedValue, DocumentNode, NodeId, NodeInput, NodeNetwork};
use graphene_core::raster::{BlendMode, ImageFrame};
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::style::{FillType, Gradient};
use graphene_core::vector::PointId;
use graphene_core::Color;

use glam::DVec2;
use std::collections::VecDeque;

/// Create a new vector layer from a vector of [`bezier_rs::Subpath`].
pub fn new_vector_layer(subpaths: Vec<Subpath<ManipulatorGroupId>>, id: NodeId, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier {
pub fn new_vector_layer(subpaths: Vec<Subpath<PointId>>, id: NodeId, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier {
let insert_index = -1;
responses.add(GraphOperationMessage::NewVectorLayer { id, subpaths, parent, insert_index });
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn new_svg_layer(svg: String, transform: glam::DAffine2, id: NodeId, parent:
}

/// Batch set all of the manipulator groups to mirror on a specific layer
pub fn set_manipulator_mirror_angle(manipulator_groups: &[ManipulatorGroup<ManipulatorGroupId>], layer: LayerNodeIdentifier, mirror_angle: bool, responses: &mut VecDeque<Message>) {
pub fn set_manipulator_mirror_angle(manipulator_groups: &[ManipulatorGroup<PointId>], layer: LayerNodeIdentifier, mirror_angle: bool, responses: &mut VecDeque<Message>) {
for manipulator_group in manipulator_groups {
responses.add(GraphOperationMessage::Vector {
layer,
Expand All @@ -61,7 +61,7 @@ pub fn set_manipulator_mirror_angle(manipulator_groups: &[ManipulatorGroup<Manip
}

/// Locate the subpaths from the shape nodes of a particular layer
pub fn get_subpaths(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<&Vec<Subpath<ManipulatorGroupId>>> {
pub fn get_subpaths(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<&Vec<Subpath<PointId>>> {
if let TaggedValue::Subpaths(subpaths) = NodeGraphLayer::new(layer, document_network)?.find_input("Shape", 0)? {
Some(subpaths)
} else {
Expand All @@ -85,11 +85,12 @@ pub fn get_viewport_pivot(layer: LayerNodeIdentifier, document_network: &NodeNet
}

/// Get the currently mirrored handles for a particular layer from the shape node
pub fn get_mirror_handles(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> Option<&Vec<ManipulatorGroupId>> {
if let TaggedValue::ManipulatorGroupIds(mirror_handles) = NodeGraphLayer::new(layer, document_network)?.find_input("Shape", 1)? {
Some(mirror_handles)
pub fn get_mirror_handles(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> &Vec<PointId> {
if let Some(TaggedValue::PointIds(mirror_handles)) = NodeGraphLayer::new(layer, document_network).and_then(|layer| layer.find_input("Shape", 1)) {
mirror_handles
} else {
None
static DEFAULT: &'static Vec<PointId> = &Vec::new();
DEFAULT
}
}

Expand Down Expand Up @@ -208,12 +209,12 @@ pub fn is_layer_fed_by_node_of_name(layer: LayerNodeIdentifier, document_network
}

/// Convert subpaths to an iterator of manipulator groups
pub fn get_manipulator_groups(subpaths: &[Subpath<ManipulatorGroupId>]) -> impl Iterator<Item = &bezier_rs::ManipulatorGroup<ManipulatorGroupId>> + DoubleEndedIterator {
pub fn get_manipulator_groups(subpaths: &[Subpath<PointId>]) -> impl Iterator<Item = &bezier_rs::ManipulatorGroup<PointId>> + DoubleEndedIterator {
subpaths.iter().flat_map(|subpath| subpath.manipulator_groups())
}

/// Find a manipulator group with a specific id from several subpaths
pub fn get_manipulator_from_id(subpaths: &[Subpath<ManipulatorGroupId>], id: ManipulatorGroupId) -> Option<&bezier_rs::ManipulatorGroup<ManipulatorGroupId>> {
pub fn get_manipulator_from_id(subpaths: &[Subpath<PointId>], id: PointId) -> Option<&bezier_rs::ManipulatorGroup<PointId>> {
subpaths.iter().find_map(|subpath| subpath.manipulator_from_id(id))
}

Expand Down

0 comments on commit fa96cbc

Please sign in to comment.