Search Unity

Finding the "eye" mesh connected to the eye bones?

Discussion in 'Animation' started by Airmouse, Jul 31, 2019.

  1. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    107
    I am trying to loop through all meshes from a character to identify (with certainty) that a mesh is the eye's mesh.

    I was hoping that the bones parameter would have shown only the bones which had weight paint for that particular mesh, however it seems that actually they contain all bones in the human definition, meaning all SkinnedMeshRenderer.bones look identical regardless of which mesh I compare.

    I then investigated the SkinnedMeshRenderer.sharedMesh.boneWeight parameter which looks more promising. I see the length of the boneWeight array varies for each mesh object, so I believe the mesh for eyes will have weights related to the eye bones and maybe a few other bones (but shouldn't include any hand bones for instance).

    Seems like the best approach is to compare each mesh's boneWeights to see if any contains the index for any of the eye bones. So I believe I need to look at the boneIndex of each mesh's boneWeight to see if the zeroth bone reference an eye bone?

    How would I get my characters eyeL and eyeR bone indexes to compare to the boneIndex?

    Would checking the indexes of the boneWeight for eye bones even be enough to guarantee that the mesh is the actual "eye" mesh?

    I am keen for any alternative approach and would love suggestions!

    Thanks