By Code generated Mesh (problems with visibility)

Hey guys,

i tried to generate mesh by code, and what should i say, once i got it it works quite good.
there is just one thing i don´t understand. when i create something like a plane, or a flat circle, it is just visible from one side. how can i define on which side (which axis) the mesh is visible?

does it depend on the vertices, the triangles, the uvs ???

would be nice if someone can tell me.

While saschandroid is right, that solution will still keep it only visible from one side, but the opposite one. The reason this occurs is because of a technique known as “backface culling”. Backface culling is a technique to speed up rendering in 3D scenarios, by ignoring the back side of any models. Usually, this is not an issue, because the “back face” is inside the mesh, so you’ll never see it anyway. The only time it becomes a problem is when you have a flat object. Fortunately, you can fix it with shaders. You’ll have to use a custom shader, but usually it’s just a case of adding the line Cull Off into it. Unfortunately, this has the problem that both sides of the object will be lit the same, so if there is harsh directional light on one side of the plane, both sides will be lit just as brightly. The only real solution for this is to create what is essentially a very thin 3D mesh, with twice the number of triangles.

Here’s some more information about backface culling and the issues involved:

http://forum.unity3d.com/threads/48919-Backface-culling-in-Unity

EDIT: There is another solution, which uses custom shaders to render the back of objects, lit correctly. I have created a package on the asset store which can do just this. It allows for no extra triangles in the mesh (though it will still need to draw the mesh twice - once for the front and once for the back), and lights the surfaces correctly. It even supports normal maps!

it seem like the problem of back face culling, if the normal vector(depend vertexes sequence you create ) of a triangle face, it can be seen, or it is invisible, you can set the cull off in material

Which side is visible depends on how you build your triangles. Try to change the vertices order for e.g. from 0-1-2 to 2-1-0.

Mesh.RecalculateBounds was the solution for me.