Skip to content

Commit 2bb07b8

Browse files
0HyperCubeKeavon
andauthored
Instance tables refactor part 8: Output the type of the input data with the Mirror node as well (#2699)
* Flatten output of mirror node * Enable reflection based on pivot, not just bounds --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 3c1cdb2 commit 2bb07b8

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ pub fn reference_point_widget(parameter_widgets_info: ParameterWidgetsInfo, disa
334334
if let Some(&TaggedValue::ReferencePoint(reference_point)) = input.as_non_exposed_value() {
335335
widgets.extend_from_slice(&[
336336
Separator::new(SeparatorType::Unrelated).widget_holder(),
337+
CheckboxInput::new(reference_point != ReferencePoint::None)
338+
.on_update(update_value(
339+
move |x: &CheckboxInput| TaggedValue::ReferencePoint(if x.checked { ReferencePoint::Center } else { ReferencePoint::None }),
340+
node_id,
341+
index,
342+
))
343+
.disabled(disabled)
344+
.widget_holder(),
345+
Separator::new(SeparatorType::Related).widget_holder(),
337346
ReferencePointInput::new(reference_point)
338347
.on_update(update_value(move |x: &ReferencePointInput| TaggedValue::ReferencePoint(x.value), node_id, index))
339348
.disabled(disabled)

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,19 @@ where
357357
result_table
358358
}
359359

360-
// TODO: Make this node return Instances<I> instead of GraphicGroupTable, while preserving the current transform behavior as the `reference_point` and `offset` parameters are varied
361360
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
362361
async fn mirror<I: 'n + Send + Clone>(
363362
_: impl Ctx,
364363
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<Color>)] instance: Instances<I>,
365-
#[default(ReferencePoint::Center)] reference_point: ReferencePoint,
364+
#[default(ReferencePoint::Center)] relative_to_bounds: ReferencePoint,
366365
offset: f64,
367366
#[range((-90., 90.))] angle: Angle,
368367
#[default(true)] keep_original: bool,
369-
) -> GraphicGroupTable
368+
) -> Instances<I>
370369
where
371370
Instances<I>: GraphicElementRendered,
372371
{
373-
let mut result_table = GraphicGroupTable::default();
372+
let mut result_table = Instances::default();
374373

375374
// Normalize the direction vector
376375
let normal = DVec2::from_angle(angle.to_radians());
@@ -380,12 +379,8 @@ where
380379
return result_table;
381380
};
382381

383-
// TODO: If the reference point is not None, use the current behavior but make it work correctly with local pivot origins of each Instances<I> row
384-
let reference_point_location = reference_point.point_in_bounding_box((bounding_box[0], bounding_box[1]).into()).unwrap_or_else(|| {
385-
// TODO: In this None case, use the input's local pivot origin point instead of a point relative to its bounding box
386-
(bounding_box[0] + bounding_box[1]) / 2.
387-
});
388-
let mirror_reference_point = reference_point_location + normal * offset;
382+
let reference_point_location = relative_to_bounds.point_in_bounding_box((bounding_box[0], bounding_box[1]).into());
383+
let mirror_reference_point = reference_point_location.map(|point| point + normal * offset);
389384

390385
// Create the reflection matrix
391386
let reflection = DAffine2::from_mat2_translation(
@@ -397,25 +392,25 @@ where
397392
);
398393

399394
// Apply reflection around the reference point
400-
let transform = DAffine2::from_translation(mirror_reference_point) * reflection * DAffine2::from_translation(-mirror_reference_point);
395+
let reflected_transform = if let Some(mirror_reference_point) = mirror_reference_point {
396+
DAffine2::from_translation(mirror_reference_point) * reflection * DAffine2::from_translation(-mirror_reference_point)
397+
} else {
398+
reflection * DAffine2::from_translation(DVec2::from_angle(angle.to_radians()) * DVec2::splat(-offset))
399+
};
401400

402401
// Add original instance depending on the keep_original flag
403402
if keep_original {
404-
result_table.push(Instance {
405-
instance: instance.to_graphic_element().clone(),
406-
transform: DAffine2::IDENTITY,
407-
alpha_blending: Default::default(),
408-
source_node_id: None,
409-
});
403+
for instance in instance.clone().instance_iter() {
404+
result_table.push(instance);
405+
}
410406
}
411407

412408
// Create and add mirrored instance
413-
result_table.push(Instance {
414-
instance: instance.to_graphic_element(),
415-
transform,
416-
alpha_blending: Default::default(),
417-
source_node_id: None,
418-
});
409+
for mut instance in instance.instance_iter() {
410+
instance.transform = reflected_transform * instance.transform;
411+
instance.source_node_id = None;
412+
result_table.push(instance);
413+
}
419414

420415
result_table
421416
}

0 commit comments

Comments
 (0)