Hey there.
Does anyone know when you loop through a mesh, how to know when uv.y is on its bottom position (mesh.uv_.y == lowest possible position) and when it reached his top position? (mesh.uv*.y == maximum possible position)?_
i need to paint the vertex color from bottom top like this:
vcol = Color.lerp(Color.clear,Color.red,(“uv y currentposition” / “uv y max position”));
sorry to tag you, but i’ve allready read severals answers from you regarding mesh and loops
_@Bunny83*_
thanks dan
EDIT 1:
Ok, if you look at the picture below, you will see following…
1. Bark / Stem on Submesh 0 and Leafs, which are all in Submesh 1
2. Vertex Color view of the Tree. Colors near the Bark are the same as the Bark (1,0,0). Colors at the end if the Leaf are (1,1,1)
3. UV is a propper box (Size (1,1))
So if i now procedurally change the Meshes Vertex Color, i’m getting not Correct results, with the method =>
i paint first all mesh on Submesh 0 then on Submesh 1 (getting submeshes based on a lovely solution by Bunny83 [Unity Answer][1]
//in a For Loop
color = new Color (1,UV_.y,UV*.y);
[157416-ua-chart-small.png*|157416]*
Heres the link to a bigger res of the picture [OneDrive][3]
*[1]: https://answers.unity.com/questions/1213025/separating-submeshes-into-unique-meshes.html*_
*
_*[3]: https://1drv.ms/u/s!AhpAG9wyQFGQv1Irz2nAbQZbn8et?e=JWolCd*_
If I recall correctly, UV coordinates are calculated from 0 to 1, regardless of the size of the image. So if your x and y coordinates are 0, then you are at the bottom left of the image. If they are 1, then you are at the top right. So if you wanted to figure out how close to the top you are you could just read from the Y position, 0.8f would mean you are 80% to the top of the image.
If you need to you can then back track to get how many pixels that is. I don’t remember the exact code but its something like:
Image.size.y * uv.y == number of pixels from bottom
Ok I’m still not entirely sure what you want to do. What I understood is that you want to perform some vertex painting (inside the editor?!) and you essentially want to filter the vertices based on what part of the UV map the vertex belongs to. Is that what you want to do?
As mentioned in the comment above the UV space itself doesn’t have an end. Even the texture itself is located between 0 and 1 where 0,0 is the bottom left corner and 1,1 the top right corner, you can specify coordinates greater than 1 / smaller than 0. Though those generally are mapped back to the 0 - 1 space based on the texture wrapmode.
If you have an unwrapped mesh in Unity you can use my UVViewer to view the UV map inside Unity. If you want to determine the min and max UV coordinates of your mesh you have to iterate through all vertices and just determine the min and max values. However I’m not sure how the min and max values would help to determine which vertices belong to which parts. This purely depends on the actual used texture and where the different parts are located on the texture.
Just to answer the question title: For a given mesh you can determine the min and max UV coordinate like this:
Vector2 min = Vector2.one * float.PositiveInfinity;
Vector2 max = -min;
var uvs = mf.sharedMesh.uv;
foreach(var uv in uvs)
{
if (uv.x < min.x) min.x = uv.x;
if (uv.x > max.x) max.x = uv.x;
if (uv.y < min.y) min.y = uv.y;
if (uv.y > max.y) max.y = uv.y;
}
This will essentially calculate the AABB of the first uv channel of all vertices in texture space.