Note that there are some explanatory texts on larger screens.

plurals
  1. POUnity3D: Reduce number of bones at runtime
    primarykey
    data
    text
    <p>I am creating something like in the sims where you have a character and you can add different clothes to the character.</p> <p>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.</p> <p>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 &#34;Number of bindposes doesn&#39;t match number of bones&#34; even though they are both 45.</p> <p>Here is the code that attaches the models:</p> <pre><code>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 &lt; 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); } </code></pre> <p>I already have asked the question on Unity Answers, but because it takes a few hours before a moderator approves the question, I wanted to try here as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload