• 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 Andrew-Black · Jul 13, 2018 at 03:05 PM · meshmaterialmaterialsmeshescombinemeshes

Combine N different meshes with M different materials on each

The situation is as follows: input parameter(meshFilters) - are parts of the pattern of clothing (such as the sleeve, back, front), they all differ from each other and all have N different materials on each.

The task: to unite all the meshes into one, keeping all the materials on each piece of clothing.

At the moment I have such a code. Output mesh uses standard material. But we don't know in advance about the number of parts and the number of materials on each of them.

     public static void MeshesToFile(List<MeshFilter> meshFilters, string filename)
 {
     Mesh resultMesh = new Mesh();
     GameObject GO = new GameObject();
     MeshFilter MF = GO.AddComponent<MeshFilter>();
     MeshRenderer MR = GO.AddComponent<MeshRenderer>();
     CombineInstance[] combiners = new CombineInstance[meshFilters.Count];
 
     for (int i = 0; i < meshFilters.Count; i++)
     {
         combiners[i].subMeshIndex = 0;
         combiners[i].mesh = meshFilters[i].sharedMesh;
         combiners[i].transform = meshFilters[i].transform.localToWorldMatrix;
     }
     resultMesh.CombineMeshes(combiners);
     MF.sharedMesh = resultMesh;
     MR.sharedMaterial = new Material(Shader.Find("Diffuse"));
 
     MeshToFile(MF, filename);
 
     Object.Destroy(GO);
 }

How can I do that?

Comment

People who like this

0 Show 2
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 madks13 · Jul 13, 2018 at 03:23 PM 0
Share

Do you have multiple materials per submesh? Also, you set subMeshIndex to 0 for each subMesh. maybe use i? As far as i know, the only way to set different materials per mesh is to use SetTriangles. but it uses triangles and materials. If you don't know what the triangles are and which materials they use, you will need a custom shader.

avatar image hexagonius madks13 · Jul 13, 2018 at 07:00 PM 0
Share

red the docs and its half the truth. Using i as submesh index is definitely correct. each subject corresponds to a material though. this means providing an array of Materials as large as the amount of submeshes should work.

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

111 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

Related Questions

Materials on an imported mesh 1 Answer

How do I use the same material on 2 meshes without distortion? 2 Answers

The best way to have multiple models with only one material 2 Answers

Mobile Material Optimization 0 Answers

How to use multiple Unity materials on external meshes 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