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

Enable more than 65k vertices per baked mesh #2

Open
AtomicJoe1 opened this issue Sep 8, 2020 · 2 comments
Open

Enable more than 65k vertices per baked mesh #2

AtomicJoe1 opened this issue Sep 8, 2020 · 2 comments

Comments

@AtomicJoe1
Copy link

Not an issue but an improvement:
On Unity 2017 or higher, you can have more than 65000 vertices per mesh changing the Mesh.indexFormat to 32bits.
I modified MeshBaker.cs to support up to 2 billion vertices in a single mesh:

change line 17:
private const int MAX_VERTEX_COUNT_PER_ONE_OBJECT = int.MaxValue-1;// 65000;
change line 277:
newMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
that's it.

Note: in theory, Unity should support up to 4 billion vertices, not "just" 2 billion, using UINT instead of INT as max value, but since the C# vertex list index property seems to be only in INT format, I settled for 2 billion vertices to avoid any possible issues.

@AtomicJoe1
Copy link
Author

Note that not all devices accept 32bit index formats, (some Mali GPUs on Android don't) so this should ideally be an option.

Also, using 32bit index when not needed increases bandwidth unnecessarily, so if vertex number is lower than 65k, using the default 16bit index format will be faster, specially on mobile.
So line 277 should be better like this:
if (vertexes.Count>65000) newMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

@Kovnir
Copy link
Owner

Kovnir commented Sep 9, 2020

Nice catch! Thank you!

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

2 participants