Skip to content

SimpleMeshBuilder#10928

Closed
stepancheg wants to merge 1 commit intobevyengine:mainfrom
stepancheg:mesh-builder
Closed

SimpleMeshBuilder#10928
stepancheg wants to merge 1 commit intobevyengine:mainfrom
stepancheg:mesh-builder

Conversation

@stepancheg
Copy link
Copy Markdown
Contributor

Constructing Mesh manually is somewhat not trivial.

SimpleMeshBuilder is a "builder" for mesh with positions, normals, uvs.

I use it my project, so I decided to submit it to bevy project. Not sure if it is universally helpful.

@Robert7301201
Copy link
Copy Markdown

TotalVec2 and TotalVec3 should probably be bevy::math::u32::UVec2 and bevy::math::u32::UVec3. Is there an advantage to using TotalVec2 and TotalVec3?

@stepancheg
Copy link
Copy Markdown
Contributor Author

stepancheg commented Dec 10, 2023

UVec2 and UVec3 store integer coordinates. TotalVec2 and TotalVec3 store float coordinates by transmuting them to integers.

So UVec2 and UVec3 could be used, but that might be misleading. Or just create TotalSimpleVertex instead of these two.

But I can get rid of TotalVec2 and TotalVec3 and just replace them with tuples.

@matiqo15 matiqo15 added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen labels Dec 10, 2023
@Robert7301201
Copy link
Copy Markdown

I think I understand now. It's a workaround to hash a Vec3 since floats can't be hashed.

I found a relevant discussion for the upstream glam-rs: bitshifter/glam-rs#123. That discussion links to https://internals.rust-lang.org/t/f32-f64-should-implement-hash/5436/33 which does offer the workaround of transmuting to u32.

I'd prefer keeping Total2 and Total3 since it clues the reader in that they're doing something special. Maybe consider renaming to HashVec2 HashVec3. Either way it'd be a good idea to document that their intended purpose is for hashing, unless I'm glossing over some other functionality.

That being said though, I wonder if it would be better to just have duplicate vertices. Would this be intended as more of a prototyping tool and some inefficiencies are acceptable, or should this be optimized?

@stepancheg
Copy link
Copy Markdown
Contributor Author

Maybe consider renaming

OK, I'll try something.

That being said though, I wonder if it would be better to just have duplicate vertices.

Might be a lot of duplication. Consider common mesh like this (e.g. when creating a sphere):

image

Here each vertex is shared by 6 triangles, and not deduplicating it may result in significant memory usage increase.

Would this be intended as more of a prototyping tool and some inefficiencies are acceptable, or should this be optimized?

I'm not an enterprise game developer, so I don't really know how often people generate meshes programmatically rather than just loading them from GLTF.

@stepancheg
Copy link
Copy Markdown
Contributor Author

Replaced TotalVec2 and TotalVec3 with simpler SimpleVertexHashable.

@stepancheg stepancheg force-pushed the mesh-builder branch 2 times, most recently from 3aacd09 to 50e4d2f Compare December 10, 2023 20:23
github-merge-queue bot pushed a commit that referenced this pull request Jan 28, 2024
By writing a test.

For changes like #10928, it is
useful to observe possible behavior change not only by running examples.
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
By writing a test.

For changes like bevyengine#10928, it is
useful to observe possible behavior change not only by running examples.
@janhohenheim
Copy link
Copy Markdown
Member

@ethereumdegen is this something that would be useful for terrain generation?

Copy link
Copy Markdown
Member

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Our mesh api is kind of annoying to work with but I feel like I'd like to better understand the pain points there and whether we can improve them rather than just adding a more normative "simple" type.

@cart
Copy link
Copy Markdown
Member

cart commented Aug 16, 2024

Yup any proposal for a SimpleX type is an indicator that we need to improve our existing APIs, not add a new one. My gut reaction is that we should enumerate the problems being solved here and try to solve them in the core types.

@janhohenheim janhohenheim added the X-Needs-SME This type of work requires an SME to approve it. label Sep 14, 2024
@IceSentry
Copy link
Copy Markdown
Contributor

I'd prefer seeing this in a crate first.

Also, this could potentially be implemented as free functions in the mesh module that take in the &mut Mesh and the fixed list of vertex data and append it to the end of the respective arrays.

@cart
Copy link
Copy Markdown
Member

cart commented Oct 1, 2024

Yup closing this out as there appears to be rough consensus that doing this upstream isn't the move.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible X-Needs-SME This type of work requires an SME to approve it.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants