Unity-Technologies / Animation-Instancing

This technique is designed to instance Characters(SkinnedMeshRender).
Other
1.65k stars 301 forks source link

Attachment normals could be wrong on some cases #122

Open albertomelladoc opened 9 months ago

albertomelladoc commented 9 months ago

Hi!

I have checked this project and I was having a really weird issue where the normals of my attachments were wrong. I think this was due to my models skeleton having a really weird base rotation. Finally I found what fixes it in my case. I modified the method of BindAttachment on AnimationInstancingMgr with this:

Vector3[] vertices = attachmentCache.mesh.vertices;
Vector3[] normals = attachmentCache.mesh.normals;

for (int k = 0; k != attachmentCache.mesh.vertexCount; ++k)
{
    vertices[k] = q * vertices[k];
    vertices[k] = vertices[k] + offset;

    normals[k] = q * normals[k];
}

attachmentCache.mesh.vertices = vertices;
attachmentCache.mesh.normals = normals;

I believe that when the vertices of the mesh are modified with the parent rotation on the attachment the normals should also be modified. At least it fixed the issue for me.