9

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.

Example: enter image description here

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?

VenoMKO
  • 3,294
  • 32
  • 38

1 Answers1

0

Skinning is a process that requires four components: x, y, z and weight. For normals, the fourth component (weight) should be set to zero. Did you try FbxVector4(x,-y,z,0) in your code? Also try
w = ((((normal.data) >> 24) & 0xFF) / 127.5f - 1.0f);
and then using FbxVector4(x,-y,z,w);

aanand_ub
  • 71
  • 3
  • What I want to say is: You are dropping the first 8 bits of the normal.data which might be containing useful w information. – aanand_ub Oct 21 '15 at 20:54
  • Thanks for your reply. The last byte is unused and stores 0xFF. I tried to pass 1.0f, 0.0f and -1.0f as the 4th component but nothing changed. – VenoMKO Oct 22 '15 at 02:46