Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dan_wipf · Apr 22, 2020 at 11:55 AM · meshuvfor-loop

Mesh UV min/max Y position

Hey there.

Does anyone know when you loop through a mesh, how to know when uv.y is on its bottom position (mesh.uv[i].y == lowest possible position) and when it reached his top position? (mesh.uv[i].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

 //in a For Loop 
 color[i] = new Color (1,UV[i].y,UV[i].y);

Small PIC Heres the link to a bigger res of the picture OneDrive

ua-chart-small.png (512.3 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Apr 22, 2020 at 03:06 PM 0
Share

I'm not sure what you mean by "looping though a mesh" ^^. Also what $$anonymous$$ and max values you have in $$anonymous$$d? In general texture space goes from 0 to 1 in both axes, U and V. However values outside that range will also result in a mapping but that depends on the textures wrapmode.

If the wrapmode is set to "clamp" it just means that the outermost texels are used. In essence the texture coordinates are clamped between 0 and 1 internally. So a value of 2.3 would just be 1.0 and a value of -0.2 would become 0.0.

A wrapmode of repeat can be imagined as if the texture is repeated in all directions. This is essentially the same what $$anonymous$$athf.Repeat does with a length of 1. So a value of 2.3 would become 0.3 and a value of -0.2 would become 0.8.


It would help if you could go more into detail what you want to do :)

avatar image dan_wipf Bunny83 · Apr 22, 2020 at 08:44 PM 0
Share

Hey Thanks!
Ok what i want to do is following. Paint vertex colors on a Tree.

the color channels are following: - R: $$anonymous$$ain Wind Bending - G: Random Wind Phase on Leafs - B: Shivering on Leafs


so as a little example:

 for (int i = 0; i<mesh.colors.Length; i++)
     {
     // $$anonymous$$ain Bending Calculation
         col[i] = Color.Lerp(new Color(0,0,0),new Color(1,0,0),currentHight / mesh.bounds.size.y);
     // Rest Calculations 
     if (isLeaf)
     {
         var WindPhase = $$anonymous$$athf.Lerp(0, Random.value, currentUV_Y_pos / maxUV_Y_pos);
         var fluttering = $$anonymous$$athf.Lerp(0, DistanceTo$$anonymous$$eshCenter * WindPhase, currentUV_Y_pos / maxUV_Y_pos);
         col[i] = new Color(col[i].r, WindPhase, fluttering);
     }
                 
 }

if i do not know where the Face of the Leaf begins, the results are in floating, not connected to the Trunk/Branch Leafs.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Apr 23, 2020 at 12:51 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dan_wipf · Apr 23, 2020 at 06:27 AM 0
Share

Hey Thanks again =)

i've updated my Question with some Pictures!

avatar image
1

Answer by CiberX15 · Apr 22, 2020 at 03:09 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dan_wipf · Apr 22, 2020 at 06:26 PM 0
Share

hm thats what i thought first aswell! but then i remeber blender and its uv editor, where you can clearly scale the uve over the border of the image. need to investigate further but thanks alot!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animated tiles and blending between different tiles on a mesh tilemap 0 Answers

How to set up UV for lightmaps for generated meshes? 4 Answers

texturing a procedurally created mesh 0 Answers

Mesh breaks apart when using vertex displacement with shadergraph. 3 Answers

Change uvs on texture packing 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges