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 seandolan · Oct 05, 2018 at 12:46 PM · meshtilemapuv

How do I apply a tilesheet to a procedural mesh and prevent bleeding?

I have the following code and I am struggling to wrap my head around UV mapping on a procedural plane made up for vertices and triangles to form a grid. I have changed he direction of the mesh to form out from 0,0 of the gameobject. Here is how I am making my mesh:

     public float tUnit = 10.0f;

     floorMap = new int[width,height];

         mesh = GetComponent<MeshFilter>().mesh;
         for(int x = 0; x < width; x++) {
             for(int y = 0; y < height; y++) {
                 floorMap[x,y] = Random.Range(0,2);
                 MakeTile(x,y);
             }
         }
     }
 
     void MakeTile(int x, int y) {
         newVertices.Add(new Vector3(x,0,y));
         newVertices.Add(new Vector3(x + 1,0,y));
         newVertices.Add(new Vector3(x + 1,0,y + 1));
         newVertices.Add(new Vector3(x,0,y + 1));
 
         newTriangles.Add((squareCount * 4) + 3);
         newTriangles.Add((squareCount * 4) + 1);
         newTriangles.Add((squareCount * 4) + 0);
         newTriangles.Add((squareCount * 4) + 3);
         newTriangles.Add((squareCount * 4) + 2);
         newTriangles.Add((squareCount * 4) + 1);
 
         squareCount++;
     }

As you can see in the order I am adding the triangles it is a little different than common methods of doing this. This is just so that the mesh expands out from the gameobject's 0,0 position correctly.

I am using the following function to convert a single int value (0 to 99) to the correct area of the tilesheet image I am using to place on the 3d mesh:

     Vector2 TextureMap(int _number) {
         return new Vector2((_number - (_number % 10)) / 10,_number % 10);
     }



For each of the tiles, I am looping through the following code:

                 Vector2 uv = TextureMap(floorMap[x,y]);
                 Vector2 uv1 = new Vector2(1 / tUnit,0);
                 Vector2 uv2 = new Vector2(1 / tUnit,1 / tUnit);
                 Vector2 uv3 = new Vector2(0,1 / tUnit);
                 Vector2 uv4 = new Vector2(0,0);
 
                 newUV.Add(uv1);
                 newUV.Add(uv2);
                 newUV.Add(uv3);
                 newUV.Add(uv4);



This works to some degree but doesn't take into consideration the actual offset of the tile from the tilesheet that I want to use. It just does the very first tile. Also the bigger part of the problem is that it seems to bleed the texture from the one next to it creating ugly lines between each square. I know that I have to use the Vector2 I am receiving back from my TextureMap function to offset to the right tile. Research also suggests that I need to implement "half pixel correction" into this method but I am unsure of how to implement each of these 2 things. I have tried a number of solutions and I believe the core problem I am having is that by swapping the order I am creating my triangles I am confusing myself too much. Making my problem too specific to directly implement solutions found on other questions on UA.

Any help would be appreciated.

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

0 Replies

· Add your reply
  • Sort: 

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

103 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

Related Questions

UV Tiling/repeat 1 Answer

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

Procedural Mesh UVing 2 Answers

Updating UV in imported mesh without having to re-material 0 Answers

Unity Shadergraph Alpha threshold problem 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