Bug: Assimp doesn't load all geometries for some meshes
- Dominant language
- C++
- Stars
- 13.2k
- Forks
- 3.2k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 21
Description
I have a problem with loading some fbx models. I use assimp for loading models and my first a test model loads correctly but I tried to load others models and get models with not whole geometry. I try to solve the proble but stuck and have no idea why this happens.
`bool Mesh_Loader::load(const char *file_name, bool print_info)
{
print("Mesh_Loader::load: Started to load {}.", file_name);
String path;
build_full_path_to_model_file(file_name, path);
if (!file_exists(path)) {
print("Mesh_Loader::load: Failed to load. {} does not exist in model folder.", file_name);
return false;
}
auto postProcessSteps = (aiPostProcessSteps)(
aiProcess_Triangulate |
aiProcess_SortByPType |
aiProcess_CalcTangentSpace |
aiProcess_FlipUVs |
aiProcess_JoinIdenticalVertices |
aiProcess_ConvertToLeftHanded);
scene = (aiScene *)importer.ReadFile(path, postProcessSteps);
if (!scene) {
print("Mesh_Loader::load: Failed to load a scene from {}.", file_name);
return false;
}
if (print_info) {
print_nodes(scene, scene->mRootNode);
}
auto matrix = aiMatrix4x4(
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
process_nodes(scene->mRootNode, matrix);
print("Mesh_Loader::load: {} was load successfully.", file_name);
return true;
}
void Mesh_Loader::process_nodes(aiNode *node, aiMatrix4x4 parent_transform_matrix)
{
Array processed_meshes;
for (u32 i = 0; i < node->mNumMeshes; i++) {
u32 mesh_index = node->mMeshes[i];
const char *mesh_name = scene->mMeshes[mesh_index]->mName.C_Str();
Mesh_Instance *mesh_instance = NULL;
if (!mesh_instance_table.get(mesh_name, &mesh_instance)) {
mesh_instance = new Mesh_Instance();
mesh_instance->name = mesh_name;
process_mesh(scene->mMeshes[mesh_index], &mesh_instance->mesh);
mesh_instance_table.set(mesh_name, mesh_instance);
mesh_instances.push(mesh_instance);
}
aiMatrix4x4 temp = parent_transform_matrix * node->mTransformation;
Matrix4 transform_matrix = {
temp.a1, temp.a2, temp.a3, temp.a4,
temp.b1, temp.b2, temp.b3, temp.b4,
temp.c1, temp.c2, temp.c3, temp.c4,
temp.d1, temp.d2, temp.d3, temp.d4,
};
transform_matrix = transpose(&transform_matrix);
mesh_instance->transform_matrices.push(transform_matrix);
}
aiMatrix4x4 transform_matrix = node->mTransformation * parent_transform_matrix;
for (u32 i = 0; i < node->mNumChildren; i++) {
process_nodes(node->mChildren[i], transform_matrix);
}
}
void Mesh_Loader::process_mesh(aiMesh *ai_mesh, Triangle_Mesh *mesh)
{
mesh->vertices.clear();
mesh->indices.clear();
for (u32 i = 0; i < ai_mesh->mNumVertices; i++) {
Vertex_XNUV vertex;
vertex.position.x = ai_mesh->mVertices[i].x;
vertex.position.y = ai_mesh->mVertices[i].y;
vertex.position.z = ai_mesh->mVertices[i].z;
if (ai_mesh->HasTextureCoords(0)) {
vertex.uv.x = (float)ai_mesh->mTextureCoords[0][i].x;
vertex.uv.y = (float)ai_mesh->mTextureCoords[0][i].y;
}
if (ai_mesh->HasNormals()) {
vertex.normal.x = ai_mesh->mNormals[i].x;
vertex.normal.y = ai_mesh->mNormals[i].y;
vertex.normal.z = ai_mesh->mNormals[i].z;
}
mesh->vertices.push(vertex);
}
for (u32 i = 0; i < ai_mesh->mNumFaces; i++) {
aiFace face = ai_mesh->mFaces[i];
assert(face.mNumIndices == 3);
for (u32 j = 0; j < face.mNumIndices; j++) {
mesh->indices.push(face.mIndices[j]);
}
}
}`
Assimp log: Info, T9096: Load d:\dev\hades-engine\data\models\Scene_Demo2.fbx
Assimp log: Debug, T9096: Assimp 5.2.2275576043 amd64 msvc debug shared singlethreadedsingle :
Assimp log: Info, T9096: Found a matching importer for this file format: Autodesk FBX Importer.
Assimp log: Info, T9096: Import root directory is 'd:\dev\hades-engine\data\models\'
Assimp log: Debug, T9096: Reading FBX file
Assimp log: Debug, T9096: Tokenizing binary FBX file
Assimp log: Debug, T9096: FBX version: 7300
Assimp log: Debug, T9096: Parsing FBX tokens
Assimp log: Debug, T9096: Creating FBX Document
Assimp log: Debug, T9096: FBX Version: 7300
Assimp log: Info, T9096: FBX: ignoring empty AnimationStack (using IK?): Unreal Take
Assimp log: Warn, T9096: FBX-DOM (TOK_KEY, offset 0x38695) property table (Properties70) not found
Assimp log: Warn, T9096: FBX-DOM (TOK_KEY, offset 0x388cd) property table (Properties70) not found
Assimp log: Warn, T9096: FBX-DOM (TOK_KEY, offset 0x38b05) property table (Properties70) not found
Assimp log: Warn, T9096: FBX-DOM (TOK_KEY, offset 0x38d47) property table (Properties70) not found
Assimp log: Debug, T9096: UpdateImporterScale scale set: 0.01
Assimp log: Info, T9096: Entering post processing pipeline
Assimp log: Debug, T9096: MakeLeftHandedProcess begin
Assimp log: Debug, T9096: MakeLeftHandedProcess finished
Assimp log: Debug, T9096: FlipUVsProcess begin
Assimp log: Debug, T9096: FlipUVsProcess finished
Assimp log: Debug, T9096: FlipWindingOrderProcess begin
Assimp log: Debug, T9096: FlipWindingOrderProcess finished
Assimp log: Info, T9096: Leaving post processing pipeline
Contributor guide
Research direction
Start at Mesh_Loader::load and trace the calls into process_nodes and process_mesh using the reported Scene_Demo2.fbx case. Compare the geometries present in the imported aiScene with the meshes and indices produced by the loader, then determine whether the loss occurs during FBX import or while traversing and storing nodes. Done means the affected models load all expected geometry or the issue is reduced to a reproducible Assimp importer defect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100