- Home /
Combining meshes in game without loosing boneWeights
So I have a simple cylinder that has a single bone in it.
I want to combine two of these end to end, but have the boneweights remain the same. So it ends up looking like this. I want the objects to be connected, but to still be controlled by the bones. This needs to happen in game.
Allowing the end result to look like this.
I have successful combined the mesh filters using this code.
[code=CSharp] using UnityEngine; using System.Collections;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class ExampleClass : MonoBehaviour {
void Start() {
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
}[/code]
This will combine the two objects, but remove the bone weights, so the bones no longer have control of the mesh.
I would really appreciate any suggestions someone might have. Either technically or more just in a general sense.
Should I worry about about combining the skinned mesh renderers? Or leave those separate and work on combining the mesh filters?
Any advice would be greatly appreciated.
Your answer
Follow this Question
Related Questions
skinned mesh renderer, combine meshes can't see the result, what am I doing wrong/ missing? 0 Answers
Combining Skinned Meshes no animation 0 Answers
CombineMeshes() Not Working Properly? 0 Answers
Create a mesh from a sub mesh 2 Answers
Assertion failed on expression: '(int)lastVertex < GetVertexCount()' 1 Answer