@@ -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) ) ]
362361async 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 >
370369where
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