I'm trying to load a mesh in my application using assimp. But this work well only with the format .stl, but with other format only a part of mesh is displayed. This is my code:
bool ModelClass::LoadModel(char* filename)
{
Assimp::Importer m_LocalImporter;
// Important! Makes sure that if the angle between two face normals is > 80 they are not smoothed together.
// Since the angle between a cubes face normals is 90 the lighting looks very bad if we don't specify this.
m_LocalImporter.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f);
m_LocalImporter.SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 1);
m_LocalImporter.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE);
const aiScene* scene = NULL;
UINT NumMeshes;
UINT NumFaces;
scene = m_LocalImporter.ReadFile(filename,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_GenSmoothNormals |
aiProcess_SplitLargeMeshes |
aiProcess_ConvertToLeftHanded |
aiProcess_SortByPType);
if(scene)
{
NumMeshes = scene->mNumMeshes;
for(DWORD nMesh=0; nMesh < NumMeshes; nMesh++)
{
aiMesh* mesh = scene->mMeshes[nMesh];
for(DWORD nVertex = 0; nVertex < mesh->mNumVertices; nVertex++)
{
VertexType vertex;
vertex.position.x = mesh->mVertices[nVertex].x;
vertex.position.y = mesh->mVertices[nVertex].y;
vertex.position.z = mesh->mVertices[nVertex].z;
vertex.normal.x = mesh->mNormals[nVertex].x;
vertex.normal.y = mesh->mNormals[nVertex].y;
vertex.normal.z = mesh->mNormals[nVertex].z;
if(mesh->HasTextureCoords(0))
{
vertex.texture.x = mesh->mTextureCoords[0][nVertex].x;
vertex.texture.y = mesh->mTextureCoords[0][nVertex].y;
}
vVertices.push_back(vertex);
}
for(DWORD nFaces = 0; nFaces < mesh->mNumFaces; nFaces++)
for(int nIndex = 0; nIndex < mesh->mFaces[nFaces].mNumIndices; nIndex++)
vIndices.push_back(mesh->mFaces[nFaces].mIndices[nIndex]);
}
}
else
{
return false;
}
return true;
}
Screen:
OBJ format:
STL format:
My obj file: