Hi!
I am trying to create a script which replace a skinned mesh with its baked skinned mesh.
I need to make this work to modify a humanoid’s bone local orientation without affecting the model’s vertices.
The small white sphere dots indicate baked skinned mesh’s vertices and these are the mesh I would like to apply to my character.
Here is the script I wrote, which made the snapshot mesh of the image above.
void MakeNewBidnPose(Transform bone, Quaternion rot)
{
for (int i = 0; i < meshInfo.Count; i++)
{
//Check bone index to see if the skm has target bone
int targetIndex = -1;
for (int boneNum = 0; boneNum < meshInfo[i].bones.Length; boneNum++)
{
if (meshInfo[i].bones[boneNum].name == bone.name)
{
targetIndex = boneNum;
continue;
}
}
//If the skm does not include target bone then skip to next skm
if (targetIndex == -1)
continue;
//Rotate bone opposit direction
bone.rotation = bone.rotation * Quaternion.Inverse(rot);
//Get snapshot of mesh with rotation offset
Mesh newBindMesh = new Mesh();
meshInfo[i].skm.BakeMesh(newBindMesh);
//Rotate back the bone to its original orientation
bone.rotation = bone.rotation * rot;
//Replace original mesh with the snapshot
meshInfo[i].mesh = newBindMesh;
//Display snapshot's vertices for debug purpose
DisplayVertices(meshInfo[i].mesh);
}
}
The dots are drawn by a small method of “DisplayVertices()” at the bottom of the script.
I want the mesh fits to the white dots but indeed it doesn’t and I don’t understand why.
It seems like my script fails to update the original mesh with the snapshot but at the same time the dots are drawn correctly based on the update mesh vertices.
Someone please advise me how I can work this right? I should be overlooking something really simple.
