HRESULT FBXLoader::Open(HWND hWnd, char* Filename)
{
HRESULT hr = S_OK;
if (FBXM)
{
FBXIOS = FbxIOSettings::Create(FBXM, IOSROOT);
FBXM->SetIOSettings(FBXIOS);
FBXI = FbxImporter::Create(FBXM, "");
if (!(FBXI->Initialize(Filename, -1, FBXIOS)))
MessageBox(hWnd, (wchar_t*)FBXI->GetStatus().GetErrorString(), TEXT("ALM"), MB_OK);
FBXS = FbxScene::Create(FBXM, "MCS");
if (!FBXS)
MessageBox(hWnd, TEXT("Failed to create the scene"), TEXT("ALM"), MB_OK);
if (!(FBXI->Import(FBXS)))
MessageBox(hWnd, TEXT("Failed to import fbx file content into the scene"), TEXT("ALM"), MB_OK);
if (FBXI)
FBXI->Destroy();
FbxNode* MainNode = FBXS->GetRootNode();
int NumKids = MainNode->GetChildCount();
FbxNode* ChildNode = NULL;
for (int i=0; i<NumKids; i++)
{
ChildNode = MainNode->GetChild(i);
FbxNodeAttribute* NodeAttribute = ChildNode->GetNodeAttribute();
if (NodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh)
{
FbxMesh* Mesh = ChildNode->GetMesh();
NumVertices = Mesh->GetControlPointsCount();//number of vertices
MyV = new FBXVTX[NumVertices];
for (DWORD j = 0; j < NumVertices; j++)
{
FbxVector4 Vertex = Mesh->GetControlPointAt(j);//Gets the control point at the specified index.
MyV[j].Position = XMFLOAT3((float)Vertex.mData[0], (float)Vertex.mData[1], (float)Vertex.mData[2]);
}
NumIndices = Mesh->GetPolygonVertexCount();//number of indices; for cube 20
MyI = new DWORD[NumIndices];
MyI = (DWORD*)Mesh->GetPolygonVertices();//index array
NumFaces = Mesh->GetPolygonCount();
MyF = new FBXFACEX[NumFaces];
for (int l=0;l<NumFaces;l++)
{
MyF[l].Vertices[0] = MyI[4*l];
MyF[l].Vertices[1] = MyI[4*l+1];
MyF[l].Vertices[2] = MyI[4*l+2];
MyF[l].Vertices[3] = MyI[4*l+3];
}
UV = new XMFLOAT2[NumIndices];
for (int i = 0; i < Mesh->GetPolygonCount(); i++)//polygon(=mostly rectangle) count
{
FbxLayerElementArrayTemplate<FbxVector2>* uvVertices = NULL;
Mesh->GetTextureUV(&uvVertices);
for (int j = 0; j < Mesh->GetPolygonSize(i); j++)//retrieves number of vertices in a polygon
{
FbxVector2 uv = uvVertices->GetAt(Mesh->GetTextureUVIndex(i, j));
UV[4*i+j] = XMFLOAT2((float)uv.mData[0], (float)uv.mData[1]);
}
}
}
}
}
else
MessageBox(hWnd, TEXT("Failed to create the FBX Manager"), TEXT("ALM"), MB_OK);
return hr;
}
I've been trying to load fbx files(cube.fbx) into my programme. but I get this. Can someone pls help me?
↧