i made a subdivided Icosahedron in Blender and split it at all edges so that i was left with zero shared vertices. I triple checked that.
Now, i imported that into Unity and am creating “continents” by assigning UV-coordinates to the vertices. I do that by going through each triangle in the triangles-array, find the three corresponding vertices, and assign three equal UV-values to them. That combined with some Perlin-Noise leaves me with the desired effect.
However, i noticed some strange behaviour at the “edges” of the continents, resulting in gradients that should not be there. When checking the UV-coordinates and vertex-indices of the triangles at runtime, i got the following result:
At the top, the selected triangle (with the white border) consists out of the vertex-indices
P0(4210)
P1(4211)
P2(1251)
The one at the bottom out of
P0(1250)
P1(4210)
P2(1251)
with two vertices (4210 and 1251)and thus their UV-coordinates (0.5, 0.8) being shared, resulting in the intended water-triangle having two vertices with green UV-coordinates, which is not what i want.
So my question is, how do i avoid my icosphere having shared vertices? I checked again in Blender, but it is all just how i want it there, with no vertices shared. Is this a problem with Unity altering (optimizing) the mesh when importing, or what did i do wrong to not have the mesh imported with no shared vertices?
For imported models you should never
call this as the import pipeline
already does it for you.
I suspect that Unity is automatically merging identical vertices when you import the mesh.
Here’s one way to hack around it…
int[] sourceIndices = sourceMesh.GetTriangles(0);
Vector3[] sourceVerts = sourceMesh.vertices;
Vector2[] sourceUVs = sourceMesh.uv;
int[] newIndices = new int[sourceIndices.Length];
Vector3[] newVertices = new Vector3[sourceIndices.Length];
Vector2[] newUVs = new Vector2[sourceIndices.Length];
// Create a unique vertex for every index in the original Mesh:
for(int i = 0; i < sourceIndices.Length; i++)
{
newIndices *= i;*
unsharedVertexMesh.SetTriangles(newIndices, 0); What this does is create a new mesh using the same triangle indices as the original, but with unique copies of every vertex. As long as you don’t call Optimize() on it, Unity should leave this the way you want it. (Note that the code above assumes the mesh contains only one submesh) _*[1]: http://docs.unity3d.com/Documentation/ScriptReference/Mesh.Optimize.html*_
mesh=GetComponent<MeshFilter>().mesh;
// unshare verts
int subMeshCnt=mesh.subMeshCount;
int[] tris=mesh.triangles;
int triCnt=mesh.triangles.Length;
int[] newTris=new int[triCnt];
Vector3[] sourceVerts = mesh.vertices;
Vector3[] sourceNorms = mesh.normals;
Vector2[] sourceUVs = mesh.uv;
Vector3[] newVertices = new Vector3[triCnt];
Vector3[] newNorms = new Vector3[triCnt];
Vector2[] newUVs = new Vector2[triCnt];
int offsetVal=0;
for (int k=0; k<subMeshCnt; k++)
{
int[] sourceIndices = mesh.GetTriangles(k);
int[] newIndices = new int[sourceIndices.Length];
// Create a unique vertex for every index in the original Mesh:
for(int i = 0; i < sourceIndices.Length; i++)
{
int newIndex=sourceIndices*;*
Hi, I think you need to have submeshes to have different UV for the same vertex. Unity mesh has 1 UV for each vertex (and UV2 but that’s something different). Check the documentation about submeshes, GetTopology etc… This is basically a mesh composed of multiple meshes.
The interesting part is that each submesh can have its own material and then it’s own set of UV, but some vertices will be duplicated (shared vertices won’t be anymore between multiple submeshes)
In Blender, you have to assign multiple materials to your mesh so that Unity imports multiple materials and creates submeshes. This involve marking “seam” in the UV editing, I did this long time ago and don’t remember exactly how, you can find tutorials about assigning materials on youtube.