I am trying to export a skinned mesh. For some reasones FbxSDK breaks normals on edges of segments if I add a skin cluster to a mesh. Without a skin everything looks totally fine.
Code:
FbxLayerElementNormal *layerElementNormal = FbxLayerElementNormal::Create(mesh, "");
layerElementNormal->SetMappingMode(FbxLayerElement::eByControlPoint);
layerElementNormal->SetReferenceMode(FbxLayerElement::eDirect);
for (int vertIndex = 0; vertIndex < vertexCount; ++vertIndex)
{
PackedNormal normal = vertices[vertIndex].normal;
double x,y,z;
x = (( (normal.data) & 0xFF) / 127.5f - 1.0f);
y = ((((normal.data) >> 8 ) & 0xFF) / 127.5f - 1.0f);
z = ((((normal.data) >> 16) & 0xFF) / 127.5f - 1.0f);
layerElementNormal->GetDirectArray().Add(FbxVector4(x,-y,z));
}
layer->SetNormals(layerElementNormal);
I tryied different mapping mods (eg. eByPolygonVertex
) and reference mods but so far no help. Seems like normals are completely ignored if a mesh has skin clusters. I commented out code above and skinned model looked like one on the left image.
I also tryied different 3d software(Maya 2015, Maya 2013 and 3ds Max 2013) to review exported model but all of them give me the same results.
P.S. this problem affects any skinned mesh.
EDIT Seems this problem is a bug in FBX pipeline: Autodesk Forum. To bypass the problem i need to "Transfer Attributes". Can anyone help with this?