• 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
Question by RER1200 · Apr 17, 2020 at 11:09 AM · meshrenderingvertices3d modeltriangles

Realtime mesh triangles do not appear depending on camera angle

I am creating a mesh that is a cube with two vertices of the same edge removed. This makes it a prism. The problem is that after clearing the mesh then setting the new vertices and triangles, only half of the triangles appear at the same time. The other half appear when changing the scene camera's angle. Here are some screenshots to show the problem :

alt text

alt text

As you can see the triangle to the right does not appear in the first screenshot but appears through a missing triangle in the second screenshot. Here is my code :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class createPrism : MonoBehaviour {
 
     public Mesh mesh;
 
     void Start () {
         mesh = GetComponent<MeshFilter>().mesh;
         Vector3[] vertices = {
             new Vector3(-0.5f,-0.5f,-0.5f),
             new Vector3(0.5f,-0.5f,-0.5f),
             new Vector3(-0.5f,0.5f,-0.5f),
             new Vector3(0.5f,0.5f,-0.5f),
             new Vector3(-0.5f,-0.5f,0.5f),
             new Vector3(0.5f,-0.5f,0.5f)
         };
 
         int[] triangles = {
             0,1,2,
             1,2,3,
             0,1,4,
             1,4,5,
             2,3,4,
             3,4,5,
             1,5,3,
             0,2,4
         };

         mesh.Clear();
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.RecalculateNormals();
         mesh.RecalculateBounds();
     }
 }

This is probably an easy fix but I couldn't find anything like this online.

screenshot-2020-04-17-at-123432.png (52.9 kB)
screenshot-2020-04-17-at-123442.png (55.5 kB)
Comment

People who like this

0 Show 0
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
Best Answer

Answer by Bunny83 · Apr 17, 2020 at 11:20 AM

Triangles have a direction they face. They have a front side (which is visible) and a back side (which is not visible). The side depends on the winding order of your vertices. In Unity by default a clockwise winding denotes the front face. If the winding order is counter clockwise it will be a backface and (due to backface culling) not visible.


I did not go through your triangle list to figure out which one you have inverted. However note that in order to change the winding order you just have to swap any two vertices of a triangle. I would start by first adding comments to your vertices to keep track which one is which. I highly recommend you create a drawing of your mesh on paper and label your vertices. Then it's much easier to figure out the correct winding order. I also recommend to add comments to each triangle tripple to know which side / face it belongs to. Your prism has 3 quads (6 tirangles) and 2 triangle faces.

Comment
Purumo

People who like this

1 Show 6 · 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 RER1200 · Apr 17, 2020 at 11:23 AM 0
Share

Thank you for the very fast response. I already have a drawing so this isn't going to take long. I will also make sure to add comments so I don't get lost. Thank you again for the fast answer !

avatar image Bunny83 RER1200 · Apr 17, 2020 at 11:32 AM 0
Share

I just had a bit time and sorted it out in my head ^^

 void Start ()
 {
     mesh = GetComponent<MeshFilter>().mesh;
     Vector3[] vertices = {
         new Vector3(-0.5f,-0.5f,-0.5f),
         new Vector3(0.5f,-0.5f,-0.5f),
         new Vector3(-0.5f,0.5f,-0.5f),
         new Vector3(0.5f,0.5f,-0.5f),
         new Vector3(-0.5f,-0.5f,0.5f),
         new Vector3(0.5f,-0.5f,0.5f)
     };
      
     //   2------3
     //   |\     |\
     //   | 4----|-5
     //   |/     |/
     //   0------1
 
     int[] triangles = {
         1,0,2, // front side
         1,2,3, // front side
         
         0,1,4, // bottom side
         1,5,4, // bottom side
         
         2,4,3, // back side
         3,4,5, // back side
         
         1,3,5, // right side
         0,4,2  // left side
     };
     // [ ... ]
avatar image RER1200 Bunny83 · Apr 17, 2020 at 12:07 PM 0
Share

This works perfectly. Thank you again !

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

159 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 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

Why does the default Unity sphere have duplicate vertices? 1 Answer

Does mesh.triangles also return a copy of the triangle array? 1 Answer

Rebuilding mesh.triangles after removing vertices 1 Answer

Generated Mesh Triangles not Being Made/Visible? 1 Answer

Any articles about mesh's vertices,uv,triangles ? 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