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

[Unity plugin] Reuse vertex indices when importing STL meshes #1353

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

Balint-H
Copy link
Collaborator

@Balint-H Balint-H commented Jan 20, 2024

This PR makes modifications to the STL IO of the Unity plugin. Changes:

  • Writes only the new bytes of the buffer to the file, which avoids having trailing nulls in the imported and scaled STL. Blender and other STL viewing software treated the files with trailing nulls as corrupted.
  • Using a dictionary, indices of shared vertices are reused during the import. This allows loading larger meshes with the same index resolution, and the resulting files are smaller and render faster (~20%-40% smaller asset files in the MPL hand for example).
  • Switch to 32bit indexing if 16 bits are not sufficient even with index reusing.

Tested with the MuJoCo mug, and the MPL hand.

It was unclear to me why was it necessary to perform axis swizzling in the STL writer part as well, and not just the parser. As I was working on this PR, meshes imported 90 degrees rotated sometimes. Removing the swizzling from there resolved that. In case I missed a case where that was key for the proper import, let me know @erez-tom.

EDIT: I re-reviewed my test cases and noticed I accidentally added an extra axis swizzling to the source mesh files when I decimated/subdivided the meshes to test with different vertex counts. Checking with the original mesh files revealed that swizzling on the writer too is necessary, so I added that back to the PR quickly.

@vidurvij-apptronik

Fixes #1244, replaces #1254

@Balint-H Balint-H changed the title [Unity plugin] Reuse STL indices [Unity plugin] Reuse indices when importing STL meshes Jan 20, 2024
@Balint-H Balint-H changed the title [Unity plugin] Reuse indices when importing STL meshes [Unity plugin] Reuse vertex indices when importing STL meshes Jan 20, 2024
@vidurvij-apptronik
Copy link

The decision to use UInt32 only when the vertex count exceed the limit is for memory optimizing reasons?

@Balint-H
Copy link
Collaborator Author

Yeah, using 16 bit will result in smaller assets, and faster loading scenes (the impact would only be noticeable on mesh heavy scenes). With the index reusing implemented, more meshes will be able to use 16 bit. Please let us know if the new implementation works for you!

Since the 3.1.2 dll is not released yet, and this PR is for the upcoming 3.1.2 compatible version of the plugin, if you want to try it now you'd need to backport the parser to your fork (just copy and paste the stl parser from this PR)

@vidurvij-apptronik
Copy link

@Balint-H I tested this with my use case and it works perfectly.

@copybara-service copybara-service bot merged commit 4fe16dd into google-deepmind:main Jan 29, 2024
14 checks passed
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

Successfully merging this pull request may close these issues.

Support for 32 Index format for higher mesh size
3 participants