-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New node: 'Heart' #4478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ayush2k02
wants to merge
7
commits into
GraphiteEditor:master
Choose a base branch
from
Ayush2k02:gizmo/1-heart-node
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New node: 'Heart' #4478
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5204430
Heart node
Keavon 0e52789
Add Heart drawing mode to the Shape tool with gizmo registration
Ayush2k02 9aaef5f
Migrate the Heart node to the ranked node input API
Ayush2k02 8478c27
Port the Heart node's geometry to BezPath and cover it with tests
Ayush2k02 d5c111f
Draw the heart in document units and skip degenerate drags
Ayush2k02 c1e0dad
Describe the cleavage angle correctly and test symmetry against the c…
Ayush2k02 8e5a9cc
Scope the ParamCurve import to the tests that use it
Ayush2k02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
editor/src/messages/tool/common_functionality/shapes/heart_shape.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use crate::messages::message::Message; | ||
| use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn; | ||
| use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_proto_node_type; | ||
| use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier; | ||
| use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeTemplate}; | ||
| use crate::messages::prelude::{DocumentMessageHandler, InputPreprocessorMessageHandler}; | ||
| use crate::messages::tool::common_functionality::graph_modification_utils; | ||
| use crate::messages::tool::common_functionality::resize::viewport_zoom; | ||
| use crate::messages::tool::common_functionality::shapes::shape_utility::ShapeToolModifierKey; | ||
| use crate::messages::tool::tool_messages::shape_tool::ShapeToolData; | ||
| use crate::messages::tool::tool_messages::tool_prelude::*; | ||
| use glam::DAffine2; | ||
| use graph_craft::document::NodeInput; | ||
| use graph_craft::document::value::TaggedValue; | ||
| use std::collections::VecDeque; | ||
|
|
||
| /// The heart's size is adjusted via a registry-driven radius gizmo (see the [gizmo registry]), while its | ||
| /// parametric controls (cleavage, lobes, shoulder, etc.) are adjusted via the Properties panel. | ||
| /// | ||
| /// [gizmo registry]: crate::messages::tool::common_functionality::gizmos::gizmo_registry | ||
| #[derive(Default)] | ||
| pub struct Heart; | ||
|
|
||
| impl Heart { | ||
| pub fn create_node() -> NodeTemplate { | ||
| let node_type = resolve_proto_node_type(graphene_std::vector::generator_nodes::heart::IDENTIFIER).expect("Heart node can't be found"); | ||
| node_type.node_template_input_override([None, Some(NodeInput::value(TaggedValue::F64(0.), false))]) | ||
| } | ||
|
|
||
| pub fn update_shape( | ||
| document: &DocumentMessageHandler, | ||
| ipp: &InputPreprocessorMessageHandler, | ||
| viewport: &ViewportMessageHandler, | ||
| layer: LayerNodeIdentifier, | ||
| shape_tool_data: &mut ShapeToolData, | ||
| modifier: ShapeToolModifierKey, | ||
| responses: &mut VecDeque<Message>, | ||
| ) { | ||
| let [center, lock_ratio, _] = modifier; | ||
|
|
||
| if let Some([start, end]) = shape_tool_data.data.calculate_points(document, ipp, viewport, center, lock_ratio) { | ||
| let Some(node_id) = graph_modification_utils::get_heart_id(layer, &document.network_interface) else { | ||
| return; | ||
| }; | ||
|
|
||
| // In document units, as every other generator does: without this the heart is drawn at the | ||
| // wrong size whenever the canvas is not at 100% zoom. | ||
| let dimensions = ((start - end) / viewport_zoom(document)).abs(); | ||
|
|
||
| // A drag that is exactly horizontal, exactly vertical, or has not moved leaves one dimension at | ||
| // zero. Dividing by it would write an infinite or NaN scale into the layer transform, so the | ||
| // degenerate frame is skipped and the last good size stands. | ||
| if dimensions.x == 0. || dimensions.y == 0. { | ||
| return; | ||
| } | ||
|
|
||
| let mut scale = DVec2::ONE; | ||
|
Ayush2k02 marked this conversation as resolved.
|
||
| let radius: f64; | ||
| if dimensions.x > dimensions.y { | ||
| scale.x = dimensions.x / dimensions.y; | ||
| radius = dimensions.y / 2.; | ||
| } else { | ||
| scale.y = dimensions.y / dimensions.x; | ||
| radius = dimensions.x / 2.; | ||
| } | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
|
|
||
| responses.add(NodeGraphMessage::SetInput { | ||
| input_connector: InputConnector::node(node_id, graphene_std::vector::generator_nodes::heart::RadiusInput), | ||
| input: NodeInput::value(TaggedValue::F64(radius), false), | ||
| }); | ||
|
|
||
| responses.add(GraphOperationMessage::TransformSet { | ||
| layer, | ||
| transform: DAffine2::from_scale_angle_translation(scale, 0., (start + end) / 2.), | ||
| transform_in: TransformIn::Viewport, | ||
| skip_rerender: false, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.