Weasy666 / bevy_svg

A simple and incomplete SVG drawer for the Bevy engine.
Apache License 2.0
108 stars 26 forks source link

Parent-child transform problems #26

Open nametable opened 1 year ago

nametable commented 1 year ago

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:

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.

nametable commented 1 year ago

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.

nametable commented 1 year ago

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.

Weasy666 commented 1 year ago

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.

nametable commented 1 year ago

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.

samuelwatsonofficial commented 1 year ago

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 .