Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 BogyDruid · Sep 13, 2016 at 10:01 AM · textureuv mappinghexdynamic mesh

How can i achieve texturing of a dynamic generated Hex?

I have dynamically created a hex and i am trying to add a texture/material to it but it does not look good.

This is the code i am using:

 List<Vector3> vertices;
     List<int> triangles;
     public float floorLevel = 0;
     public Material material;
 public void GenerateMesh()
     {
         MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
         Renderer renderer = gameObject.AddComponent<MeshRenderer>();
 
         vertices = new List<Vector3>();
         triangles = new List<int>();
 
         Hex hex = new Hex(
             new Node(new Vector3(-1, floorLevel, -.5f)),
             new Node(new Vector3(-1, floorLevel, .5f)),
             new Node(new Vector3(0, floorLevel, 1)),
             new Node(new Vector3(1, floorLevel, .5f)),
             new Node(new Vector3(1, floorLevel, -.5f)),
             new Node(new Vector3(0, floorLevel, -1))
             );
 
         Vector2[] uv = new Vector2[]
         {
             new Vector2(0, .25f),
             new Vector2(0, .75f),
             new Vector2(.5f, 1),
             new Vector2(1, .75f),
             new Vector2(1, .25f),
             new Vector2(.5f, 0)
         };
 
         TriangulateHex(hex);
 
         Mesh mesh = new Mesh();
         mesh.vertices = vertices.ToArray();
         mesh.triangles = triangles.ToArray();
         mesh.uv = uv;
         mesh.RecalculateNormals();
 
         meshFilter.mesh = mesh;
         meshFilter.transform.rotation = Quaternion.Euler(0, 90f, 0);
 
         renderer.material = material;
     }

These are the images: alt text alt text

I want the hexagon texture to tile perfectly on the generated hexagon, but it tiles weirdly. Does anyone know what the problem is?

Thanks.

Later edit: Based on the comments bellow i tried to remake this hex, but still haven't managed to get it working

Here is a representation of what i did: alt text

So based on this image i created the following vertex positions:

  • left: 0, .5f

  • top-left: .25f, 1

  • bottom-left: .25f, 0

  • top-right: .75f, 1

  • bottom-right: .75f, 0

  • right: 1, .5f

I have created the following triangles based on corner positions:

  • 1, 2, 6

  • 2, 5, 6

  • 2, 3, 5

  • 3, 4, 5

The hex renders ok.

I then try to add the UV mapping on the hex. These are the points i use for the mapping (same vertex positions as above):

  • 0, .5f

  • .25f, 1

  • .75f, 1

  • 1, .5f

  • .75f, 0

  • .25f, 0

Still the texture does not tile over the generated hex, it is skewed like in the image above, in a different way, but still not correctly tiled. What am i doing wrong?

hexproblem.png (16.4 kB)
unity.jpg (291.3 kB)
Comment
Add comment · Show 4
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 Cherno · Sep 13, 2016 at 10:35 AM 0
Share

Your uv mapping is correct, but your vertex positions look off. For a hex at 0,0 world position, it should have the same vertex coordinates as the uv map coordinates. If I tilt my head and look at your screenshot, I see an imperfect hex. Then the uv map looks the same (no matter where the vertices are in world space, of course).

avatar image BogyDruid Cherno · Sep 13, 2016 at 01:28 PM 0
Share

So you are saying that the hex was built wrong, but the UV are correct? What is wrong? The vertex positions or the triangles?

avatar image Cherno BogyDruid · Sep 13, 2016 at 01:54 PM 0
Share

The vertex position are wrong.

alt text

hex.png (5.5 kB)
Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Help mapping Square Texture to Hex Shape Mesh. 1 Answer

is it possible adding text in realtime using shadergraph? 0 Answers

Can I independently manipulate UVs of a multi-material object? 0 Answers

white texture gets yellowish and weird at a distance 0 Answers

Texture tiling difference between unlit and surface shader? 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