- Home /
skinned mesh renderer, combine meshes can't see the result, what am I doing wrong/ missing?
I put all the skinned mesh renderers I want to combine in a variable called combine. smrenderer is the skinned mesh renderer i want the combined mesh in. "i" loops through the smrenderers in combine. "j" and "k" are used to copy the materials. I have tried with and without the localtoworld line.
The bones are set to that of the main mesh object and the root transform is set to the root of these bones. All of this is working as it should according to the data I can get with watch in monodevelop, except for recalculatebounds, which gives me a bounding box around something in 2D that I can't see. I get a new skinned mesh renderer with 35 materials(don't ask why I have so many it's just a test) and seemingly the right amount of vertices, correct number of bones with correct names. the meshes were working correctly with animation, together, before they were merged. when they are merged they all disappear and I can't find them. nothing appears to be wrong and since I can't see the meshes at all I don't know what the problem is.
CombineInstance[] combine = new CombineInstance[smrenderersToCombine.Length];
int i = 0;
while (i < smrenderersToCombine.Length) {
combine[i].mesh = smrenderersToCombine[i].sharedMesh;
//combine[i].transform = smrenderersToCombine[i].transform.localToWorldMatrix;
Material[] newmats = new Material[smrenderersToCombine[i].materials.Length+smrenderer.materials.Length];
int j=0;
for(;j < smrenderer.materials.Length;j++){
newmats[j] = smrenderer.materials[i];
}
for(int k = 0 ; k < smrenderersToCombine[i].materials.Length ; k++){
newmats[(j+k)] = smrenderersToCombine[i].materials[k];
}
smrenderer.materials = newmats;
smrenderersToCombine[i].gameObject.SetActive(false);
i++;
}
//set own data, just once
smrenderer.rootBone = referenceBrotherPosition.transform;
smrenderer.bones = smrendererRef.bones;
//Set own mesh, make function of this
smrenderer.sharedMesh = new Mesh();
smrenderer.sharedMesh.CombineMeshes(combine);
smrenderer.sharedMesh.name = "ABAGGARD";
smrenderer.sharedMesh.RecalculateBounds();
smrenderer.sharedMesh.RecalculateNormals ();
VertNumber = smrenderer.sharedMesh.vertexCount;
It seems the actual vertex points positions are the only thing that doesn't carry over to the product of the function. all the 6000 vertices of the new mesh have the xyz- values (0,0,0). these values were correct in the objects in the list I sent to the combine function.