Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTF Importer: Build a list of the actual vertices so it works well with shared attribute lists #5003

Conversation

FlorianBorn71
Copy link
Contributor

@FlorianBorn71 FlorianBorn71 commented Mar 9, 2023

This PR addresses this bug:
Out-of-memory for some gltf exported with "Sketchup glTF Exporter by Centaur"

It shows that the memory consumption during import for said customer model now goes down from >800GM (->out-of-memory) to <700MB, so more than 1000x !

In my opinion this change makes sense, but I wanted to ask if this looks like a good approach to the problem for you as well.
Of course this needs more testing with other assets,

ASSIMP_LOG_WARN("Positions of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
} else {
aiVector3D *positionDiff = nullptr;
target.position[0]->ExtractData(positionDiff);
target.position[0]->ExtractData(positionDiff, vertexRemappingTable);
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
aiAnimMesh.mVertices[vertexId] += positionDiff[vertexId];
}
delete[] positionDiff;
}
}
if (needNormals) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to revisit whether the following block still uses the correct indexing of normals/tangets for animated parts

@@ -380,7 +380,7 @@ TEST_F(utglTF2ImportExport, importglTF2PrimitiveModeLines) {
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/glTF-Asset-Generator/Mesh_PrimitiveMode/Mesh_PrimitiveMode_08.gltf", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);
EXPECT_EQ(scene->mMeshes[0]->mNumVertices, 4u);
std::array<unsigned int, 5> l1 = { { 0u, 3u, 2u, 1u, 0u } };
std::array<unsigned int, 5> l1 = { { 0u, 1u, 2u, 3u, 0u } };
EXPECT_EQ(scene->mMeshes[0]->mFaces[0].mNumIndices, 2u);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracting the used vertices changes the order of vertices and thus the index buffer

@FlorianBorn71
Copy link
Contributor Author

@kimkulling , what do you think about this improvements?
Summarized, I changed the GLTF loading code to build a list of vertices that are actually needed per primitive. This gives us huge memory saving in case the full vertex attribute stream is shared for many primitives. In case of the customer model, the memory saving was 1000x

@kimkulling
Copy link
Member

I have started to take a look on it. Stay tuned :-).

Copy link
Member

@kimkulling kimkulling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when identitying the indices are the same this fix will just reuse them to save memory allocation. Great idea! Thanks a lot for your investigations and the PR as well! I really appreciate this!

@kimkulling kimkulling merged commit f2efcd7 into assimp:master Apr 3, 2023
11 checks passed
@kimkulling
Copy link
Member

Merged, thanks a lot for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants