add InfallibleMesh for mesh construction without unwraps#21986
add InfallibleMesh for mesh construction without unwraps#21986robtfm wants to merge 5 commits intobevyengine:mainfrom
Conversation
5f2babf to
e3ad522
Compare
|
I've skimmed the changes and couldn't spot any obvious issues. I'm not sold on the way But that's debatable, and the current version does solve an immediate problem. So maybe it's fine to get the current version in first, and make the case for follow on changes separately. |
|
That would mean having InfallibleMesh as a separate asset type? I can see lots of issues arising from that, on first glance I’m definitely on the opposite team for the debate… In case it helps with framing, I would have called it MeshBuilder if that wasn’t already taken. |
|
No, I didn't intend for InfallibleMesh to be a separate asset type. It's just a temporary helper. So the only change to the current PR would be to remove the implicit deref - then InfallibleMesh can only be turned into a Mesh through Actually... just checking the PR - InfallibleMesh currently derives Asset? Is that intended? Feels wrong regardless of which approach is taken. |
|
the reason for the deref was primitive builders that use we only allow read-only access to the mesh content though, so that we can still ensure it hasn't been extracted. i don't think i've quite understood the point about compression though - if it modifies the mesh and we don't want it to, we just avoid providing an InfallibleMesh compression method ... but maybe that's not what you meant? |
|
The scenario I'm imagining is that Mesh becomes more optimised for loading and GPU upload at some point in the future - maybe that's through compression, or interleaving attributes, or packing everything into a single allocation. Or maybe there's extra validation added to make sure attributes match up. These kinds of things are difficult to do incrementally as attributes are added - they want the attributes finalised first so they can validate or optimize everything in a single step. If InfallibleMesh can be deref'd to Mesh at any time then that could be difficult. It would be easier if the only way to get a Mesh value is through calling But I'm just speculating. Maybe the API ends up looking completely different. |
|
you're right about the Asset derive - removed, thanks. regarding invalid mesh states, i see what you're saying now, but agree we can cross that bridge when we come to it. |
|
Sounds good to me. Personally I'd be minded to approve this PR even though I'm not keen on the deref - it's still a step in the right direction. |
@greeble-dev 😅I realize that is a bit difficult and greatly breaks compatibility. Because |
|
My guess is that there'll be pressure to keep |
|
Iterating over compressed or interleaved vertex attributes might degrade mesh performance for CPU reads, not the complexity of handling it. If the goal is just to have a mesh that’s efficient for GPU uploads, a mechanism like I think the current Mesh interface is fine. Even modifying it can panic if it's extracted, I guess most users would still use Mesh over InfallibleMesh. |
|
In my view, the key issue is separating the mesh types optimized for writing from the mesh types optimized for reading. I'm also assuming there would be multiple types optimised for different kinds of reads - so having physics be able to read GPU mesh data is a useful convenience in some situations, but for situations where performance is more important there would be a separate type optimized for physics. So I see this PR as a step forward to separating read and write types. I'm not so worried about which of those types ends up getting called |
ca83f5a to
7d6aae4
Compare
kfc35
left a comment
There was a problem hiding this comment.
Reviewing this PR since I have context from the 0.18 release and the current strange state Mesh is in, and would like to see it continue into a better state. I agree that this PR helps with that.
I couldn’t find anything that should block this pull request logic wise. I think the only small concern I have as someone with less context is if the panicking in bevy_render is acceptable behavior, but given that there have not been any complaints or bug reports about it, I assume it is fine.
As for conflicts with main (if this PR is still a candidate for moving forward), I know that one conflict is just with intersections.rs as a result of the bug fix from #22356: should be resolvable by following what’s on main to use ok()? instead of the expects used in this PR
| /// | ||
| /// # Panics | ||
| /// Panics if [`Mesh::ATTRIBUTE_POSITION`] is not of type `float3`. | ||
| /// Panics if the mesh has any other topology than [`PrimitiveTopology::TriangleList`].= |
There was a problem hiding this comment.
| /// Panics if the mesh has any other topology than [`PrimitiveTopology::TriangleList`].= | |
| /// Panics if the mesh has any other topology than [`PrimitiveTopology::TriangleList`]. |
| /// Panics if [`Mesh::ATTRIBUTE_POSITION`] is not of type `float3`. | ||
| /// Panics if the mesh has any other topology than [`PrimitiveTopology::TriangleList`]. | ||
| /// Panics if the mesh does not have indices defined. | ||
| /// Panics when the mesh data has already been extracted to `RenderWorld`. To handle |
There was a problem hiding this comment.
This last panic should not be here, right?
| /// towards the planes divided into the most triangles: | ||
| /// ``` | ||
| /// # use bevy_asset::RenderAssetUsages; | ||
| /// # use bevy_mesh::{Mesh, PrimitiveTopology, Meshable, MeshBuilder}; |
There was a problem hiding this comment.
Does this code example need to be updated with InfallibleMesh at all?
There was a problem hiding this comment.
Clicking approve as this seems like a reasonable step forward - I think it's good to separate the building of meshes from the read-optimized result. I do have a few concerns though:
- The PR competes with #22128, although I prefer this PR.
- I don't like the implicit deref to
Mesh(comment), although that could be changed in a follow up. InfallibleMeshis not an intuitive name. ButMeshBuilderis already taken. MaybeCustomMeshBuilder?MutableMesh?
Also in case it helps when merging main, InfallibleMesh needs the skinned mesh bounds methods pasted in. And mesh picking needs the changes from #22356.
|
It looks like your PR is a breaking change, but you didn't provide a migration guide. Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes. |
|
if we changed |
|
Personally, I think this is controversial and am not convinced about this PR:
|
|
I'm adding the |
|
Similarly not super keen on the prospect of additional code duplication here, but I agree that the mesh ergonomics situation with unwraps is not great. I am content to largely defer to our assorted SMEs here though. |
|
For what it's worth, my guess is that the duplication is mostly temporary. So in the future |
Objective
InfallibleMeshbuilder type suggested by @greeble-dev in Retain asset without data for RENDER_WORLD-only assets #21732 (review)try_xxxmethods fromMesh, make the base methods returnResultsSolution
builds on #21732 - could replace that, but i thought better to raise a different PR to keep the changes separated as this touches quite a lot more of the codebase. to see the diff for just this pr i created https://github.com/robtfm/bevy/pull/5/files which applies this onto the original pr.
InfallibleMeshtype for use during cpu-side mesh construction, which wrapsMeshand ensures that the internal mesh data can't be extracted.From<primitives> for Meshcode: remove ~30 individualFrom<T> for Meshimplementations and replace with a blanket impl, supported by modifyingMeshable::meshto takeselfinstead of&self. basically all existing implementations were copying or cloning self anyway, so this doesn't seem like it should cause any issues.Changelog
Existing accessor methods on
Meshhave been changed to return aResult<T, MeshAccessError>which will return an error if the Mesh has been extracted to theRenderWorld.When constructing meshes we now recommend using the
InfallibleMeshtype which guarantees the internal data cannot be extracted prior to being converted into a normal mesh.