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
0
Question by AxeSlash · Apr 09, 2015 at 04:28 AM · meshtilemapuvuv mappinguv coordinates

UV Tiling/repeat

I understand how UV coordinates works with regard to e.g. a simple quad - each vertex has a UV coordinate that ranges from 0,0 to 1,1 etc.

I'm procedurally generating a TileMap at the moment, where each tile contains two quads. I have a texture that I want to fill 2 quads, then do the same for each tile. Every other row is offset by one quad (half a tile - see pic below).

My question is: how would I map the texture correctly using Mesh.uv?

At the moment I'm doing something like this:

  for (int z = 0; z < Height; z++)
     {
         for (int x = 0; x < Width; x++)
         {
            
             lstUVs.Add((UVs.BottomLeft)+new Vector2(x,z));
             lstUVs.Add((UVs.TopLeft) + new Vector2(x, z) );
             lstUVs.Add((UVs.TopMiddle) + new Vector2(x, z) );
             lstUVs.Add((UVs.BottomMiddle) + new Vector2(x, z));

             lstUVs.Add((UVs.BottomMiddle) + new Vector2(x, z));
             lstUVs.Add((UVs.TopMiddle) + new Vector2(x, z) );
             lstUVs.Add((UVs.TopRight) + new Vector2(x, z) );
             lstUVs.Add((UVs.BottomRight) + new Vector2(x, z));
     }
 }
 mesh.uv = lstUVs.ToArray();

UVs.TopLeft etc are all just some static Vector2s containing e.g. 0,0, 0,1 etc depending which 'corner' they are.

That code works for the first row (the texture is displayed correctly), but all the other rows don't work (see attached pic).

I have checked that all the UV coordinates match up with the correct vertices during debug, it all looks correct to me in the data structure, so my conclusion is that I must be misunderstanding how UV coordinates work; to me it almost looks like the rows are 'sharing' the Z vertexes.

I tried applying a 0.5f X offset to the 'bottom' UV of each tile on an odd row, but that just screwed up the first row and made no difference to the rest.

So I'm guessing I have some misunderstanding of how UVs work; can someone enlighten me?

Thanks

alt text

*yes, the half-tile offset of the geometry every other row is intentional. The diagonal slant of the texture is not.

EDIT: If I remove the geometry offset from the 'odd' rows (so it's just a simple grid), my code works flawlessly - the texture tiles as it should. I have no idea why the offset screws it up.

borked.gif (91.9 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
0
Best Answer

Answer by AxeSlash · Apr 09, 2015 at 02:14 PM

I figured this out; in case anyone else has similar problems, I was setting mesh.triangles incorrectly; I made the mistake of thinking that a Vector3 was a reference type, and was using List.IndexOf to get the index of a vertex. Hence, it would return the first vertex with the same X, Y and Z coordinates as the one I passed it, instead of the correct instance of that Vector3, which existed further down the list.

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

2 People are following this question.

avatar image avatar image

Related Questions

Creating cube in script/ texture stretches on all sides but top and bottom? 1 Answer

Apply texture to a mesh on all 3 sides 2 Answers

Procedural Mesh UV problem 0 Answers

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

Texture on custom mesh splits at edge. 1 Answer


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