Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform rewrite - initial draft #374

Merged
merged 25 commits into from
Sep 14, 2020
Merged

Conversation

MarekLg
Copy link
Contributor

@MarekLg MarekLg commented Aug 27, 2020

This is the first draft of my rewrite of bevy's transformation system (corresponding issue #229).

Lights and root entity placement works as expected.

2 tests are failing:

  • transform-propagate-system::test::did_propagate_command_buffer()
  • hierarchy_maintenance_system::test::correct_children()
    and I can't explain myself what's causing it..

Parenting does not work as expected: children seem to keep the same Transform as their parent.
All these issues seem to be related to Commands, which I don't understand fully at this point.

Also, I ignored UI and 2D for now.

I'm hoping for feedback from more experienced contributors, as I don't have much experience with bevy yet, so every help is greatly appreciated.

@MarekLg MarekLg marked this pull request as draft August 27, 2020 16:33
Copy link
Contributor

@GrantMoyer GrantMoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments, but I'm not familiar enough with the parenting system to see what's wrong with that component.

crates/bevy_transform/src/components/transform.rs Outdated Show resolved Hide resolved
crates/bevy_transform/src/components/transform.rs Outdated Show resolved Hide resolved
crates/bevy_transform/src/transform_propagate_system.rs Outdated Show resolved Hide resolved
examples/3d/z_sort_debug.rs Outdated Show resolved Hide resolved
@karroffel karroffel added C-Code-Quality A section of code that is hard to understand or change A-ECS Entities, components, systems, and events labels Aug 28, 2020
@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 1, 2020

Parenting works now. The problem came from replacing LocalTransform with Transform, especially in ChildBuilder and WorkChildBuilder, where it was set to default after the Entity has been added to world with the proper Transform.

@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 3, 2020

The last test that's failing is hierarchy_maintenance_system::correct_children()
It seems to fail because the commands passed during parent_update_system() don't seem to be applied right away (reparenting works if schedule is run 2 times and fails if schedule is run 1time). This causes transform_propagate_system() to try to access a child that, although already being world.despawned, still is being referenced to in Children.

Does anyone have an idea how to solve this?

@cart
Copy link
Member

cart commented Sep 8, 2020

I'll be diving into this soon. I'll hopefully have answers to your questions in the near future.

@cart
Copy link
Member

cart commented Sep 9, 2020

I love how much simpler this makes the code ❤️

// ideally setting the transform automatically propagates back to position / translation / rotation,
// but right now they are always considered the source of truth
local: Mat4,
global: Mat4,
}

impl Transform {
Copy link
Member

@cart cart Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this api in general, but I don't think its a complete replacement for the current transform system until we have the following apis:

// sets the absolute local scale
set_local_scale(&mut self, scale: Vec3)

// gets the absolute local rotation
local_rotation(&self) -> Quat

// sets the absolute local rotation
set_local_rotation(&mut self, rotation: Quat)

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry for the multiple reviews. still sorting out the best way to use the VSCode Github Pull Requests extension)

Just wrapped up my first pass. In general I think this is the right direction. Once we address comments and fix the broken tests I think this is merge-able.

@@ -26,7 +26,7 @@ impl<'a, 'b> WorldChildBuilder<'a, 'b> {
.with_bundle((
Parent(parent_entity),
PreviousParent(Some(parent_entity)),
LocalTransform::default(),
//Transform::default(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that this no longer couples hierarchy to transforms

crates/bevy_transform/src/lib.rs Outdated Show resolved Hide resolved
}
}
}
}

// ANSWERME: maybe speed this up with compute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short term I don't think using compute is worth the complexity. For now this is totally fine

crates/bevy_ui/src/flex/mod.rs Outdated Show resolved Hide resolved
..Default::default()
})
// camera
.spawn(Camera3dComponents {
transform: Transform::new_sync_disabled(Mat4::face_toward(
transform: Transform::new(Mat4::face_toward(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm new_sync_disabled was a pretty big papercut. Removing it is a big win

examples/3d/3d_scene.rs Outdated Show resolved Hide resolved
examples/3d/load_model.rs Outdated Show resolved Hide resolved
examples/3d/parenting.rs Outdated Show resolved Hide resolved
assert!(world.get::<LocalTransform>(child1).is_ok());
assert!(world.get::<LocalTransform>(child2).is_ok());
assert!(world.get::<Transform>(child1).is_ok());
assert!(world.get::<Transform>(child2).is_ok());
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove these asserts as we no longer automatically add Transforms via with_children (which is a good thing)

crates/bevy_transform/src/transform_propagate_system.rs Outdated Show resolved Hide resolved
@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 11, 2020

@cart Thanks for the great comments! Your help is greatly appreciated. I resolved the comments which I consider addressed in the following commits.

@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 12, 2020

If everything works in 3D, how should Transform be implemented for 2D? I see 2 options:

  1. Make 2D Components also use Transform (maybe implement Transform::translate() for Vec2)
  2. Make Entities without Transform and GlobalTransform also be renderable by generating GlobalTransform from Translation etc.

What are your guys opinions?

@cart
Copy link
Member

cart commented Sep 12, 2020

In the immediate short term I'd like to keep this PR scoped to reworking the current transform system (which is used in both 2d and 3d). Eventually we might add a more 2d-centric API, but I'd like that to be a separate discussion.

@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 14, 2020

I'm on it. Do you think Translation, Rotation, Scale and NonUniformScale are still needed, or can they be removed?

@cart
Copy link
Member

cart commented Sep 14, 2020

Let's remove them

@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 14, 2020

The shader/ examples are the only one that don't work yet.

@MarekLg
Copy link
Contributor Author

MarekLg commented Sep 14, 2020

Everything works now.

@MarekLg MarekLg marked this pull request as ready for review September 14, 2020 09:53
@MarekLg MarekLg requested a review from cart September 14, 2020 09:55
Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to go. I'm really excited for these changes :)

@cart cart merged commit 474bb54 into bevyengine:master Sep 14, 2020
@MarekLg MarekLg deleted the transform-rewrite branch September 15, 2020 07:23
mrk-its pushed a commit to mrk-its/bevy that referenced this pull request Oct 6, 2020
Remove individual Translation / Rotation / Scale components in favor of a combined Transform component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants