FbxSDK breaks normals
Asked Answered
M

1

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?

Marron answered 15/10, 2015 at 21:11 Comment(4)
Is the thing on the picture really what I think it is, or do I need to visit a shrink?Nasya
That's exactly what you think!Marron
That's good. Sorry, can't help with the actual question, though.Nasya
Was this issue ever resolved? I've a very similar problem #72876912Abran
E
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);

Exophthalmos answered 21/10, 2015 at 20:48 Comment(2)
What I want to say is: You are dropping the first 8 bits of the normal.data which might be containing useful w information.Exophthalmos
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.Marron

© 2022 - 2024 — McMap. All rights reserved.