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 vipvex · Apr 15, 2012 at 01:40 AM · proceduralcubeuvmapping

Help Uv mapping !!!

I have made a script that procedurally creates a cube and i need help uv mapping it. When it generates the texture looks all messed up and i don't know how to fix it. I compared my procedural cube to the cube the one that's comes with unity and it seems that the unity cube has 24 vertexes while mine has 8. May that be the problem? Here's my script: var check : boolean = true;

function Start () {

 var mesh : Mesh = GetComponent(MeshFilter).mesh;
 
 var vertices : Vector3[] = new Vector3[8];
     
     vertices[0] = new Vector3(.5, .5, .5); //high-top-left  (.5, .5, .5)
     
     vertices[1] = new Vector3(.5, .5, -.5); //high-top-right (.5, .5, -.5)
     
     vertices[2] = new Vector3(-.5, .5, -.5); //high-bottom-left (-.5, .5, -.5)
     
     vertices[3] = new Vector3(-.5, .5, .5); //high-bottom-right (-.5, .5, .5)
     
     vertices[4] = new Vector3(.5, -.5, .5); //low-top-left 
     
     vertices[5] = new Vector3(.5, -.5, -.5); //low-top-right
     
     vertices[6] = new Vector3(-.5, -.5, -.5); //low-bottom-left
     
     vertices[7] = new Vector3(-.5, -.5, .5); //low-bottom-right
  
 mesh.vertices = vertices;
 
 if (check){
     
 
     if (!Physics.Raycast (transform.position, Vector3.up, 1)) {
     
            print("Creating a face on top");
         
         mesh.triangles += [0, 1, 2, 0, 2, 3];
         
     }
    
 
     if (!Physics.Raycast (transform.position, Vector3.down, 1)) {
     
         print("Creating a face on botton");
         
         mesh.triangles += [7, 6, 4, 6, 5, 4];
     
     }
 
     if (!Physics.Raycast (transform.position, Vector3.right, 1)) {
     
         print("Creating a face on right");
         
         mesh.triangles += [0, 4, 5, 5, 1, 0];    
     
     }
 
     if (!Physics.Raycast (transform.position, Vector3.left, 1)) {
     
         print("Creating a face on left");
     
         mesh.triangles += [3, 6, 7, 6, 3, 2];
     
     }
 
     if (!Physics.Raycast (transform.position, Vector3.forward, 1)) {
     
         print("Creating a face on front");
              
         mesh.triangles += [0, 3, 4, 7, 4, 3];
     
     }
 
     if (!Physics.Raycast (transform.position, Vector3.back, 1)) {
     
         print("Creating a face on back");
     
         mesh.triangles += [5, 2, 1, 2, 5, 6];
     
     }
     
     var uvs : Vector2[] = new Vector2[8];
     
     uvs[0] = new Vector2(0, .5); //bottom-right
     
     uvs[1] = new Vector2(.5, .5); //middle
     
     uvs[2] = new Vector2(0,0); //bottom-left
     
     uvs[3] = new Vector2(.5, 0); //top-left
     
        uvs[4] = new Vector2(0, 0); //top-left
     
     uvs[5] = new Vector2(0.5, 0.5); //top-right
     
     uvs[6] = new Vector2(0, .5); //bottom-left
     
     uvs[7] = new Vector2(.5, .5); //bottom-right
     
     mesh.uv = uvs;
     
     mesh.RecalculateNormals();
     
     check = false;
 
 }

}

PS: I'v researched this but did not fined a answer.

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 Owen-Reynolds · Apr 15, 2012 at 05:30 AM

Yes, 8 vs. 24 verts is the answer. If you search around for "unwrapping a cube," there's no good way to position 8 verts so all 6 sides look good. So, modellers makes seams. A seam duplicates the verts along that edge, which allows you to appear to position, for example, the lower-right corner in 1 spot for the front face, and another for the side face. 24 verts simply repeats each vert once for each face (or, each face "owns" its unique four verts.)

Also, your numbers are odd. You have (0.5,0.5) as the middle, top-right and bottom-right. Normally, for textures, (1,1) is top-right, (1,0) is bottom-right, (0,1) is top-left, ... .

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 vipvex · Apr 15, 2012 at 07:01 AM 0
Share

THAN$$anonymous$$ YOU GOOD SIR !!!

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

Multiple Cars not working 1 Answer

Blender to Mixamo to Unity3D 1 Answer

Create planar UVs on procedurally generated mesh 1 Answer

help making map! 1 Answer

Automatic UV Mapping for a Cube in C# 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