karl- / pb_Stl

STL import/export for Unity, supporting both ASCII and Binary.
MIT License
179 stars 43 forks source link

Vertice count increases drastically on import #11

Closed AndreasLangberg closed 4 years ago

AndreasLangberg commented 5 years ago

An object which Blender tells me have 12k vertices somehow ends up with 70k vertices after using this script to import it to Unity. With Unity's 65k max vertices count pr mesh this is an obvious problem, not to mention performance in general.

karl- commented 5 years ago

The dramatic increase is likely due to the STL format splitting each triangle into discrete vertices. During export to STL instead of coincident vertices sharing a single vertex (like Blender is probably doing), each vertex referenced by a triangle becomes distinct.

To fix this on the import side we could define an option to import smoothed normals, and therefore share coincident vertices.

AndreasLangberg commented 5 years ago

That would be excellent. Just tested with another object with 8500 vertices, and after import ended up with 49500 vertices, nearly 6x as much. This would give us a roof of 11300 vertices pr mesh instead of the intended 65534.

karl- commented 5 years ago

I've started work on this in a the package branch. Installing the lib is a little different now, instead of putting the code in your Assets directory, instead just clone the repository into the Project/Packages directory.

AndreasLangberg commented 5 years ago

Tested and works. Vertice count is now equal with Blender with the smoothing option set to true. The direction of the imported model has changed tho, and the "UpAxis" option doesn't seem to be implemented, so I'm not able to make use of this quite yet. But so far so good!

Can I request an option to choose the mesh indexformat? So one can more easily set mesh.indexFormat to IndexFormat.UInt32 (Or even better, change it automatically if vertice count > 65k)? This way one doesn't have to deal with an array of meshes if vertice count goes beyond 65k. I don't expect to be working with any objects remotely close to that amount of vertices, but I am working with unknown imported data and I'd rather not deal with the rubbish CombineInstance solution Unity has for combining meshes if one weird one happen to go a little bit beyond.

karl- commented 5 years ago

Can I request an option to choose the mesh indexformat? So one can more easily set mesh.indexFormat to IndexFormat.UInt32 (Or even better, change it automatically if vertice count > 65k)?

Sounds like a great idea, can you open a new issue for it?

Morgan-6Freedom commented 4 years ago

Hello @karl- did you merge your package branch into the master ? Is this issue closed ? Thank you