@@ -357,20 +357,19 @@ where
357
357
result_table
358
358
}
359
359
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
361
360
#[ node_macro:: node( category( "Vector" ) , path( graphene_core:: vector) ) ]
362
361
async fn mirror < I : ' n + Send + Clone > (
363
362
_: impl Ctx ,
364
363
#[ implementations( GraphicGroupTable , VectorDataTable , RasterDataTable <Color >) ] instance : Instances < I > ,
365
- #[ default( ReferencePoint :: Center ) ] reference_point : ReferencePoint ,
364
+ #[ default( ReferencePoint :: Center ) ] relative_to_bounds : ReferencePoint ,
366
365
offset : f64 ,
367
366
#[ range( ( -90. , 90. ) ) ] angle : Angle ,
368
367
#[ default( true ) ] keep_original : bool ,
369
- ) -> GraphicGroupTable
368
+ ) -> Instances < I >
370
369
where
371
370
Instances < I > : GraphicElementRendered ,
372
371
{
373
- let mut result_table = GraphicGroupTable :: default ( ) ;
372
+ let mut result_table = Instances :: default ( ) ;
374
373
375
374
// Normalize the direction vector
376
375
let normal = DVec2 :: from_angle ( angle. to_radians ( ) ) ;
@@ -380,12 +379,8 @@ where
380
379
return result_table;
381
380
} ;
382
381
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) ;
389
384
390
385
// Create the reflection matrix
391
386
let reflection = DAffine2 :: from_mat2_translation (
@@ -397,25 +392,25 @@ where
397
392
) ;
398
393
399
394
// 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
+ } ;
401
400
402
401
// Add original instance depending on the keep_original flag
403
402
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
+ }
410
406
}
411
407
412
408
// 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
+ }
419
414
420
415
result_table
421
416
}
0 commit comments