I created an triangle mesh with 3 vertices and 1 triangle with 3 indices. But when I apply an material the MainTexture isn't showing on the triangle. I think it is about the uvs. That's how I generate the mesh: Code (CSharp): void Start() { mesh = new Mesh(); mesh = GetComponent<MeshFilter>().mesh; //lastxSize = xSize; //lastm = m; CreateMesh(); RenderMesh(); //AssetDatabase.CreateAsset(mesh, "Assets/Cloth.asset"); //AssetDatabase.SaveAssets(); } // Update is called once per frame private void Update() { //RenderMesh(); //if(lastxSize != xSize) //{ //CreateMesh(); //lastm = removeX; //lastxSize = xSize; //} if (save == true) { RenderMesh(); save = false; AssetDatabase.CreateAsset(mesh, "Assets/sails.asset"); AssetDatabase.SaveAssets(); } } void CreateMesh() { //vertices = new Vector3[(xSize + 1) * (zSize + 1)]; vertices = new Vector3[3]; for (int i = 0, z = 0; z <= zSize; z++) { for (int x = 0; x <= xSize; x++) { if (i < 3) { vertices[i] = new Vector3(x, 0, z); i++; } } } triangles = new int[xSize * zSize * 3];//*only 3 triangle indicies int vert = 0; int tris = 0; for (int z = 0; z < zSize; z++) { for (int x = 0; x < xSize; x++) { triangles[tris + 0] = vert + 0; triangles[tris + 1] = vert + xSize + 1; triangles[tris + 2] = vert + 1; //triangles[tris + 3] = vert + 1; //triangles[tris + 4] = vert + xSize + 1; //triangles[tris + 5] = vert + xSize + 2; vert++; //tris += 3; } vert++; } } void RenderMesh() { mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); GetComponent<MeshCollider>().sharedMesh = mesh; }
I think it's something in your logic, your loops or something. This works fine for me, I get a single pair of triangles, one facing each direction: Code (csharp): void Start() { var mesh = new Mesh(); mesh.vertices = new Vector3[] { new Vector3( 0, 0, 0), new Vector3( 0, 1, 0), new Vector3( 1, 0, 0), }; mesh.uv = new Vector2[] { new Vector2( 0, 0), new Vector2( 0, 1), new Vector2( 1, 0), }; mesh.triangles = new int[] { 0,1,2, 0,2,1, // doublesided }; AssetDatabase.CreateAsset(mesh, "Assets/Fnord.asset"); AssetDatabase.SaveAssets(); } I don't even recalculate bounds or normals or anything (you probably should).
Yes, but I didn't work with uvs in unity especially c# only in modeling softwares like blender where all is visualized
I'm sorry, I misunderstood your question. I thought you weren't seeing ANYTHING working... well, UVs should save (I see them in my file even though I never set them), but as for what texture is on a mesh, that has nothing to do with the mesh. That is entirely the renderer. Here's what goes in: Assets: Mesh Textures Material <- can have colors and texture references Components MeshFilter <- has a Mesh MeshRenderer <- has a Material EDIT: I added UV adding to the script above; works fine; put a textured material on a MeshRenderer and see.
Yep, the mesh generation worked for my the first time I have some troubles with applying some texturing: Isn't this related with uv mapping?
Actually no, pink usually means "no material" or else in some cases "no texture." Most often no material.
I don't mean the pink, I meant the fact that after applying the material the texture wasn't on the surface
This texture should be on the triangle: But it is a solid color. I'm not sure but I think it takes the color of 1 pixel from the texture and that's why the color is changing after changing the offset. Is there in unity an "unwrap" action like blender?
Not sure what your script state is now but I don't see you setting UVs... set them! See my edit example code. If you want more robust patterns for producing procedural geometry, you're welcome to lift stuff from my MakeGeo repository: MakeGeo is presently hosted at these locations: https://bitbucket.org/kurtdekker/makegeo https://github.com/kurtdekker/makegeo https://gitlab.com/kurtdekker/makegeo https://sourceforge.net/p/makegeo