//-------------------------------------------------------------------------------------- // Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED) // and aren't tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { g_SettingsDlg.Init( &g_DialogResourceManager ); g_HUD.Init( &g_DialogResourceManager ); g_SampleUI.Init( &g_DialogResourceManager ); g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ); g_SettingsDlg.OnD3D9CreateDevice( pd3dDevice ); g_HUD.SetCallback( OnGUIEvent ); int iY = 10; g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 ); g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22, VK_F3 ); g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 ); g_SampleUI.SetCallback( OnGUIEvent ); iY = 10; g_SampleUI.AddCheckBox( IDC_DISABLEALBEDO, L"Disable albedo", 35, iY += 24, 160, 22, g_DisableAlbedo ); g_SampleUI.AddCheckBox( IDC_PAUSEANIMATION, L"Pause animation", 35, iY += 24, 160, 22, g_PauseAnimation ); g_SampleUI.AddCheckBox( IDC_DISABLESKINING, L"Disable skining", 35, iY += 24, 160, 22, g_DisableSkining ); g_SampleUI.AddCheckBox( IDC_SHOWNORMALS, L"Show normals", 35, iY += 24, 160, 22, g_ShowNormals ); CDXUTComboBox* pCombo; g_SampleUI.AddComboBox( IDC_TECHNIQUECOMBO, 35, iY += 30, 160, 22, 0, false, &pCombo ); if( pCombo ) { pCombo->SetDropHeight( 100 ); pCombo->AddItem( L"Unpacked TBN", ( LPVOID )0x0 ); pCombo->AddItem( L"Packed TBN", ( LPVOID )0x1 ); pCombo->AddItem( L"Unpacked Quaternion", ( LPVOID )0x2 ); pCombo->AddItem( L"Packed Quaternion", ( LPVOID )0x3 ); pCombo->SetSelectedByIndex(g_TechniqueIndex); } iY = 10; D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &g_pFont9 ); d3dAnimation.Create(pd3dDevice); d3dMesh.Create(pd3dDevice); d3dFloor.Create(pd3dDevice); FBXImporter importer; const char* fbxFileName = ".\\data\\MilitaryMechanic.fbx"; importer.Import(fbxFileName, &d3dMesh, &d3dAnimation); return S_OK; }
void FBXObj::Import(char* filename, ID3D11Device* dev) { vector<XMFLOAT3> positions; vector<int> indices; vector<XMFLOAT3> norms; vector<XMFLOAT2> texVec; vector<int> texNum; mFBXImporter.Import(filename, &positions, &indices, &norms, &texVec, &texNum); std::vector<Vertex::PosNormalTexTan> vertices; Vertex::PosNormalTexTan tempVert; XMVECTOR p; XMVECTOR n; for(int i = 0; i < positions.size(); i++) { p = XMVectorSet(positions[i].x, positions[i].y,positions[i].z, 1.0 ); n = XMVectorSet(norms[i].x, norms[i].y, norms[i].z, 1.0 ); XMVECTOR cross = XMVector3Cross(p, n); XMStoreFloat3(&tempVert.TangentU, cross); tempVert.Pos = positions[i]; tempVert.Normal = norms[i]; tempVert.Tex = texVec[i]; tempVert.TexNum = texNum[i]; vertices.push_back(tempVert); } mIndexCount = indices.size(); mVertexCount = positions.size(); mVertices = positions; mIndices = indices; D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(Vertex::PosNormalTexTan) * positions.size(); vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = &vertices[0]; HR(dev->CreateBuffer(&vbd, &vinitData, &mVB)); // // Pack the indices of all the meshes into one index buffer. // D3D11_BUFFER_DESC ibd; ibd.Usage = D3D11_USAGE_IMMUTABLE; ibd.ByteWidth = sizeof(UINT) * mIndexCount; ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; ibd.CPUAccessFlags = 0; ibd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = &indices[0]; HR(dev->CreateBuffer(&ibd, &iinitData, &mIB)); }
int main( int argc, char* argv[] ) { Logger::Start_Log( "converter.log", false ); for( int i = 0; i < argc; i++ ) to_lower( argv[i] ); if( argc == 1 ) { print_usage( argv[0], false ); return ERROR_SUCCESS; } if( strcmp( argv[1], "--help" ) == 0 || strcmp( argv[1], "-h" ) == 0 ) { print_usage( argv[0], true ); return ERROR_SUCCESS; } if( argc > 4 ) { Print_Error_Message( "Error: Too many arguments." ); return ERROR_BAD_ARGUMENTS; } char* path; char* fbxFilename; Parse_Path( argv[1], path, fbxFilename ); if( strlen( fbxFilename ) < 4 || strcmp( fbxFilename + strlen( fbxFilename ) - 4, ".fbx" ) != 0 ) { Print_Error_Message( "Error: the FBX file argument does not have the proper file extension.\n" ); return ERROR_BAD_ARGUMENTS; } if( strlen( fbxFilename ) == 4 ) { Print_Error_Message( "Error: the FBX file argument must be more than just the extension.\n" ); return ERROR_BAD_ARGUMENTS; } FBXImporter importer; importer.Import( path, fbxFilename ); if( argc == 4 ) { if( strcmp( argv[2], "-include" ) != 0 ) { Print_Error_Message( "Error: unknown parameter/option.\n" ); return ERROR_BAD_ARGUMENTS; } char* additionalTexture = argv[3]; importer.Add_Extra_Texture( additionalTexture ); } ModelWriter::Write( importer.GetModelData(), path, MODEL_CONVERTER_VERSION ); Logger::Stop_Log(); return ERROR_SUCCESS; }