Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by dchen05 · May 21, 2013 at 12:03 AM · meshproceduraluvuvs

Create planar UVs on procedurally generated mesh

I have a completly flat 2D mesh that is being generated procedurally. ( more info here http://forum.unity3d.com/threads/181596-Triangulation-of-spline-to-mesh-questions-and-results )

The mesh was generated from this image that I'm now trying to apply as a texture, so I'm trying to get the UV's to work.

         Vector2[] endingUVs = new Vector2[finalVerts.Count];
         Bounds bounds = newMesh.bounds;
 
         for(int k = 0; k < fVerts.Length;k++) {
             Vector2 aUV = new Vector2((fVerts[k].x/bounds.size.y)*-1, (fVerts[k].y/bounds.size.y));
             endingUVs[k] = aUV; 
         }
         newMesh.uv = endingUVs;


Here are things I have found out:

  • Dividing by bounds.size.Y both times gives me the closest size at the correct aspect ratio (my image isn't quite square 492w*470h)

  • Multiplying by -1 gives me the right flip on the X axis

  • Afterward setting the offset to .5 and .5 in the editor makes it centered. (like below, at offset 0, 0 its in the top right)

alt text

Any ideas how I can get this sized correctly in a procedural way that will work for any image?

If I print out the values of some of the UV's I'm making I am getting some negative ones because naturally some of the vertices have negative positions. (0.3, -0.2) etc, when I try Math.Abs on the values that doesn't seem to give the desired results either.

Also I found this which is very similar code to what I have: http://docs.unity3d.com/Documentation/ScriptReference/Mesh-bounds.html

screen shot 2013-05-20 at 7.46.54 pm.png (202.5 kB)
Comment
Add comment
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

1 Reply

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

Answer by dchen05 · May 21, 2013 at 03:03 AM

Figured it out, ignore my rambling above. It turns out I was using the wrong bounds. The

The newly generated mesh had a tighter bounds, thus I was getting a smaller projection of the image, which makes sense.

What I wanted to use was the bounds of the original plane (not pictured here), which is the same size as my character texture, and makes for a correct planar projection. Awesome.

So yeah I was second guessing it, but the formula found here is pretty sound, just make sure you use the right bounds :) http://docs.unity3d.com/Documentation/ScriptReference/Mesh-bounds.html

Comment
Add comment · 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

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

13 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

Related Questions

Manual UV-Mapping of a Primitive Cube 1 Answer

Easy way to convert a bunch of vertices to triangles or uv's? 1 Answer

Scale mesh but keep original uv? 0 Answers

Check if a mesh has UV map at runtime 1 Answer

Procedural Mesh UVing 2 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