Unity-Technologies/Animation-Instancing

Attachment normals could be wrong on some cases

albertomelladoc opened this issue · 0 comments

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.