Bevy Developer Network
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 2d Transforms & Sorting The purpose of this working group is to improve Bevy's 2D support by adding a specialized 2D transform. There's an abnormally large number of closely linked PRs in development that touch this topic: A [2d transform PR], a [UI transform PR], a [y-sorting PR], as well as the [new tilemap renderer]. So part of the purpose of this document is cross-initiative coordination. [2d transform PR]: https://github.com/bevyengine/bevy/pull/19389 [UI transform PR]: https://github.com/bevyengine/bevy/pull/16615 [y-sorting PR]: https://github.com/bevyengine/bevy/pull/19463 [new tilemap renderer]: https://hackmd.io/@bevy/Hkum_o-xll # Proposal + Merge the [ui transform PR] basically as is. + New PR: Replace `ZIndex` and `GlobalZIndex` with a field on `UiTransform`. + Clean up and merge the [2d transform PR]. + Merge the [y-sorting PR], modified so that `ZIndex` and `YSort` are fields of `Transform2d` (leave out `SortBias` for now) and `ZIndex` actually effects the `GlobalTransform`. ## Demonstration Here's an overview of what this would look like. (WIP) ```rust= #[derive(Component, Default)] pub struct Transform2d { /// X-Y Position translation: Vec2, /// Rotation about Z Axis rotation: Rot2, /// Scale in X and Y scale: f32, /// Z component of position depth: Depth2d, /// Opt-in to y sort y_sort: bool } /// Determines the layer a 2d object is drawn on. #[derive(Default)] pub enum Depth2d { Relative(f32), // Parent layer + i Absolute(f32), // Set layer to i } impl Default for Depth2d { fn default() -> Depth2d { // This default makes children be drawn slightly infront // of their parents. Depth2d::Relative(1.0) } } ``` + Mixing 2d and 3d transforms in the same hierarchy is allowed. Both compute `GlobalTransform` given the parent's `GlobalTransform` (if it exists). + We will use hooks to enforce archetype invariants: Adding one transform type automatically removes the other transform type. + Relative values for `depth` are incorperated into transform prop. `depth` is effectivly the same as the `z` position component on `Transform3d`, but with the option to specify it in absolute terms. + `Camera` will no longer require `Transform`. Instead `Camera3d` will require `Transform3d` and `Camera2d` will require `Transform2d`. --- # Detailed Analysis of Related PRs ## PR #19389: 2D Transforms - Core Assessment ### What It Actually Does - **Renames `Transform` → `Transform3d`** (with backward-compatible alias) - **Introduces `Transform2d`** with 2D-native fields (Vec2, Rot2, f32 scale) - **Duplicates transform propagation systems** for 2D variants - **Updates all sprite/2D systems** to work with new types ### Critical Issues Identified from Review 1. **The "Unpleasant" Layering Problem** - Current PR requires 3D parent entities for Z-layering - Forces developers back into 3D thinking for 2D problems - Example of problematic workaround: ```rust commands.spawn(( Name("Layer five"), Transform3d::from_translation(Vec3::Z * 5.0), // 3D parent! children![ (MyComponent, Transform2d::from_translation(Vec2::splat(10.0))) ] )); ``` 2. **Incomplete Solution Without Sorting** - Transform2d alone doesn't solve the core 2D ergonomics problem - Still requires manual Z-coordinate management - Reviewer consensus: needs sorting solution in same release ### Performance Implications **Positive**: - Smaller memory footprint (Vec2 vs Vec3, Rot2 vs Quat) - Reduced computational overhead for 2D operations - Better cache locality **Concerns**: - Code duplication in transform systems - Complexity in mixed 2D/3D hierarchies ## PR #19463: Sorting Components - Integration Analysis ### The Sorting Stack ``` ┌─────────────────┐ │ ZIndex (i32) │ ← Primary: Layer separation ├─────────────────┤ │ YSort (marker) │ ← Secondary: Depth illusion ├─────────────────┤ │ SortBias (f32) │ ← Tertiary: Fine-tuning └─────────────────┘ ``` ### Key Reviewer Concerns 1. **Naming Conflict with UI ZIndex** - UI already has `ZIndex` component with different semantics - Need resolution strategy before merge 2. **Per-Entity vs Per-Layer Y-Sorting** - Current: Per-entity `YSort` marker - Concern: May be confusing when mixed with non-Y-sorted entities - Reviewer suggestion: Y-sorting as layer property 3. **Missing Hierarchy Propagation** - No automatic Z-index inheritance - Children don't inherit parent's layer by default - Community expectation: children should inherit parent's Z-layer ### Critical Edge Cases - **Mixed Y-Sort Entities**: Inconsistent behavior when some entities in layer have `YSort`, others don't - **Floating Point Precision**: Y-sorting reliability with similar Y positions - **Performance Scaling**: CPU-based sorting limits for large entity counts ## Synergy Analysis: Why Both PRs Work Better Together ### The Perfect Marriage PR #19463 directly solves PR #19389's biggest problem: **Before (PR #19389 alone)**: ```rust // Awkward 3D parent workaround commands.spawn(( Transform3d::from_translation(Vec3::Z * 5.0), children![(Transform2d::default(), SpriteBundle::default())] )); ``` **After (Both PRs)**: ```rust // Clean, ergonomic 2D solution commands.spawn(( Transform2d::from_translation(Vec2::new(x, y)), ZIndex::new(5), YSort, // Optional depth sorting SpriteBundle::default() )); ``` ### Integration Recommendation: Unified Transform2d The proposed `Transform2d` with integrated depth/sorting fields addresses all core issues: ```rust #[derive(Component, Default)] pub struct Transform2d { translation: Vec2, rotation: Rot2, scale: f32, depth: Depth2d, // Integrated Z-layering y_sort: bool, // Integrated Y-sorting } ``` **Benefits**: - Single component for all 2D transform needs - Eliminates need for separate sorting components - Provides both relative and absolute depth control - Maintains transform propagation semantics --- # Migration Strategy & Risk Assessment ## Phase 1: Foundation (Immediate) 1. **Resolve naming conflicts** - Rename 2D sorting components 2. **Integrate depth into Transform2d** - Eliminate 3D parent workaround 3. **Implement hierarchy propagation** - Children inherit parent depth by default ## Phase 2: Optimization (Follow up PRs) 1. **Performance validation** - Benchmark sorting with realistic 2D scenes 2. **GPU-based sorting** - For high entity count scenarios 3. **Advanced sorting features** - Custom sort keys, spatial partitioning ## Critical Success Factors ### Must Resolve Before Merge 1. **UI ZIndex naming conflict** - Clear disambiguation strategy 2. **Hierarchy propagation** - Automatic depth inheritance 3. **Performance benchmarking** - Validate sorting overhead acceptable ### High-Risk Areas 1. **Breaking changes** - Large mechanical refactoring 2. **Performance regression** - Additional sorting complexity 3. **User confusion** - Dual transform system complexity ### Mitigation Strategies 1. **Comprehensive backward compatibility** - Transform alias, migration tools 2. **Performance budgets** - Clear thresholds for acceptable overhead 3. **Clear documentation** - When to use 2D vs 3D transforms --- # Community Feedback Integration ## Key Reviewer Positions **@rparrett**: Strong opposition to 3D parent workaround - **Resolution**: Integrated depth in Transform2d eliminates this need **@ickshonpe**: Concerned about UI ZIndex conflict - **Resolution**: Rename 2D version or namespace appropriately **@hymm**: Y-sorting should be per-layer, not per-entity - **Discussion**: Current per-entity approach provides more flexibility **@NthTensor**: Fold sorting into Transform2d - **Agreement**: Proposed unified approach addresses this ## Consensus Points - **Strong support** for improved 2D ergonomics - **Agreement** both PRs provide more value together - **Consensus** that current Transform2d without sorting is insufficient - **Shared concern** about performance and complexity --- # Testing & Validation Requirements ## Critical Test Scenarios ### Sort Order Validation ```rust // Test integrated depth system spawn_entity(Transform2d { depth: Depth2d::Absolute(10.0), ..default() }); spawn_entity(Transform2d { depth: Depth2d::Relative(5.0), ..default() }); // Verify consistent, expected ordering ``` ### Hierarchy Propagation ```rust // Test depth inheritance spawn_parent(Transform2d { depth: Depth2d::Absolute(5.0), ..default() }, [ spawn_child(Transform2d { depth: Depth2d::Relative(2.0), ..default() }), // Depth 7.0 spawn_child(Transform2d::default()), // Depth 6.0 (5.0 + 1.0 default) ]); ``` ### Performance Benchmarks - Entity count scaling (1K, 10K, 100K entities) - Frame time impact measurement - Memory usage comparison vs current system ## Acceptance Criteria 1. **Functional**: All existing 2D examples work without modification 2. **Performance**: <5% overhead compared to current Transform system 3. **Ergonomic**: No 3D parent workarounds required for common 2D scenarios 4. **Compatible**: Clear migration path for existing codebases --- # Conclusion & Next Steps ## Recommendation: Proceed with Integrated Approach The proposed unified `Transform2d` with integrated depth and sorting provides the best balance of: - **Ergonomics**: Single component for all 2D transform needs - **Performance**: Eliminates separate component overhead - **Flexibility**: Supports both relative and absolute depth control - **Consistency**: Maintains transform propagation semantics ## Immediate Actions Required 1. **Resolve UI ZIndex naming conflict** - Critical blocker 2. **Implement integrated Transform2d** - Combines both PR benefits 3. **Add hierarchy propagation** - Community expectation 4. **Performance validation** - Ensure acceptable overhead ## Long-term Vision These changes establish foundation for advanced 2D features: - Sophisticated sorting strategies (custom sort keys) - 2D-specific optimization passes - Integrated 2D animation systems - Advanced 2D physics integration The initial complexity investment is justified by the significant improvement to Bevy's 2D development experience and the foundation it provides for future 2D enhancements.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully