• 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 Yanger_xy · Jun 18, 2011 at 05:33 PM · meshuvalign

How to align texture when comes to a corner

I draw a rect tunnel using Mesh, It all works well. What is the problem is:How can i align its texture with the tunnel.For example, when the tunnel turns off, the texture i assigned does turn at all by using codes like this:

 uvs[i] = vertices[i];

And here are two pictures, the first one is the wrong one. and the second is what i want.

alt text

pic 1

alt text

pic 2

The next two pictures may be more clear.

alt text

pic3 Look at the small green arrow,i wanna the texture align with it not the red one on its left.

alt text

Pic4 this is what i want

Hope that it's clear.Any answer will be appreciate!

Comment
Add comment · Show 5
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 Marnix · Jun 18, 2011 at 06:06 PM 0
Share

Had to look twice or thrice, but I see what you mean. Is your hallway only one quad or are they multiple triangles and follow the walls?

avatar image Yanger_xy · Jun 19, 2011 at 02:55 AM 0
Share

The hallway is made up of four $$anonymous$$eshes, left,right,top and bottom.So i can handle it separatly

avatar image Marnix · Jun 19, 2011 at 10:28 AM 0
Share

@Yanger_xy: How many triangles is the floor alone?

avatar image Yanger_xy · Jun 19, 2011 at 08:15 PM 0
Share

it's dynamically generated, the triangles count is not fixed.

avatar image Marnix · Jun 19, 2011 at 08:17 PM 0
Share

@Yanger_xy: Isn't my answer satisfying yet?

2 Replies

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

Answer by Marnix · Jun 19, 2011 at 06:14 PM

Let's give it a try. This is the correct way of doing it, and it completely depends on you uv-coordinates. As you describe, you only set your uv-coordinates to the vertex position in real-world. This means, that you will get uv-coordinates like (100,350,1). So what happens if you go around the corner? Nothing, because you do not catch that in your coordinates.

Your coords should go like this: uv-coordinates

You see that the image actually goes around the corner. uv-coordinates are not numbers going from position to position. They have their own values. Normally, a quad or a complete mesh goes from (0,0) to (1,1), but you can also let them continue past that number. If you do so, like in the above example, you need to assign your texture to be repeated (or mirror repeated) and not clamped.

So during your for-loop, you need to assign values that correspond to these values in the example.

Extra info here:

  • http://msdn.microsoft.com/en-us/library/bb206245%28v=vs.85%29.aspx

  • http://en.wikipedia.org/wiki/Texture_mapping

Comment
Add comment · Show 6 · 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 Yanger_xy · Jun 20, 2011 at 06:49 AM 0
Share

Thank you for your answer, It seems that your answer is great, but the picture after this sentence "Your coords should go like this:" can not be shown. I know uv varies from (0,0) to (1,1) and it can repeat if its coordinate is larget than it, but i am still not very clear about how to align it when the hallway turns.Please forgive my bad understanding ability!Thanks

avatar image Marnix · Jun 20, 2011 at 08:43 AM 0
Share

The link to the image is: http://img14.imageshack.us/img14/8509/uvcrooked.png

Does that work?

avatar image Yanger_xy · Jun 21, 2011 at 03:31 AM 0
Share

Yeah,It works.Thank you for your patient answer!

avatar image Yanger_xy · Jun 21, 2011 at 11:04 AM 0
Share

Hi,$$anonymous$$arnix.Here comes another problem that if i assign the uv coordinates like the picture shown above, the texture will be distorted greatly if the distance is too far between two vertices.For example, let's say there are six vertices on a mesh, and the distance between them are all very far(100m width, and 5000m length or something like this),the texture will be distorted or stretched even if it doesn't comes to a corner,not to speak of the corner! Am i right? Is there a way that keep the texture not be distorted, and when come across the corner, it align with it.

avatar image Marnix · Jun 21, 2011 at 11:20 AM 0
Share

@Yanger_xy: Ah yes of course, you are right with that. You can't just assign 1,2,3 to values that have a scale. You have to make these values in a way that they are scaled to the length of your object's vertex positions. The only thing that is actually important in this scheme, is that you keep the lower line on 0, because that is your reference point. The upper line doesn't have to be 1, but this does make sure that your line will go around the corner.

Show more comments
avatar image
1

Answer by Peter G · Jun 19, 2011 at 12:42 PM

Here's an idea, its not great because it will cause some stretching, but I would map it so that the floor is in a straight line on your uv map. Something like:

 _________________
 |               |
 |               |
 -----------------
 |               |
 -----------------
 |               |
 |               |
 -----------------

then when the path turns, the uvs will rotate in that direction. If you're doing it procedurally. If you're doing it manually, then your can definitely do a better job than this.

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 Yanger_xy · Jun 20, 2011 at 08:25 AM 0
Share

It is a way out,i have thought about that before,.But i want to know how to handle the uv coordinates procedurally.I am not very clear about aligning uv,that is the problem. thank you

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Check if a mesh has UV map at runtime 1 Answer

Unity Shadergraph Alpha threshold problem 0 Answers

Is this a bug in Unity? 0 Answers

Meshes not respecting Blender uv maps 3 Answers

UV map on an arch/ color issue 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