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
1
Question by tchesa · Jan 28, 2013 at 05:21 PM · meshcubenormalsmeshrenderernormal

Drawing a cube by a new Mesh

Hi guys, I am with a very simple problem, but it is blocking my work. I am instantiating a cube with a new Mesh, setting manually all the vertices, uv's, triangles and normals. This is my code:

 using UnityEngine;
 using System.Collections;
 
 public class cube : MonoBehaviour {
     public Vector3 index;
     void Start(){
         mesh.Clear();
         mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0), new Vector3(1, 0, 0),  //front
                                        new Vector3(1, 0, 1), new Vector3(1, 1, 1), new Vector3(0, 1, 1), new Vector3(0, 0, 1),  //back
                                        new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(1, 1, 1), new Vector3(1, 0, 1),  //right
                                        new Vector3(0, 0, 1), new Vector3(0, 1, 1), new Vector3(0, 1, 0), new Vector3(0, 0, 0),  //left
                                        new Vector3(0, 1, 0), new Vector3(0, 1, 1), new Vector3(1, 1, 1), new Vector3(1, 1, 0),  //top
                                        new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(1, 0, 0)}; //bottom
         mesh.uv = new Vector2[] {new Vector2(0, 0),    new Vector2(0, 1),    new Vector2(1, 1),    new Vector2 (1, 0),
                                  new Vector2(0, 0),    new Vector2(0, 1),    new Vector2(1, 1),    new Vector2 (1, 0),
                                  new Vector2(0, 0),    new Vector2(0, 1),    new Vector2(1, 1),    new Vector2 (1, 0),
                                  new Vector2(0, 0),    new Vector2(0, 1),    new Vector2(1, 1),    new Vector2 (1, 0),
                                  new Vector2(0, 0),    new Vector2(0, 1),    new Vector2(1, 1),    new Vector2 (1, 0),
                                  new Vector2(0, 0),    new Vector2(0, 1),    new Vector2(1, 1),    new Vector2 (1, 0)};
         mesh.triangles = new int[] {0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23};
         mesh.normals = new Vector3[] {new Vector3( 0, 0,-1),new Vector3( 0, 0,-1),new Vector3( 0, 0,-1),new Vector3( 0, 0,-1),  //front
                                       new Vector3( 0, 0, 1),new Vector3( 0, 0, 1),new Vector3( 0, 0, 1),new Vector3( 0, 0, 1),  //back
                                       new Vector3( 1, 0, 0),new Vector3( 1, 0, 0),new Vector3( 1, 0, 0),new Vector3( 1, 0, 0),  //right
                                       new Vector3(-1, 0, 0),new Vector3(-1, 0, 0),new Vector3(-1, 0, 0),new Vector3(-1, 0, 0),  //left
                                       new Vector3( 0, 1, 0),new Vector3( 0, 1, 0),new Vector3( 0, 1, 0),new Vector3( 0, 1, 0),  //top
                                       new Vector3( 0,-1, 0),new Vector3( 0,-1, 0),new Vector3( 0,-1, 0),new Vector3( 0,-1, 0)}; //bottom
     }
 }

The problem is: the bottom face normals are inverted, and i can't invert them. This is the cube made by this code, with the normals drawn on Gizmos.

alt text

The normals settings are correct. This is the same cube, with only the bottom face drawn.

alt text

Then the normals are really bugged, not simply inverted. In the image1, the bottom normals are settled like the posted code. The image2 is the bottom normals with the inverted normals.

I don't know why it's happening. Please help me!! thanks!

sem título.png (18.3 kB)
sem título2.png (26.7 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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by joonturbo · Nov 16, 2013 at 11:26 AM

It seems like the problem is your triangle is generated facing the wrong way. Normals are mainly used to calculate light, but the triangles are what decide whether something faces one way or the other. Try changing 20,21,22 and 20,22,23 to 20,22,21 and 20,23,22

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
avatar image
1

Answer by Berenger · Jan 28, 2013 at 05:23 PM

Sounds like the perfect time to bring out my freshly made wiki entry : http://wiki.unity3d.com/index.php/ProceduralPrimitives

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 tchesa · Jan 28, 2013 at 09:15 PM 0
Share

drawing the cube with 8 vertices the bottom render perfectly. But, i need to have the faces separated to mapping every face on diferent regions on the texture map.

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

11 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

Related Questions

How to set mesh normals per face? 2 Answers

Sphere made of cubes algorithm 4 Answers

issues with mobile build 0 Answers

Character always standing normal to mesh - without using physics system 2 Answers

My meshes arent loading properly. 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