Ich habe die Netze korrekt mit all ihren Eckpunkten, Indizes, UVs und Normalen geladen. Ich versuche gerade, die Animationen richtig zum Laufen zu bringen. Ich habe mir die FBX SDK-Dokumentation mit wenig Hilfe angesehen. Wenn mir jemand beim Einstieg helfen oder mich in die richtige Richtung weisen könnte, wäre ich sehr dankbar. Ich habe Code hinzugefügt, damit Sie eine Vorstellung davon bekommen, was ich tue. Ich sollte in der Lage sein, diesen Code irgendwo in der Lade-FBX-Funktion zu platzieren und ihn funktionieren zu lassen.
//GETTING ANIMAION DATA
for(int i = 0; i < scene->GetSrcObjectCount<FbxAnimStack>(); ++i)
{
FbxAnimStack* lAnimStack = scene->GetSrcObject<FbxAnimStack>(i);
FbxString stackName = "Animation Stack Name: ";
stackName += lAnimStack->GetName();
string sStackName = stackName;
int numLayers = lAnimStack->GetMemberCount<FbxAnimLayer>();
for(int j = 0; j < numLayers; ++j)
{
FbxAnimLayer* lAnimLayer = lAnimStack->GetMember<FbxAnimLayer>(j);
FbxString layerName = "Animation Stack Name: ";
layerName += lAnimLayer->GetName();
string sLayerName = layerName;
queue<FbxNode*> nodes;
FbxNode* tempNode = scene->GetRootNode();
while(tempNode != NULL)
{
FbxAnimCurve* lAnimCurve = tempNode->LclTranslation.GetCurve(lAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);
if(lAnimCurve != NULL)
{
//I know something needs to be done here but I dont know what.
}
for(int i = 0; i < tempNode->GetChildCount(false); ++i)
{
nodes.push(tempNode->GetChild(i));
}
if(nodes.size() > 0)
{
tempNode = nodes.front();
nodes.pop();
}
else
{
tempNode = NULL;
}
}
}
}
Hier ist die volle Funktion
bool FBXLoader::LoadFBX(ParentMeshObject* _parentMesh, char* _filePath, bool _hasTexture)
{
FbxManager* fbxManager = FbxManager::Create();
if(!fbxManager)
{
printf( "ERROR %s : %d failed creating FBX Manager!\n", __FILE__, __LINE__ );
}
FbxIOSettings* ioSettings = FbxIOSettings::Create(fbxManager, IOSROOT);
fbxManager->SetIOSettings(ioSettings);
FbxString filePath = FbxGetApplicationDirectory();
fbxManager->LoadPluginsDirectory(filePath.Buffer());
FbxScene* scene = FbxScene::Create(fbxManager, "");
int fileMinor, fileRevision;
int sdkMajor, sdkMinor, sdkRevision;
int fileFormat;
FbxManager::GetFileFormatVersion(sdkMajor, sdkMinor, sdkRevision);
FbxImporter* importer = FbxImporter::Create(fbxManager, "");
if(!fbxManager->GetIOPluginRegistry()->DetectReaderFileFormat(_filePath, fileFormat))
{
//Unrecognizable file format. Try to fall back on FbxImorter::eFBX_BINARY
fileFormat = fbxManager->GetIOPluginRegistry()->FindReaderIDByDescription("FBX binary (*.fbx)");
}
bool importStatus = importer->Initialize(_filePath, fileFormat, fbxManager->GetIOSettings());
importer->GetFileVersion(fileMinor, fileMinor, fileRevision);
if(!importStatus)
{
printf( "ERROR %s : %d FbxImporter Initialize failed!\n", __FILE__, __LINE__ );
return false;
}
importStatus = importer->Import(scene);
if(!importStatus)
{
printf( "ERROR %s : %d FbxImporter failed to import the file to the scene!\n", __FILE__, __LINE__ );
return false;
}
FbxAxisSystem sceneAxisSystem = scene->GetGlobalSettings().GetAxisSystem();
FbxAxisSystem axisSystem( FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eLeftHanded );
if(sceneAxisSystem != axisSystem)
{
axisSystem.ConvertScene(scene);
}
TriangulateRecursive(scene->GetRootNode());
FbxArray<FbxMesh*> meshes;
FillMeshArray(scene, meshes);
unsigned short vertexCount = 0;
unsigned short triangleCount = 0;
unsigned short faceCount = 0;
unsigned short materialCount = 0;
int numberOfVertices = 0;
for(int i = 0; i < meshes.GetCount(); ++i)
{
numberOfVertices += meshes[i]->GetPolygonVertexCount();
}
Face face;
vector<Face> faces;
int indicesCount = 0;
int ptrMove = 0;
float wValue = 0.0f;
if(!_hasTexture)
{
wValue = 1.0f;
}
for(int i = 0; i < meshes.GetCount(); ++i)
{
int vertexCount = 0;
vertexCount = meshes[i]->GetControlPointsCount();
if(vertexCount == 0)
continue;
VertexType* vertices;
vertices = new VertexType[vertexCount];
int triangleCount = meshes[i]->GetPolygonVertexCount() / 3;
indicesCount = meshes[i]->GetPolygonVertexCount();
FbxVector4* fbxVerts = new FbxVector4[vertexCount];
int arrayIndex = 0;
memcpy(fbxVerts, meshes[i]->GetControlPoints(), vertexCount * sizeof(FbxVector4));
for(int j = 0; j < triangleCount; ++j)
{
int index = 0;
FbxVector4 fbxNorm(0, 0, 0, 0);
FbxVector2 fbxUV(0, 0);
bool texCoordFound = false;
face.indices[0] = index = meshes[i]->GetPolygonVertex(j, 0);
vertices[index].position.x = (float)fbxVerts[index][0];
vertices[index].position.y = (float)fbxVerts[index][1];
vertices[index].position.z = (float)fbxVerts[index][2];
vertices[index].position.w = wValue;
meshes[i]->GetPolygonVertexNormal(j, 0, fbxNorm);
vertices[index].normal.x = (float)fbxNorm[0];
vertices[index].normal.y = (float)fbxNorm[1];
vertices[index].normal.z = (float)fbxNorm[2];
texCoordFound = meshes[i]->GetPolygonVertexUV(j, 0, "map1", fbxUV);
vertices[index].texture.x = (float)fbxUV[0];
vertices[index].texture.y = (float)fbxUV[1];
face.indices[1] = index = meshes[i]->GetPolygonVertex(j, 1);
vertices[index].position.x = (float)fbxVerts[index][0];
vertices[index].position.y = (float)fbxVerts[index][1];
vertices[index].position.z = (float)fbxVerts[index][2];
vertices[index].position.w = wValue;
meshes[i]->GetPolygonVertexNormal(j, 1, fbxNorm);
vertices[index].normal.x = (float)fbxNorm[0];
vertices[index].normal.y = (float)fbxNorm[1];
vertices[index].normal.z = (float)fbxNorm[2];
texCoordFound = meshes[i]->GetPolygonVertexUV(j, 1, "map1", fbxUV);
vertices[index].texture.x = (float)fbxUV[0];
vertices[index].texture.y = (float)fbxUV[1];
face.indices[2] = index = meshes[i]->GetPolygonVertex(j, 2);
vertices[index].position.x = (float)fbxVerts[index][0];
vertices[index].position.y = (float)fbxVerts[index][1];
vertices[index].position.z = (float)fbxVerts[index][2];
vertices[index].position.w = wValue;
meshes[i]->GetPolygonVertexNormal(j, 2, fbxNorm);
vertices[index].normal.x = (float)fbxNorm[0];
vertices[index].normal.y = (float)fbxNorm[1];
vertices[index].normal.z = (float)fbxNorm[2];
texCoordFound = meshes[i]->GetPolygonVertexUV(j, 2, "map1", fbxUV);
vertices[index].texture.x = (float)fbxUV[0];
vertices[index].texture.y = (float)fbxUV[1];
faces.push_back(face);
}
meshes[i]->Destroy();
meshes[i] = NULL;
int indexCount = faces.size() * 3;
unsigned long* indices = new unsigned long[faces.size() * 3];
int indicie = 0;
for(unsigned int i = 0; i < faces.size(); ++i)
{
indices[indicie++] = faces[i].indices[0];
indices[indicie++] = faces[i].indices[1];
indices[indicie++] = faces[i].indices[2];
}
faces.clear();
_parentMesh->AddChild(vertices, indices, vertexCount, indexCount);
}
return true;
}