-
Notifications
You must be signed in to change notification settings - Fork 29
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
Mesh normals aren't correct #38
Comments
Thank you for your report!! |
Hey, great! So in case you want it, here's the code to weld vertices back together: https://pastebin.com/fSNYiUKf (like i mentioned, its a bit messy, but it works). You need to split them first, then do mesh.RecalculateNormals() and then weld it back together. Also, Im not sure how far you're interested in developing this tool, but as a brief FYI there are some interesting options there, especially in the area of manipulating the output mesh to make it more defined. Ive added several stuff to better suit the needs of my game, and aside from rotating/scaling the mesh one thats particularily intersting is modifying the vertex 'height' with the use of unity animation curves like so: It doesnt always work perfectly though, as its very reliant on vertex distribution around the edges, if its not dense enough then there might be some glitchy looking results. It would work best, if there was a way to add some spare vertices within the polygon after generating the sprite outline, but before triangulation, sort of a middle ground between what the 'OpaqueMesh' and 'GridMesh' do, im not sure if that's easily doable or not, i had a brief look at the generation code for both of those but it wasnt easy enough to read for me, maybe you'll have a better idea! :) |
Yeah, a height map would work too! Although the same issue would still apply, it would only be sampled where the vertexes are, so only around the outline of the sprite, to get any more detail we'd need more vertexes added within the polygon. |
That looks awesome, man, well done! Thank you for the update, Its definitely moving in the right direction! |
New version updated! |
This is awesome, thanks!
The triangulation of the OpaqueWithoutTightGrid part uses less vertices than the Grid mesh, so the faces end up being raised differently between them. This can be mitigated by using smaller grid mesh, which has a good chance of making the gaps less noticeable, but not eliminating them completely: Im only sharing this as an FYI in case you're interested, not asking you to fix it further, as its definitely good enough for my needs, the gaps wont be noticeable in my use cases (weapons being too small on the screen to notice). Once again, thank you for the amazing tool, its super useful! |
OK. I'll check this! |
Hey again, i noticed that the generated normals arent correct (left is how it looks, right is how it should look for a flat surface):

Its caused by the triangles sharing vertices (which is perfectly fine when you dont need to use normals, as it reduces the vert count to minimum), i fixed it on my end by splitting the vertices on the generated mesh using this little method: https://pastebin.com/QqpVQT75
You could make it an optional thing, as it does increase vert count quite drastically (triple the amount of triangles). They can however be welded back together afterwards (but respecting the normals this time), which will still be quite a bit more than the original but that's the choice here if someone wants correct normals. I can provide you with a welding method too, although its not as clean as its part of my much older code base.
The text was updated successfully, but these errors were encountered: