How can I add a TriangleMesh?

Hello everybody!

This is the problem I have: I have created an empty GameObject and I add a mesh Filter to it, but I want to be able to change the triangles of this mesh Filter as I want by script. So the idea is to do a this.GetComponent() in the script and edit it.

How would you do that?

Thanks in advance!

Sorry for only posting a link, but the docs explain it pretty well: Unity - Scripting API: Mesh

I already saw that script, but the code doesn’t work for the normals. Is there anything else I should do? Maybe the set up…
2971598--220729--upload_2017-2-24_12-12-31.png

Have you added code to set custom normals? works the same as setting vertices or UVs. Create an array of Vector3 and assign it to the mesh.normals property. It must be the same length as mesh.vertexCount.

Are normals Vector2? I thought they were Vector3, actually the code itself has Vector3 to define normals. I have added normals as you say, the code has no errors but nothing appears in the scene…
I am not sure how to set up UV’s either…but I think that is not important for now.

Yes, sorry, Vector3. Post the code, maybe I can see what’s wrong.

You’ve got 2 threads going for the same thing now; just for anyone else trying to follow along.
https://forum.unity3d.com/threads/mistake-in-meshes-creation-from-script.458010/

Possibly because the winding order of your triangle has it facing down and your looking at it from above.