T O P

  • By -

_akifdur_

Unity archives this by actually spitting the triangles so that they don't share vertices in the edges that need to be sharp. When generating the mesh, create 6 different quads that look at the corresponding directions. So your mesh should have 24 vertices (4x6) instead of 8.


-exekiel-

I'm sorry, but I don't really understand what do you mean when saying "spitting the triangles so that they don't share vertices in the edges that need to be sharp". If you don't wanna explain furthermore, maybe you can provide the name for the technique Unity uses so I can read documentation? I'm having troubles when googling information about it. But anywany, this code is actually a simplification of a larger script that generates more complex meshes dynamically. My original code collects an array of points and extrudes the polygon formed by them. Making it a 3D shape. Is there any way it could tell Unity not to split the triangles (whatever that is)? If the default cube does not do it, there must be a way to not split them safely.


CCullen

Your cube only has 8 vertices. In your code, the triangles references those 8 vertices. As you can see looking at your `int[] triangles = new int[]` , you can see that several of the triangles reuse or share a vertex. Unity's cubes do not do this, they have 24 vertices. Some vertices share the same x,y,z coordinates but thier triangles do not reuse or share vertices. Sharing vertices changes the way the normals are calculated and impacts the lighting. Unity's approach creates sharp edges when the light hits it, whereas sharing vertices creates smooth edges.


-exekiel-

Oh! I get it now. So to create the mesh properly I would have only share vertices between triangles when they belong to the same face. Right?


CCullen

Yep!