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
3
Question by Marnix · Apr 14, 2012 at 03:29 PM · meshnormalsmeshcombine

Mesh.CombineMeshes flips normals

I am trying to use the following example script to combine small parts of a mesh into one, so I am able to make a dynamic terrain: http://unity3d.com/support/documentation/ScriptReference/Mesh.CombineMeshes.html.

The problem is that it flips the normals of some of the meshes. How come and how to solve this?

The following image shows that the normals of the edges of my model are flipped, while some of the edges are still ok. These blocks all exist out of a center plane, corners and edges.

flipped normals

What it should be:

What it should look like

 private static void CombineMesh(GameObject iceBerg)
 {
     MeshFilter[] meshes = iceBerg.GetComponentsInChildren<MeshFilter>();

     CombineInstance[] combine = new CombineInstance[meshes.Length];
     for (int i = 0; i < meshes.Length; i++)
     {
         combine[i].mesh = meshes[i].sharedMesh;
         combine[i].transform = meshes[i].transform.localToWorldMatrix;
         meshes[i].gameObject.active = false;
     }

     MeshFilter meshFilter = iceBerg.AddComponent<MeshFilter>();
     meshFilter.mesh = new Mesh();
     meshFilter.mesh.CombineMeshes(combine);

     MeshRenderer renderer = iceBerg.AddComponent<MeshRenderer>();
     renderer.material = (Material)Resources.Load("Materials/GridIce");

     MeshCollider col = iceBerg.AddComponent<MeshCollider>();
     col.smoothSphereCollisions = true;
 }


flipped normals.png (202.7 kB)
no flipped normals.png (157.3 kB)
Comment
Add comment · Show 10
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 Bunny83 · Apr 14, 2012 at 04:36 PM 0
Share

Hmm it's hard to tell what's going wrong here. Can you add a screenshot of the same view before you combine the meshes so you have a reference how it should look like?

By "flipped normals" do you refer to front / back sides are flipped? Or do you talk about the vertex normals (used for lighting)?

avatar image Marnix · Apr 14, 2012 at 04:47 PM 0
Share

I added another picture. As you can see, the front and back is flipped. Which means that the normals are flipped. The top and sideskirts are not attached to one another in the original model. So both top and side have their own vertex normals. I used an edge split modifier in blender to achieve that.

avatar image Bunny83 · Apr 14, 2012 at 11:37 PM 1
Share

There is nothing flipped. It looks like there are some triangles missing. What's the vertex and triangle count of the meshes? Unity use just a 16 bit index buffer, so there can be only 65536 vertices in a single mesh.

Also what shader do you use?

avatar image Marnix · Apr 15, 2012 at 09:23 PM 0
Share

$$anonymous$$aybe I should update my images. I hoped that it would be clear from these images. But I am certain that the normals are flipped. Looking the this object from the other side shows exactly the missing faces. I will try to make a better image later this week.

avatar image karl_ · Apr 15, 2012 at 10:08 PM 0
Share

I've had issues in the past with n-gon geometry not getting triangulated properly, and subsequently not rendering. Is your mesh triangulated pre-unity import, or are you allowing unity to triangulate it?

Show more comments

2 Replies

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

Answer by Marnix · Apr 18, 2012 at 07:21 PM

I have found the problem! It is a bug in Unity and I will probably contact them about it.

The objects that are flipped in my scene are flipped because of a negative scale that I use to reuse the model multiple times. I avoided this by making a mirrored version of the object in Blender.

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 Bunny83 · Apr 18, 2012 at 10:22 PM 0
Share

Uhmm in which way is this a bug? If you use negative scaling values the faces have to flip. A mesh always have only one front side, if you use a negative scale all points are projected to the opposite side but the renderorder will stay the same so the faces are flipped.

avatar image
0

Answer by kaz2057 · Jan 23, 2013 at 11:51 AM

Any news about any fix? Anybody can help me to insert a check inverted scale on game object and its parent to have correct normals on triangle strip?

Please contact me becausa I have thousand combined geometry and it not possible mirror them!

Thanks

Comment
Add comment · Show 2 · 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 Bunny83 · Jan 23, 2013 at 12:12 PM 0
Share

Just avoid scaling inside Unity in general. negative scaling (especially on only one axis) will cause a lot more problems than that. For example rotating the object might flip the faces on certain angles.

I had to instruct our artists several times to reset all transformations before they export the model.

avatar image kaz2057 · Jan 23, 2013 at 02:43 PM 0
Share

The models are exported in 0,0,0 in world but the problem is I create big shapes welding thounsands of little modulared objects. To save memory I use 4 singular fbx mesh duplicated and scaled on -1 to create custom bigger shape. Any solution?

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem drawing a mesh with Graphics.DrawMeshNow 1 Answer

Get face normal and get its local Euler Angles? 3 Answers

Seing through triangles in runtime edited mesh 0 Answers

Pointcast? - Raycast Point X from same Point X 0 Answers

Unity Mesh Rendering Issue 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