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

Use assimp for loading meshes #393

Merged
merged 86 commits into from
Jul 30, 2022
Merged

Use assimp for loading meshes #393

merged 86 commits into from
Jul 30, 2022

Conversation

luca-della-vedova
Copy link
Member

@luca-della-vedova luca-della-vedova commented Jul 13, 2022

🎉 New feature

Closes #374

Summary

This PR introduces using the assimp library for parsing models and, with it, support for GLB, GLTF and FBX formats.
For now it overrides all the custom loaders, there is no known regression with obj and stl, while there are a few regression with collada files.
Most of the regressions have been handled upstream at the assimp library level, however the fixes didn't make it to the released Debian package so they might not reflect unless assimp is built from source or a new release is triggered upstream.
A regression in actor.sdf that segfaults is known and currently under investigation.
Imo a nice stretch goal would be to deprecate as many loaders as possible and only maintain one but this can be a scary change so the alternative could be to just add yet another loader for "all other formats" and keep using the internal ones for obj, stl and dae. However, obj and stl seem to be simple and reliable enough that I believe they could be removed.

Depends on a gz-cmake PR and release to add support for finding assimp in gz_find_package for CI to be green.

Test it

All the unit tests from STL, Collada and OBJ loaders have been ported to the assimp loader and updated in cases where the behavior changed.
New unit tests for the new formats have been merged in #385 by @onurtore.
You will need a few glb assets to test this PR, I provided a few in the matching gz-rendering PR.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

luca-della-vedova and others added 30 commits May 13, 2022 12:20
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off by: Onur Berk Tore [email protected]

Co-authored-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
* Fix: Works even the root node doesnt have child

* Assimp also generates normals

* Revert "Fix: Works even the root node doesnt have child"

This reverts commit 7687252.

Signed-off by: Onur Berk Tore, [email protected]

Signed-off by: Onur Berk Tore, [email protected]

Co-authored-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off-by: Luca Della Vedova <[email protected]>
Copy link
Contributor

@onurtore onurtore left a comment

Choose a reason for hiding this comment

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

Tested locally, looks good to me

this->dataPtr->fileExtensions.insert("gltf");
this->dataPtr->fileExtensions.insert("glb");
this->dataPtr->fileExtensions.insert("fbx");

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @luca-della-vedova,
Should we remove this newline?

@onurtore
Copy link
Contributor

onurtore commented Aug 7, 2022

Hi @luca-della-vedova, @ahcorde,

While I trying to fix seg fault of actor.sdf, I have realized there is at least two reason for the seg fault, one is solved in this PR, second is bvh animation in actor.sdf. Before bvh animation are added to skeleton in here we are checking whether loaded bvh skeleton count are same with the skeleton loaded through mesh manager. If we use scene node in mesh manager, then those numbers are not same (The code is here). Actually, even if we use assimp for loading bvh file, which I tried, then the rootNode will not be scene, bvh loader in assimp do not utilize scene node. (I also utilized a check for any occurence of error during bvhloading in here)

So there are two things we can do, if this PR, and this PR are merged, then seg fault problem will dissappear. Otherwise, we have to modify the code during Bvhloading in SkeletonAnimation. I dont think that will be hard, and even we might deprecate the bvhloader and use assimp there as well.

The hotfix looks little bit hackish so I am not sure it is the right direction, so I am waiting your views on the topic to move forward.

// Now add the bones to the skeleton
if (assimpMesh->HasBones() && _scene->HasAnimations())
{
// TODO(luca) merging skeletons here
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @luca-della-vedova,
Can you eloborate on this TODO little bit more, I want to implement it, but I did not quite understand it.

// TODO(luca) merging skeletons here
auto skeleton = _mesh->MeshSkeleton();
// TODO(luca) Append to existing skeleton if multiple submeshes?
skeleton->SetNumVertAttached(subMesh.VertexCount());
Copy link
Contributor

@onurtore onurtore Aug 9, 2022

Choose a reason for hiding this comment

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

Hi @luca-della-vedova,
Is this TODO necessary ? By the way, resizing this vector in each iteration looks like heavy operation, but I don't think we have better alternative.

math::Vector3d texcoords;
texcoords.X(_assimpMesh->mTextureCoords[uvIdx][vertexIdx].x);
texcoords.Y(_assimpMesh->mTextureCoords[uvIdx][vertexIdx].y);
// TODO(luca) why do we need 1.0 - Y?
Copy link
Contributor

@onurtore onurtore Aug 11, 2022

Choose a reason for hiding this comment

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

Hi @luca-della-vedova,
Looks like aiProcess_FlipUVs flag solves this issue, should we use that?

auto [texName, texData] = this->LoadTexture(_scene,
texturePath, this->GenerateTextureName(_scene, assimpMat, "Diffuse"));
if (texData != nullptr)
mat->SetTextureImage(texName, texData);
Copy link
Contributor

@onurtore onurtore Aug 22, 2022

Choose a reason for hiding this comment

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

Hi @luca-della-vedova,
Do you know how we can combine multiple diffuse in here? I want to implement it but my knowledge is weak. I know we can access them using a while loop but dont know how to merge them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change Breaks API, ABI or behavior. Must target unstable version. enhancement New feature or request 🌱 garden Ignition Garden
Projects
Archived in project
5 participants