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 stainless7221 · Aug 23, 2013 at 12:11 PM · meshmeshrenderermeshfiltergenerated

Generated Mesh is partially rendered, but shown correctly in scene view

I generate a mesh by code. In the Scene and Game View, it is shown correctly, but when i look at the generated mesh in the inspector preview, only half the triangles are generated. The other ones are only visible on the other side, when i flip the preview around.

To explain, here are some screenshots:

alt text Scene View

alt text Game View

alt text Inspector Preview

alt text Inspector Preview flipped over

I also added a collision to my mesh. If i place a cube with gravity enabled over the mesh, it only collides with the triangles shown in picture #3.. This is also my main problem.

I think i have something with the triangles or the normals wrong, so here is my code.

     MeshFilter mf = GetComponent<MeshFilter>();
     Mesh mesh = new Mesh();
     mf.mesh = mesh;
     
     //Vertices
     Vector3[] verticies = new Vector3[]
     {
         new Vector3(0,0,0), 
         new Vector3(2,0,0), 
         new Vector3(0,0,3), 
         new Vector3(2,0,3),
         
         new Vector3(0,0,4), 
         new Vector3(2,0,4), 
         new Vector3(0,0,6), 
         new Vector3(2,0,6),
         
         new Vector3(0,0,7), 
         new Vector3(6,0,7), 
         new Vector3(0,0,9), 
         new Vector3(6,0,9),
         
         new Vector3(4,0,0), 
         new Vector3(6,0,0), 
         new Vector3(4,0,2), 
         new Vector3(6,0,2),
         
         new Vector3(5,0,2), 
         new Vector3(6,0,2), 
         new Vector3(5,0,4), 
         new Vector3(6,0,4),
         
         new Vector3(4,0,4), 
         new Vector3(6,0,4), 
         new Vector3(4,0,6), 
         new Vector3(6,0,6)
     };
     
     //Triangles
     int[] tri = new int[]
     {
         0,1,2,
         1,2,3,
         
         4,5,6,
         5,6,7,
         
         8,9,10,
         9,10,11,
         
         12,13,14,
         13,14,15,
         
         16,17,18,
         17,18,19,
         
         20,21,22,
         21,22,23
     };
     
     //Normals, to see the Object
     Vector3[] normals = new Vector3[]
     {
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward,
         -Vector3.forward
     };
     
     //UVs what is displayed
     Vector2[] uv = new Vector2[]
     {
         new Vector2(0,0),
         new Vector2(1,0),
         new Vector2(0,1),
         new Vector2(1,1),
         
         new Vector2(0,0),
         new Vector2(1,0),
         new Vector2(0,1),
         new Vector2(1,1),
         
         new Vector2(0,0),
         new Vector2(1,0),
         new Vector2(0,1),
         new Vector2(1,1),
         
         new Vector2(0,0),
         new Vector2(1,0),
         new Vector2(0,1),
         new Vector2(1,1),
         
         new Vector2(0,0),
         new Vector2(1,0),
         new Vector2(0,1),
         new Vector2(1,1),
         
         new Vector2(0,0),
         new Vector2(1,0),
         new Vector2(0,1),
         new Vector2(1,1)
     };
     
     //Assign Arrays to Object
     mesh.vertices    = verticies;
     mesh.triangles     = tri;
     mesh.normals    = normals;
     mesh.uv         = uv;
     
     MeshCollider mc = gameObject.AddComponent(typeof(MeshCollider)) as MeshCollider;
     mc.sharedMesh = mesh; // Give it your mesh 


I hope some of you can help me, i'd appretiate it!

Comment
Add comment · Show 7
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 meat5000 ♦ · Aug 23, 2013 at 12:12 PM 0
Share

It's just a problem with Normals in my opinion. Flip the normals of the triangles you cant see.

avatar image stainless7221 · Aug 23, 2013 at 12:25 PM 0
Share

But aren't the Normals matching the vertices ins$$anonymous$$d the triangles? Flipping the normals didn't work, because each normal is dedicated to one point and not one triangle... or am i missing out on something?

avatar image meat5000 ♦ · Aug 23, 2013 at 12:26 PM 0
Share

Normals are for faces, no? Calculated through 3 or more vertices.

avatar image stainless7221 · Aug 23, 2013 at 12:31 PM 0
Share

But why do i have to enter 24 vertices, 12 triangles and 24 normals? How would i flip the normals in my case?

avatar image meat5000 ♦ · Aug 23, 2013 at 12:38 PM 0
Share

http://answers.unity3d.com/questions/187637/procedural-meshs-normals-are-reversed.html

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Paulius-Liekis · Aug 24, 2013 at 07:24 PM

Reverse order (or simply flip two indices) in very triangle that is reversed. It's called CW (clock-wise) and CCW (counter-clock-wise) culling.

Reversing normals does not reverse triangles.

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

17 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

Related Questions

Bounds of dynamic mesh not updating 1 Answer

Unity5 Procedural meshing slower than in Unity4? 1 Answer

Procedurally generated mesh not Rendering all triangles 1 Answer

Unity won't show my programatically created Mesh(A Simple Triangle) 2 Answers

Sharing a generated mesh between multiple game objects 2 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