void loadBinormal(FbxMesh* fbxMesh, int vertexIndex, int controlPointIndex, Vertex* vertex) { if (fbxMesh->GetElementBinormalCount() > 0) { // Get only the first binormal. FbxGeometryElementBinormal* binormal = fbxMesh->GetElementBinormal(0); FbxGeometryElement::EMappingMode mappingMode = binormal->GetMappingMode(); if (mappingMode == FbxGeometryElement::eByControlPoint) { switch (binormal->GetReferenceMode()) { case FbxGeometryElement::eDirect: { FbxVector4 vec4 = binormal->GetDirectArray().GetAt(controlPointIndex); vertex->hasBinormal = true; vertex->binormal.x = (float)vec4[0]; vertex->binormal.y = (float)vec4[1]; vertex->binormal.z = (float)vec4[2]; } break; case FbxGeometryElement::eIndexToDirect: { int id = binormal->GetIndexArray().GetAt(controlPointIndex); FbxVector4 vec4 = binormal->GetDirectArray().GetAt(id); vertex->hasBinormal = true; vertex->binormal.x = (float)vec4[0]; vertex->binormal.y = (float)vec4[1]; vertex->binormal.z = (float)vec4[2]; } break; default: break; } } else if (mappingMode == FbxGeometryElement::eByPolygonVertex) { switch (binormal->GetReferenceMode()) { case FbxGeometryElement::eDirect: { FbxVector4 vec4 = binormal->GetDirectArray().GetAt(vertexIndex); vertex->hasBinormal = true; vertex->binormal.x = (float)vec4[0]; vertex->binormal.y = (float)vec4[1]; vertex->binormal.z = (float)vec4[2]; } break; case FbxGeometryElement::eIndexToDirect: { int id = binormal->GetIndexArray().GetAt(vertexIndex); FbxVector4 vec4 = binormal->GetDirectArray().GetAt(id); vertex->hasBinormal = true; vertex->binormal.x = (float)vec4[0]; vertex->binormal.y = (float)vec4[1]; vertex->binormal.z = (float)vec4[2]; } break; default: break; } } } }
void FBXImporter::ReadBinormals(FBXMeshData* fbxMeshData, int controlPointIndex, int tangentIndex) { FbxMesh* mesh = fbxMeshData->mMesh; if (mesh->GetElementTangentCount() < 1) { return; } FbxGeometryElementBinormal* binormalElement = mesh->GetElementBinormal(0); switch (binormalElement->GetMappingMode()) { case FbxGeometryElement::eByControlPoint: { switch (binormalElement->GetReferenceMode()) { case FbxGeometryElement::eDirect: { FbxVector4 fbxBinormal = binormalElement->GetDirectArray().GetAt(controlPointIndex); XMFLOAT3 binormal; binormal.x = static_cast<float>(fbxBinormal[0]); binormal.y = static_cast<float>(fbxBinormal[1]); binormal.z = static_cast<float>(fbxBinormal[2]); fbxMeshData->mBinormals.push_back(binormal); } break; case FbxGeometryElement::eIndexToDirect: { int id = binormalElement->GetIndexArray().GetAt(controlPointIndex); FbxVector4 fbxBinormal = binormalElement->GetDirectArray().GetAt(id); XMFLOAT3 binormal; binormal.x = static_cast<float>(fbxBinormal[0]); binormal.y = static_cast<float>(fbxBinormal[1]); binormal.z = static_cast<float>(fbxBinormal[2]); fbxMeshData->mBinormals.push_back(binormal); } break; default: break; } } case FbxGeometryElement::eByPolygonVertex: { switch (binormalElement->GetReferenceMode()) { case FbxGeometryElement::eDirect: { FbxVector4 fbxBinormal = binormalElement->GetDirectArray().GetAt(tangentIndex); XMFLOAT3 binormal; binormal.x = static_cast<float>(fbxBinormal[0]); binormal.y = static_cast<float>(fbxBinormal[1]); binormal.z = static_cast<float>(fbxBinormal[2]); fbxMeshData->mBinormals.push_back(binormal); } break; case FbxGeometryElement::eIndexToDirect: { int id = binormalElement->GetIndexArray().GetAt(tangentIndex); FbxVector4 fbxBinormal = binormalElement->GetDirectArray().GetAt(id); XMFLOAT3 binormal; binormal.x = static_cast<float>(fbxBinormal[0]); binormal.y = static_cast<float>(fbxBinormal[1]); binormal.z = static_cast<float>(fbxBinormal[2]); fbxMeshData->mBinormals.push_back(binormal); } break; default: break; } } break; default: break; } }
//=============================================================================================================================== bool FBXLoader::LoadVertexBinormal(FbxMesh* mesh, int inCtrlPointIndex, int inVertexCounter, int binormalElement, XMFLOAT3& outBinormal) { if (mesh->GetElementBinormalCount() < 1) { throw std::exception("Invalid Binormal Number"); } int directIndex = -1; FbxGeometryElementBinormal* vertexBinormal = mesh->GetElementBinormal(binormalElement); switch (vertexBinormal->GetMappingMode()) { case FbxGeometryElement::eByControlPoint: { switch (vertexBinormal->GetReferenceMode()) { case FbxGeometryElement::eDirect: { directIndex = inCtrlPointIndex; //outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inCtrlPointIndex).mData[0]); //outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inCtrlPointIndex).mData[1]); //outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inCtrlPointIndex).mData[2]); } break; case FbxGeometryElement::eIndexToDirect: { directIndex = vertexBinormal->GetIndexArray().GetAt(inCtrlPointIndex); //int index = vertexBinormal->GetIndexArray().GetAt(inCtrlPointIndex); //outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[0]); //outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[1]); //outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[2]); } break; default: throw std::exception("Invalid Reference"); } } break; case FbxGeometryElement::eByPolygonVertex: { switch (vertexBinormal->GetReferenceMode()) { case FbxGeometryElement::eDirect: { directIndex = inVertexCounter; //outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inVertexCounter).mData[0]); //outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inVertexCounter).mData[1]); //outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(inVertexCounter).mData[2]); } break; case FbxGeometryElement::eIndexToDirect: { directIndex = vertexBinormal->GetIndexArray().GetAt(inVertexCounter); //int index = vertexBinormal->GetIndexArray().GetAt(inVertexCounter); //outBinormal.x = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[0]); //outBinormal.y = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[1]); //outBinormal.z = static_cast<float>(vertexBinormal->GetDirectArray().GetAt(index).mData[2]); } break; default: throw std::exception("Invalid Reference"); } } break; } if (directIndex != -1) { FbxVector4 binorm = vertexBinormal->GetDirectArray().GetAt(directIndex); outBinormal = XMFLOAT3((float)binorm.mData[0], (float)binorm.mData[1], (float)binorm.mData[2]); return true; } return false; }