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 $$anonymous$$ · Oct 23, 2012 at 08:06 AM · boneskinnedmeshrenderer

Reduce number of bones on runtime

Hi,

I am creating something like in the sims where you have a character and you can add different clothes to the character.

All the models I use are using the same bones and rig. I have put these models in different asset bundles. At runtime I read the asset bundles and combine these models in one SkinnedMeshRenderer and thus in one object. But every time I add another object the bone count goes up.

I know why this is happening, but I would like to reduce the number of bones again. I tried to find the duplicate bones and delete those and the bindpose on the same index as the bone deleted, but this still gives me the error "Number of bindposes doesn't match number of bones" even though they are both 45.

Here is the code that attaches the models:

 private void UpdateSkinnedMesh()
 {
     float startTime = Time.realtimeSinceStartup;

     // Create a list of for all data
     List combineInstances = new List();
     List materials = new List();
     List bones = new List();
     Transform[] transforms = baseModel.GetComponentsInChildren();

     //TEMP
     List elements = new List();
     elements.Add(body);
     if(_currentActiveProps.ContainsKey(ItemSubCategory.Skin))
         elements.Add(tutu);

     //Go over all active elements
     foreach (CharacterElement element in elements)
     {
         //Get the skinned mesh renderer
         SkinnedMeshRenderer smr = element.GetSkinnedMeshRenderer();

         //Add materials to the entire list
         materials.AddRange(smr.materials);

         //Add all submeshes to a combined mesh
         for (int sub = 0; sub < smr.sharedMesh.subMeshCount; sub++)
         {
             CombineInstance ci = new CombineInstance();
             ci.mesh = smr.sharedMesh;
             ci.subMeshIndex = sub;
             combineInstances.Add(ci);
         }

         //Bones are not saved in asset bundle, get the names and reference them again
         foreach (string bone in element.GetBoneNames())
         {
             foreach (Transform transform in transforms)
             {
                 if (transform.name != bone) continue;
                 bones.Add(transform);
                 break;
             }
         }

         //Destroy the temp object
         Destroy(smr.gameObject);
     }

     //Get skinned mesh renderer
     SkinnedMeshRenderer r = baseModel.GetComponentInChildren();

     //Create enew combined mesh
     r.sharedMesh = new Mesh();
     r.sharedMesh.CombineMeshes(combineInstances.ToArray(), false, false);

     //Add bones and materials
     r.bones = bones.ToArray();
     r.materials = materials.ToArray();

     Debug.Log("Bindposes: " + r.sharedMesh.bindposes.Length);

     Debug.Log("Generating character took: " + (Time.realtimeSinceStartup - startTime) * 1000 + " ms");
     Debug.Log("Bone count: " + r.bones.Length);
 }
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

8 People are following this question.

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

Related Questions

Swap mesh parts i.e. attach one skinned mesh to another via bone 1 Answer

Applying different boneWeights to SkinnedMeshRenderer creates unwanted vert stretching 2 Answers

How to deform a game object using a skinned mesh and bones? 1 Answer

Skinned Mesh Renderer Importing as Mesh Renderer 2 Answers

Moving bones without moving mesh 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