Improve the Circular Repeat node
This commit is contained in:
parent
980b692d46
commit
8fbf0cbb69
|
|
@ -2038,12 +2038,12 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
|||
identifier: NodeImplementation::proto("graphene_core::vector::CircularRepeatNode<_, _, _>"),
|
||||
inputs: vec![
|
||||
DocumentInputType::value("Vector Data", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), true),
|
||||
DocumentInputType::value("Rotation Offset", TaggedValue::F32(0.), false),
|
||||
DocumentInputType::value("Angle Offset", TaggedValue::F32(0.), false),
|
||||
DocumentInputType::value("Radius", TaggedValue::F32(5.), false),
|
||||
DocumentInputType::value("Count", TaggedValue::U32(10), false),
|
||||
],
|
||||
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
|
||||
properties: node_properties::circle_repeat_properties,
|
||||
properties: node_properties::circular_repeat_properties,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
|
|
|
|||
|
|
@ -1788,12 +1788,12 @@ pub fn repeat_properties(document_node: &DocumentNode, node_id: NodeId, _context
|
|||
vec![direction, LayoutGroup::Row { widgets: count }]
|
||||
}
|
||||
|
||||
pub fn circle_repeat_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
|
||||
let angle_radius = number_widget(document_node, node_id, 1, "Rotation Offset", NumberInput::default(), true);
|
||||
let radius = number_widget(document_node, node_id, 2, "Radius", NumberInput::default().min(0.), true);
|
||||
pub fn circular_repeat_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
|
||||
let angle_offset = number_widget(document_node, node_id, 1, "Angle Offset", NumberInput::default().unit("°"), true);
|
||||
let radius = number_widget(document_node, node_id, 2, "Radius", NumberInput::default(), true); // TODO: What units?
|
||||
let count = number_widget(document_node, node_id, 3, "Count", NumberInput::default().min(1.), true);
|
||||
|
||||
vec![LayoutGroup::Row { widgets: angle_radius }, LayoutGroup::Row { widgets: radius }, LayoutGroup::Row { widgets: count }]
|
||||
vec![LayoutGroup::Row { widgets: angle_offset }, LayoutGroup::Row { widgets: radius }, LayoutGroup::Row { widgets: count }]
|
||||
}
|
||||
|
||||
/// Fill Node Widgets LayoutGroup
|
||||
|
|
|
|||
|
|
@ -102,14 +102,14 @@ fn repeat_vector_data(mut vector_data: VectorData, direction: DVec2, count: u32)
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct CircularRepeatNode<RotationOffset, Radius, Count> {
|
||||
rotation_offset: RotationOffset,
|
||||
pub struct CircularRepeatNode<AngleOffset, Radius, Count> {
|
||||
angle_offset: AngleOffset,
|
||||
radius: Radius,
|
||||
count: Count,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(CircularRepeatNode)]
|
||||
fn circular_repeat_vector_data(mut vector_data: VectorData, rotation_offset: f32, radius: f32, count: u32) -> VectorData {
|
||||
fn circular_repeat_vector_data(mut vector_data: VectorData, angle_offset: f32, radius: f32, count: u32) -> VectorData {
|
||||
// repeat the vector data
|
||||
let VectorData { subpaths, transform, .. } = &vector_data;
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ fn circular_repeat_vector_data(mut vector_data: VectorData, rotation_offset: f32
|
|||
let base_transform = DVec2::new(0., radius as f64) - center;
|
||||
|
||||
for i in 0..count {
|
||||
let angle = (2. * std::f64::consts::PI / count as f64) * i as f64 + rotation_offset.to_radians() as f64;
|
||||
let angle = (2. * std::f64::consts::PI / count as f64) * i as f64 + angle_offset.to_radians() as f64;
|
||||
let rotation = DAffine2::from_angle(angle);
|
||||
let transform = DAffine2::from_translation(center) * rotation * DAffine2::from_translation(base_transform);
|
||||
for mut subpath in subpaths.clone() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue