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

Consider switching to a generic math library #17

Closed
cart opened this issue Jun 6, 2020 · 1 comment
Closed

Consider switching to a generic math library #17

cart opened this issue Jun 6, 2020 · 1 comment

Comments

@cart
Copy link
Member

cart commented Jun 6, 2020

Bevy currently uses glam, which is blissfully simple, but also doesnt cover the breadth of types required (UVec2 / IVec2 / etc). Additionally, given that we are using a data driven approach for shaders, it makes sense that the math library can map to all (or at least most) shader types. Ideally all types can be zero-copy converted into their shader types.

Libs to consider:

nalgebra
euclid
pathfinder_geometry

@cart cart added this to the Open Source Release milestone Jun 24, 2020
@cart
Copy link
Member Author

cart commented Jul 11, 2020

First some thoughts on Euclid:

  • Euclid is pretty cool. I started porting some parts of bevy to it and it definitely works.
  • For ergonomics I ended up aliasing f32 types like Vector3D<f32, WorldSpace> to Vec3.
  • The path to/from types isn't always clear. Ex: if you want a Transform3D and you have a Point3D, you need to convert it to a Vector3D first. Not a huge deal and relatively rare, but it came up
  • The types are verbose (but we already knew that and its also a plus). This only really comes up when debugging / serializing
  • I like that they directly expose fields instead of putting them behind getters/setters, but this also comes at a cost: adding SIMD would be a breaking change
  • Being able to use the types directly for components (because of unit specifiers) is pretty cool.
  • Its missing a number of "nice to have" methods for transform construction: permutation of "from rotation/scale/translation" , rh/lh perspective matrices.

nalgebra is "slow" to compile in comparison to everything else (nalgebra: 17seconds , glam 0.6 seconds /euclid 1.9 seconds/cgmath 3.3 seconds) and the types are still not fun to deal with

In general I only do "linear algebra operations" on f32s
If 99% of the code would use f32 aliased world space euclid types that look identical to glam and glam has a more complete, performant, and future proof api, I think it makes sense to just use glam
and then for the 1% of cases where we need integer types (ex: glsl datatypes), we can just create a new Vec3 type with a really simple api
the only downside I see to this approach:

  • We're back to wrapper types for transform components. Not the end of the world imo, this is a common pattern in rust
  • Less features available to our custom Vec3 api (at least at the beginning)
    and it also means i dont need to port anything which is nice

@cart cart closed this as completed Jul 11, 2020
pcwalton pushed a commit to pcwalton/bevy that referenced this issue Aug 30, 2021
Keep z translation value untouched in 2d
ricky26 pushed a commit to ricky26/bevy that referenced this issue Jan 13, 2024
Optimise extract_meshlet_meshes and prepare_meshlet_per_frame_resources
zmbush pushed a commit to zmbush/bevy that referenced this issue Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant