Weasy666/bevy_svg

Parent-child transform problems

Opened this issue · 5 comments

Version: 0.9
Scenario: I have 2 svgs, one is the parent and has a child svg. Here is stripped down version below:

    commands
        .spawn(Svg3dBundle {
            svg: component_svg,
            origin: Origin::Center,
            transform: Transform {
                translation: translation,
                scale: Vec3::new(1.0, 1.0, 1.0),
                ..Default::default()
            },
            ..Default::default()
        })
        .with_children(|parent| {
                parent.spawn(Svg3dBundle {
                    svg: pin_svg,
                    origin: Origin::Center,
                    transform: Transform {
                        translation: Vec3::new(pin.position.x, pin.position.y, 1.0),
                        scale: Vec3::new(1.0, 1.0, 1.0),
                        ..Default::default()
                    },
                    ..Default::default()
                });
            }

The problems that I see are as follows:

  • The placement of the child seems to follow Origin::TopLeft of the child instead of Origin::Center of the child
  • When the child is translated by itself, it is placed relative to the Origin::TopLeft of the parent, and Origin::Center of the child.
    • When the parent is translated, the child is placed back according to the Origin::TopLeft of the child, offset from the (correct) Origin::Center of the parent.

I'm not sure if it matters, but I'm using bevy-inspector-egui to modify the transforms. A short recording of the issues can be seen below:

bevy_svg_parenting_problems.webm

If a more minimal reproduction or repo with example would be useful, I can make one up.

I have started taking a look here in this branch. I'm starting to try to create an example to test with. I want to add the ability to use a keyboard shortcut to toggle movement of the parent or child, to see what happens when each is modified without the other, and then both. I've copied and modified examples/2d/multiple_translation.rs to make examples/2d/parent_child_translation_check.rs.

For now I may just use Origin::TopLeft since it naturally transforms correctly between children. I think the problem is with how Bevy's transform_propagate_system processes the translation of child entities.

Thanks for taking a look. If you think it is a problem with Bevy's propagate system, i guess we should wait 1-2 weeks, port main to Bevy 0.10 and then try it again. I think, with all the changes done to the scheduling in stageless we need to touch that part of the code anyways.

I don't think it's a problem with the Bevy's propagate system per se, but I think that bevy_svg will somehow have to "hook" into the child translation propagation. In other words, applying the origin translation is not happening currently with children when the parent translation changes.

I think you are right about waiting for Bevy 0.10 though, especially if it introduces a way for bevy_svg to "hook into" or provide a custom system for child transform propagation.

I'm having issues similar to this where the child svg will flicker between Centered and TopLeft origin in Bevy 11.2, https://github.com/samuelwatsonofficial/Scarlet .