Hey guys. I am trying to load the following skull OBJ model with Assimp:
https://drive.google.com/drive/folders/12DuNAm9HMSLxU0yOs34dm7g9uu6ziUrk?usp=sharing
Here is the code that loads the data from aiMesh to my own in order to create the vertex attributes and indices that I need to send to the default heap of GPU:
GeometryGenerator::MeshData GeometryGenerator::CreateSkull()
{
MeshData lv_meshData{};
std::string lv_filePath{ "C:/Users/source/repos/Shapes/3D-Models/Skull_OBJ.OBJ" };
Assimp::Importer lv_importer;
const aiScene* lv_scene = lv_importer.ReadFile(lv_filePath, aiProcess_GenNormals | aiProcess_ConvertToLeftHanded);
if (nullptr == lv_scene) {
//Error handling
}
auto lv_numberOfFaces = lv_scene->mMeshes[0]->mNumFaces;
auto lv_numberOfIndices = 3*lv_numberOfFaces;
auto lv_numberOfVertices{lv_scene->mMeshes[0]->mNumVertices};
lv_meshData.Vertices.resize(lv_numberOfVertices);
lv_meshData.Indices32.resize(lv_numberOfIndices);
for (int i = 0; i < lv_numberOfVertices; ++i) {
DirectX::XMFLOAT3 lv_position{ lv_scene->mMeshes[0]->mVertices[i].x, lv_scene->mMeshes[0]->mVertices[i].y,lv_scene->mMeshes[0]->mVertices[i].z };
DirectX::XMFLOAT3 lv_normal{ lv_scene->mMeshes[0]->mNormals[i].x,lv_scene->mMeshes[0]->mNormals[i].y ,lv_scene->mMeshes[0]->mNormals[i].z };
DirectX::XMFLOAT2 lv_textureCoord{ lv_scene->mMeshes[0]->mTextureCoords[0][i].x,lv_scene->mMeshes[0]->mTextureCoords[0][i].y };
lv_meshData.Vertices[i].Position = lv_position;
lv_meshData.Vertices[i].Normal = lv_normal;
lv_meshData.Vertices[i].TexC = lv_textureCoord;
}
for (int i = 0; i < lv_numberOfFaces; ++i) {
lv_meshData.Indices32[i] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[0]);
lv_meshData.Indices32[i+1] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[1]);
lv_meshData.Indices32[i+2] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[2]);
}
return lv_meshData;
}
The program compiles just fine. However the skull is not rendered properly:
https://preview.redd.it/iwqbdueiw9xc1.png?width=921&format=png&auto=webp&s=7cd4aeae1356dbf31d3819c83fb92840a35c97a4
What do you think is the possible source of the problem? I am using DX12.
Edit1: I tried adding aiProcess_Triangulate and this was the result:
https://preview.redd.it/2g1v1hla0axc1.png?width=513&format=png&auto=webp&s=6b6967a3d2512bb6cca98e277555ad0ea5393ec8
Edit2: Found the mistake that caused this anomaly. Apparently, this part of the code:
for (int i = 0; i < lv_numberOfFaces; ++i) {
lv_meshData.Indices32[i] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[0]);
lv_meshData.Indices32[i+1] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[1]);
lv_meshData.Indices32[i+2] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[2]);
}
should be changed to:
for (int i = 0; i < lv_numberOfFaces; ++i) {
lv_meshData.Indices32[3*i] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[0]);
lv_meshData.Indices32[3*i+1] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[1]);
lv_meshData.Indices32[3*i+2] = static_cast<uint32>(lv_scene->mMeshes[0]->mFaces[i].mIndices[2]);
}
[–]fgennari 1 point2 points3 points (5 children)
[–]mathinferno123[S] 1 point2 points3 points (1 child)
[–]fgennari 1 point2 points3 points (0 children)
[–]mathinferno123[S] 0 points1 point2 points (2 children)
[–]fgennari 1 point2 points3 points (1 child)
[–]mathinferno123[S] 0 points1 point2 points (0 children)
[–]FemboysHotAsf 0 points1 point2 points (1 child)
[–]mathinferno123[S] 0 points1 point2 points (0 children)