| 901 | } |
| 902 | |
| 903 | void Model::CreateWithAssimp(ID3D11Device* device, const wchar* fileName, bool forceSRGB) |
| 904 | { |
| 905 | Assert_(FileExists(fileName)); |
| 906 | |
| 907 | std::string fileNameAnsi = WStringToAnsi(fileName); |
| 908 | |
| 909 | Assimp::Importer importer; |
| 910 | uint32 flags = aiProcess_CalcTangentSpace | |
| 911 | aiProcess_Triangulate | |
| 912 | aiProcess_JoinIdenticalVertices | |
| 913 | aiProcess_MakeLeftHanded | |
| 914 | aiProcess_PreTransformVertices | |
| 915 | aiProcess_RemoveRedundantMaterials | |
| 916 | aiProcess_OptimizeMeshes | |
| 917 | aiProcess_FlipUVs | |
| 918 | aiProcess_FlipWindingOrder ; |
| 919 | const aiScene* scene = importer.ReadFile(fileNameAnsi, flags); |
| 920 | |
| 921 | if(scene == nullptr) |
| 922 | throw Exception(L"Failed to load scene " + std::wstring(fileName) + |
| 923 | L": " + AnsiToWString(importer.GetErrorString())); |
| 924 | |
| 925 | if(scene->mNumMeshes == 0) |
| 926 | throw Exception(L"Scene " + std::wstring(fileName) + L" has no meshes"); |
| 927 | |
| 928 | if(scene->mNumMaterials == 0) |
| 929 | throw Exception(L"Scene " + std::wstring(fileName) + L" has no materials"); |
| 930 | |
| 931 | fileDirectory = GetDirectoryFromFilePath(fileName); |
| 932 | |
| 933 | // Load the materials |
| 934 | const uint64 numMaterials = scene->mNumMaterials; |
| 935 | for(uint64 i = 0; i < numMaterials; ++i) |
| 936 | { |
| 937 | MeshMaterial material; |
| 938 | const aiMaterial& mat = *scene->mMaterials[i]; |
| 939 | |
| 940 | aiString diffuseTexPath; |
| 941 | aiString normalMapPath; |
| 942 | if(mat.GetTexture(aiTextureType_DIFFUSE, 0, &diffuseTexPath) == aiReturn_SUCCESS) |
| 943 | material.DiffuseMapName = GetFileName(AnsiToWString(diffuseTexPath.C_Str()).c_str()); |
| 944 | |
| 945 | if(mat.GetTexture(aiTextureType_NORMALS, 0, &normalMapPath) == aiReturn_SUCCESS |
| 946 | || mat.GetTexture(aiTextureType_HEIGHT, 0, &normalMapPath) == aiReturn_SUCCESS) |
| 947 | material.NormalMapName = GetFileName(AnsiToWString(normalMapPath.C_Str()).c_str()); |
| 948 | |
| 949 | LoadMaterialResources(material, fileDirectory, device, forceSRGB); |
| 950 | |
| 951 | meshMaterials.push_back(material); |
| 952 | } |
| 953 | |
| 954 | // Initialize the meshes |
| 955 | const uint64 numMeshes = scene->mNumMeshes; |
| 956 | meshes.resize(numMeshes); |
| 957 | for(uint64 i = 0; i < numMeshes; ++i) |
| 958 | meshes[i].InitFromAssimpMesh(device, *scene->mMeshes[i]); |
| 959 | } |
| 960 |
nothing calls this directly
no test coverage detected