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 karlog · Nov 13, 2013 at 07:08 AM · textureuv mappinghexagonhex

Help mapping Square Texture to Hex Shape Mesh.

I want to map a Square Texture to a Hex Shaped Mesh. I have the Mesh with 4 Triangle & 6 Vertices. I want to do this using Code, dynamically.

Here is the Code I used.

Script Name : "Plance.cs"

 using UnityEngine;
 using System.Collections;
      
 public class Plane : MonoBehaviour
 {
     public Vector3[] Vertices;
     public Vector2[] UV;
     public int[] Triangles;
      
     void MeshSetup ()
     {
         float halfHeight = 0;
         Vertices = new Vector3[] {
             new Vector3 (-1, halfHeight, 0),
             new Vector3 (-.5f, halfHeight, Mathf.Sqrt (3) / -2),
             new Vector3 (.5f, halfHeight, Mathf.Sqrt (3) / 2),
             new Vector3 (-.5f, halfHeight, Mathf.Sqrt (3) / 2),
             new Vector3 (.5f, halfHeight, Mathf.Sqrt (3) / -2),//
             new Vector3 (1, halfHeight, 0)//
         };
         UV = new Vector2[] {
             new Vector2 (0.5F, 0.87F),
             new Vector2 (0.87F, 0.13F),
             new Vector2 (0.13F, 0.87F),
             new Vector2 (0.87F, 0.87F),
             new Vector2 (0.13F, 0.13F),
             new Vector2 (0.5F, 0.13F)
         };
         Triangles = new int[] {
             0,3,1,
             3,2,1,
             1,2,4,
             4,2,5
         }; 
     }
      
     void Start ()
     {
         MeshSetup ();
         Mesh stuff = new Mesh ();
         gameObject.AddComponent<MeshFilter> ().mesh = stuff;
         stuff.vertices = Vertices;
         stuff.triangles = Triangles;
         stuff.uv = UV; 
     }
 }

I have attached this Script to an Empty Game Object. It has a Material attached to it with the Texture.

I have attached the Exported Package.

Click Here to Download Unity Package

I need it to look like this :

HEX_NEEDED

This is how it looks like now : Hex_Current_State

Immediate responses are appreciated.

hex_needed.png (330.9 kB)
hex_actual.jpg (279.0 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 karlog · Nov 14, 2013 at 06:14 AM

I have fixed it. The following code fixes the issue when having the material with tiling x=-1 and y=1.

Here is the Code : using UnityEngine; using System.Collections;

 public class Plane : MonoBehaviour
 {
     public Vector3[] Vertices;
     public Vector2[] UV;
     public int[] Triangles;
     
     void MeshSetup ()
     {
         float halfHeight = 0;
         Vertices = new Vector3[] {
 //            new Vector3 (0, halfHeight, 0),
             
 
             new Vector3 (-.5f, halfHeight, Mathf.Sqrt (3) / 2),
             new Vector3 (-1f, halfHeight, 0),            
 
             new Vector3 (-.5f, halfHeight, Mathf.Sqrt (3) / -2),//
             new Vector3 (.5F, halfHeight,Mathf.Sqrt (3) / -2),//
             new Vector3 (1F, halfHeight, 0),
             new Vector3 (.5f, halfHeight, Mathf.Sqrt (3) / 2),
             
         };
         UV = new Vector2[] {
             
 //            new Vector2 (0.5F, 0.5F),
             new Vector2 (0.75F, 0.87F),
             new Vector2 (1F, 0.5F),
             
             new Vector2 (0.75F, 0.13F),
             
             new Vector2 (0.25F, 0.13F),
             new Vector2 (0F, 0.5F),
             new Vector2 (0.25F, 0.87F),
             
 
             
             
         };
         Triangles = new int[] {
             2,4,3,4,2,5,1,5,2,0,5,1,
 //            0,1,5,1,2,5,2,4,5,2,3,4,
 //            1,6,0,6,5,0,5,4,0,4,3,0,3,2,0,2,1,0,
             //            1,2,0,2,3,0,3,4,0,4,5,0,5,6,0,6,1,0,
             //            0,3,2,0,2,1,0,1,6,0,6,5,0,5,4,0,4,3
             //            0,4,3,0,3,2,0,2,1,0,1,6,0,6,5,0,5,4
             //            0,1,6,0,6,5,0,5,4,0,4,3,0,3,2,0,2,1,
         }; 
     }
     
     void Start ()
     {
         MeshSetup ();
         Mesh stuff = new Mesh ();
         gameObject.AddComponent<MeshFilter> ().mesh = stuff;
         stuff.vertices = Vertices;
         stuff.triangles = Triangles;
         stuff.uv = UV;
     }
 }
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

16 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

Related Questions

How can i achieve texturing of a dynamic generated Hex? 0 Answers

Get texture with UV Mesh Mapping 0 Answers

3DS Max Seams from Unity Cubes 2 Answers

Render Texture out from a 3D Object 1 Answer

Hexagon grid UV mapping 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