-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
2d Transforms #19389
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
base: main
Are you sure you want to change the base?
2d Transforms #19389
Conversation
Is the intended mechanism for controlling draw order / "z index" using Or are there plans to add another component on top of this changeset? |
This is the first of a few PRs I have planned. For the initial implementation, if you want to have layers just parent a 3d transform to a 2d transform. 2d transforms are in effect 3d transforms which only let you specify coords in XY, and you can mix-and-match 2d and 3d within the same hierarchy. I'd like to have a z index solution, but I think it should be built on top. I certainly don't want to do it as part of this PR, which is very large and mostly mechanical. |
That sounds pretty unpleasant. I would personally rather deal with quaternions.
It would be helpful to see an outline / timeline of this plan. It is hard to get a feeling for what working in 2d will be like without this. |
Could you expand on this? Clearly it's not ideal but this is a stronger reaction than I was expecting. What about it is so unpleasant? Here's a quick sample of what I was picturing: commands.spawn((
Name("Layer five")
Transform3d::from_translation(Vec3::Z * 5.0), // Add a layer at +5 Z.
children![
(MyComponent, Transform2d::from_translation(Vec2::splat(10.0))) // X 10, Y 10, Z 5
/* Add all the things to your layer here */
]
));
Yeah, that's fair. I can't give one, since this is pretty early in the process. I wanted to gauge if a working group would be necessary to get this in, and now it seems like it might be. |
The generated |
A bit of a gut (perhaps over-)reaction to the idea of adding more layers of hierarchy to my stuff, but: If I want to spawn an entity on a particular layer that already exists, I now have an added step of looking up a layer entity. If I want to move an entity from one layer to another, I now need to look up the new layer entity and reparent the entity. If my character has a sword which must be drawn on top of the main sprite, and a cape which must be drawn below the main sprite, I guess I'm using If I have 1000 entities and just want to ensure a particular consistent render order, I guess I'm using There are probably other use-cases like isometric / y-sorting that don't fit neatly into the "layers" approach, and it is nice that I'm not anti- |
Great, that makes a lot of sense. Yeah, I totally see your concerns. I'm trying to figure out how to cut this change up into manageable bits. There's a lot we need to do with transforms, and if we go for all of them at once it's going to be a slog. What would your ideal API be? I do want to land this along with a proper z-layer solution within the same release cycle, but I'm worried about pinning them together so closely: These changes are big and (mostly) uncontroversial, and the z-layer api will be smaller and much more prone to bike-shedding. Is there a temporary fix that would make this more palatable in the meantime? For instance, if |
What about an optional ZIndex component. Read it into transform3d's z POS if it exists otherwise 0. |
Objective
Add a dedicated 2d transform type. Having to deal with 3d math for 2d logic is no fun at all.
Solution
Transform
toTransform3d
(This is the bulk of the diff).Transform2d
type usingRot2
andVec2
.This is a draft PR, with the bare-bones logic scaffolded out. It lacks polish and testing. Putting it up now so I can sense how people feel about these changes.
Questions for Reviewers
And more seriously:
Transform
, or exporting it as an alias forTransform3d
. Is this worth it?