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 qwee · Jun 21, 2013 at 08:57 AM · meshmaterialsfacesassignmentsubdivision

Split mesh faces C#

How can i split mesh faces without losing faces materials assignments. The code i used is here (the other variables you can't see are declared in the main code), it works but it loses materials assignments and gets the final mesh with only a material:

 void defragMesh()
     {
         myMesh = new Mesh();
         
         myMesh.vertices = startMesh.vertices;
         myMesh.triangles = startMesh.triangles;
         myMesh.uv = startMesh.uv;
         myMesh.normals = startMesh.normals;
         
         newVertices = new Vector3[myMesh.triangles.Length];
         int[] newTris = new int[myMesh.triangles.Length];
         Vector2[] newUV = new Vector2[myMesh.triangles.Length];
         Vector3[] newNormals = new Vector3[myMesh.triangles.Length];
         
         for(int i = 0; i < myMesh.triangles.Length; i++)
         {
             newVertices[i] = myMesh.vertices[myMesh.triangles[i]];
             newUV[i] = myMesh.uv[myMesh.triangles[i]];
             newNormals[i] = myMesh.normals[myMesh.triangles[i]];
             newTris[i] = i;
         }
         
         myMesh.vertices = newVertices;
         myMesh.triangles = newTris;
         myMesh.uv = newUV;
         myMesh.normals = newNormals;
         
         normals = new Vector3[myMesh.triangles.Length / 3];
         int index = 0;
         for(int i = 0; i < normals.Length; i++)
         {
             Vector3 v = newVertices[index++];
             normals[i] = Vector3.Cross(newVertices[index++] - v, newVertices[index++] - v).normalized;
         }
         
     }
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 ShujoSLX · Apr 06, 2019 at 12:11 AM 0
Share

Does this divide the triangles of the mesh in two? Did you manage to achieve the desired effect without loosing the material assignments?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Jun 21, 2013 at 09:31 AM

If you use multiple materials you will need to use SetTriangles and GetTriangles to set the triangles for each of the submeshes. Using triangles directly removes the sub meshes.

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 qwee · Jun 21, 2013 at 10:26 AM 0
Share

And there is a script that allow me to get the vertices in a sub-mesh?

avatar image whydoidoit · Jun 21, 2013 at 10:27 AM 0
Share

You get the vertex numbers from the triangles.

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

16 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

Related Questions

Materials on an imported mesh 1 Answer

How do I properly apply a transparent texture to a mesh? 2 Answers

Is it possible to use Multiple Materials on a single mesh? 0 Answers

Change uvs on texture packing 0 Answers

How to subdivide a mesh into 4 quadrants? 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