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 PhilippUmschaden · Feb 16, 2018 at 10:08 AM · texturemeshvertices

Problem with generating a tube mesh

I am trying to create a tube mesh. Right now I have a set of circles. Every circle consists of 8 points, which are my vertices for the mesh. My circlePointsList holds all the circle points. I go through the circlePointsList to create my mesh triangles like you can see in the following piece of code:

 for(int k = 0; k <= circlePointsList.Count; k++){
                 if(k+9 < circlePointsList.Count){

                     triangleList.Add(k+1);
                     triangleList.Add(k+8);
                     triangleList.Add(k);
                     triangleList.Add(k+1);
                     triangleList.Add(k+8);
                     triangleList.Add(k+9);

                 }
             }

The result looks like the following pictures:

alt text

alt text

As you can see all the triangles are being created. But I do not know why they are not displayed at the same time. If I look inside the object (first picture), all the upper triangles are displayed, and if I look at the object from the outside, only the lower triangles are displayed. Has anyone an idea what could be the problem here?

bildschirmfoto-2018-02-16-um-105737.png (120.7 kB)
bildschirmfoto-2018-02-16-um-105750.png (97.2 kB)
Comment
Add comment · Show 1
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 · Feb 16, 2018 at 11:35 AM 1
Share

Check the triangle array of your mesh. I assume that the invisible triangles are facing the other side and by default their backsides are not rendered. If you have three vertices, you can make a triangle from them in two ways: facing "your" side and facing "away" from you. The former would be v1,v2,v3 (clockwise) and the latter v3,v2,v1 (counter-clockwise).

So, in your case, I would try a different direction for the triangles:

                      triangleList.Add(k+1);
                      triangleList.Add(k+8);
                      triangleList.Add(k);
                      triangleList.Add(k+9);
                      triangleList.Add(k+8);
                      triangleList.Add(k+1);

or

                      triangleList.Add(k);
                      triangleList.Add(k+8);
                      triangleList.Add(k + 1);
                      triangleList.Add(k+1);
                      triangleList.Add(k+8);
                      triangleList.Add(k+9);

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by yummy81 · Feb 16, 2018 at 11:53 AM

What determines which side of a triangle is visible (in your case pink), is the orientation of its vertex indices. The way it works is that if they are arranged in a clockwise direction then the triangle is forward-facing and visible. By contrast, a counter-clockwise direction means that the triangle is not rendered and not visible. So, it seems that part of your triangles have clockwise-arranged vertex indices and the other one have counterclockwise-arranged vertex indices. So, create new gameobject, reset its position, add meshfilter, put the script on it, read my comments in the script and play with it by uncommenting and commenting. Here's the code:

     private void OnValidate()
     {
         MeshFilter mf = gameObject.GetComponent<MeshFilter>();
         
         Vector3[] vertices = new Vector3[]
         {
             new Vector3(-1f, 1f, 0), // index 0 in triangles array
             new Vector3(1f, 1f, 0), // index 1 in triangles array
             new Vector3(1f, -1f, 0), // index 2 in triangles array
             new Vector3(-1f, -1f, 0) // index 3 in triangles array
         };
         
         int[] triangles = new int[]
         {
 // Let's assume that you are forward-facing. In other words, looking at the Z axis direction.
 // Those indices are arranged clockwise so you will see the triangles
             //0, 1, 2,
             //2, 3, 0
 // You will also see these triangles
             //1, 2, 0,
             //3, 0, 2
 // And these too. There can be many combinations as you can see:        
             //2, 0, 1,
             //0, 2, 3
 // But you won't see them when you arrange them counterclockwise (they are seen from behind), like that:
             //0, 2, 1,
             //0, 3, 2
 // Or like that. There can be many combinations:
             //1, 0, 2,
             //0, 3, 2
             
 // Your problem, however, is that one triangle has its indices clockwise arranged, and the other one counterclockwise. They just look like that:
             0, 1, 2,
             2, 0, 3
 // Of course, in your case, there can be many combinations. It can be also like that:
             //1, 2, 0,
             //0, 3, 2
         };
         
         Mesh mesh = new Mesh();
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mf.mesh = mesh;
     }
 
 
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 PhilippUmschaden · Feb 16, 2018 at 12:03 PM 0
Share

Thank you so much.

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

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

Related Questions

Split a mesh while using same UVs and texture position. 0 Answers

Do I need to split my mesh up to properly UV texture it? 1 Answer

How to get the texture co-ordinate(x,y) from a 3D point on the mesh renderer? 1 Answer

How do i add a texture material to my imported object? 1 Answer

How do I know if a clicked vertex is contained in a blendshape? 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