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
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
33c8d2f
First draft of assimp loader, can load obj and dae meshes
luca-della-vedova May 13, 2022
bce766d
WIP correct material assignments
luca-della-vedova May 13, 2022
3b08c5b
Refactor mesh creation into separate function
luca-della-vedova May 13, 2022
0ed8f69
WIP adding actor support
luca-della-vedova May 18, 2022
531b2a8
[FEATURE] Drag and drop support for gltf and fbx (#354)
May 18, 2022
8f63b21
WIP actors with single skeletons working
luca-della-vedova May 20, 2022
db823ca
Migrate to assimp 5.2.0
luca-della-vedova May 23, 2022
1795314
Fix: Works even the root node doesnt have child (#358)
May 30, 2022
ce4cfc8
Only load bones if model has animations
luca-della-vedova May 30, 2022
47e42a3
Naming style to follow Gazebo convention
luca-della-vedova May 30, 2022
2a94bfc
Merge branch 'main' of github.com:gazebosim/gz-common into luca/assim…
luca-della-vedova May 30, 2022
c106035
Fix after namespace migration
luca-della-vedova May 30, 2022
d5f9935
Parse alpha from texture from GLTF materials
luca-della-vedova Jun 1, 2022
1f28b89
Minor cleanups, parse metalness and roughness
luca-della-vedova Jun 1, 2022
b7f160a
Fix: Assimp generates normals for all the meshes. (#359)
Jun 3, 2022
1c9771d
WIP create API for having in memory textures
luca-della-vedova Jun 6, 2022
fd3a0f5
Diffuse textures working
luca-della-vedova Jun 6, 2022
08f1102
Add API to load compressed images and read RGBA data
luca-della-vedova Jun 9, 2022
661823c
Add test
luca-della-vedova Jun 9, 2022
b5ab18f
Deallocate memory in tests
luca-della-vedova Jun 9, 2022
97b459e
Merge branch 'feature/compressed_images' into luca/inmemory_textures
luca-della-vedova Jun 9, 2022
d08554f
Migrate to image API, minor cleanups
luca-della-vedova Jun 10, 2022
304cd93
Merge branch 'luca/inmemory_textures' into luca/assimp_sandbox
luca-della-vedova Jun 10, 2022
d6c59b1
Add PBR materials to inmemory textures
luca-della-vedova Jun 10, 2022
6879e1c
Merge branch 'luca/inmemory_textures' into luca/assimp_sandbox
luca-della-vedova Jun 13, 2022
435fe13
Use correct mesh index to load bones
luca-della-vedova Jun 15, 2022
91e32ea
Add metallic roughness map support
luca-della-vedova Jun 17, 2022
d09f892
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jun 21, 2022
ee7fb08
Add API to return image data as vector of bytes
luca-della-vedova Jun 21, 2022
7ee1c45
Update migration guide
luca-della-vedova Jun 21, 2022
c822fc0
Move to new API
luca-della-vedova Jun 22, 2022
032611b
Move to GZ impl ptr, don't remove empty bones
luca-della-vedova Jun 23, 2022
05f4604
Merge branch 'main' into luca/vector_image_data
mjcarroll Jun 24, 2022
2f78228
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jun 27, 2022
9d9d692
Merge branch 'main' into luca/vector_image_data
mjcarroll Jun 27, 2022
41541c1
Add path to find external texture for collada files
luca-della-vedova Jun 28, 2022
da0d078
WIP port all tests from other loaders
luca-della-vedova Jun 28, 2022
98c5c06
Minor cleanup and name migration
luca-della-vedova Jun 28, 2022
2f580e7
WIP Fixing and reenabling tests
luca-della-vedova Jun 28, 2022
efec93f
Fix more tests
luca-della-vedova Jun 28, 2022
683a6c1
Fix a few more unit tests
luca-della-vedova Jun 29, 2022
b5bc4db
Fix: Reversed models when skeletons exist (#375)
Jun 30, 2022
b630640
Merge branch 'main' into luca/vector_image_data
mjcarroll Jun 30, 2022
a970a52
Revert to only parse skeletons for scenes with animations
luca-della-vedova Jul 8, 2022
4e7c022
Clean debug statements
luca-della-vedova Jul 12, 2022
2b2e220
Minor performance improvements in mesh manager
luca-della-vedova Jul 12, 2022
d030bc5
Add assimp dependency to github packages
luca-della-vedova Jul 12, 2022
af99a3e
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jul 12, 2022
57f8a73
Don't force assimp version anymore
luca-della-vedova Jul 12, 2022
8bb789e
Code style
luca-della-vedova Jul 12, 2022
5a5cbea
Documentation, remove workaround and clean state
luca-della-vedova Jul 12, 2022
d647967
Minor cleanup and review feedback
luca-della-vedova Jul 14, 2022
28f9b68
Merge branch 'main' into luca/vector_image_data
mjcarroll Jul 18, 2022
589bc8a
Merge branch 'main' of https://github.com/ignitionrobotics/ign-common…
luca-della-vedova Jul 19, 2022
51a8953
WIP compile in Ubuntu 20.04
luca-della-vedova Jul 19, 2022
d798f74
WIP Make CI green in focal
luca-della-vedova Jul 20, 2022
a62eb6f
Fix CI in Jammy
luca-della-vedova Jul 20, 2022
8ce8b79
Update for bone node assignment in assimp 5.2.0
luca-della-vedova Jul 20, 2022
6a0839a
Fix bone node name logic
luca-della-vedova Jul 20, 2022
cdfb6da
Revert to normal loaders for old asset formats
luca-della-vedova Jul 20, 2022
61e22e6
Remove commented tests
luca-della-vedova Jul 20, 2022
8fe6b91
Feature: Inits units tests for fbx and glTF2 (#385)
Jul 20, 2022
36aca25
Revert bone node name change
luca-della-vedova Jul 20, 2022
54aea7c
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jul 20, 2022
590ee15
Merge remote-tracking branch 'origin/luca/vector_image_data' into luc…
luca-della-vedova Jul 22, 2022
e0b3cd6
Add PBR Emissive map
luca-della-vedova Jul 22, 2022
a0c668d
Fix style
luca-della-vedova Jul 22, 2022
d78e2dd
Minor cleanups
luca-della-vedova Jul 22, 2022
ff4c1eb
Add test for material
luca-della-vedova Jul 22, 2022
cdc14c8
Merge branch 'main' of https://github.com/ignitionrobotics/ign-common…
luca-della-vedova Jul 26, 2022
85bfe1b
Address review feedback, fix const correctness
luca-della-vedova Jul 27, 2022
9165ee9
Add test for fully featured GLB and embedded lightmap
luca-della-vedova Jul 27, 2022
25616cd
Skip test on older assimp version
luca-della-vedova Jul 27, 2022
e801652
Add test to texture values and alpha from texture
luca-della-vedova Jul 27, 2022
2f969d4
Fix color test, add mesh manager integration test
luca-della-vedova Jul 27, 2022
8224142
Fix texture splitting index calculation
luca-della-vedova Jul 27, 2022
1138935
Fix color parsing and unit test
luca-della-vedova Jul 27, 2022
44e19b1
Temporary - use gz-cmake custom branch for CI
luca-della-vedova Jul 29, 2022
5d43e70
Change to ci matching branch
luca-della-vedova Jul 29, 2022
420bc48
Remove github dependencies file
luca-della-vedova Jul 29, 2022
a7b0967
Disable narrowing conversion warning
luca-della-vedova Jul 29, 2022
acdf06d
Silence warning on Ubuntu / Mac
luca-della-vedova Jul 29, 2022
4484e5e
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jul 29, 2022
afc47c8
Introduces GZ_MESH_FORCE_ASSIMP flag (#403)
Jul 29, 2022
2c07731
Add integration test for environment variable
luca-della-vedova Jul 29, 2022
a1c0b9f
Increase test coverage
chapulina Jul 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP correct material assignments
Signed-off-by: Luca Della Vedova <luca@openrobotics.org>
luca-della-vedova committed May 13, 2022
commit bce766d313f13a12941b90b3b5067811e212a242
62 changes: 39 additions & 23 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
@@ -34,10 +34,6 @@
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags

void hello_world()
{
}

namespace ignition
{
namespace common
@@ -49,10 +45,10 @@ class AssimpLoader::Implementation
/// Convert a color from assimp implementation to Ignition common
public: ignition::math::Color ConvertColor(aiColor4D& _color);

public: MaterialPtr CreateMaterial(const aiScene* scene, unsigned mat_idx, const std::string& path);
/// Convert a transformation from assimp implementation to Ignition math
public: ignition::math::Matrix4d ConvertTransform(aiMatrix4x4& _matrix);

/// Maps assimp material index to Ignition common's material index
public: std::unordered_map<unsigned, unsigned> addedMaterialIndexes;
public: MaterialPtr CreateMaterial(const aiScene* scene, unsigned mat_idx, const std::string& path);
};

ignition::math::Color AssimpLoader::Implementation::ConvertColor(aiColor4D& _color)
@@ -61,11 +57,18 @@ ignition::math::Color AssimpLoader::Implementation::ConvertColor(aiColor4D& _col
return col;
}

ignition::math::Matrix4d AssimpLoader::Implementation::ConvertTransform(aiMatrix4x4& _sm)
{
return ignition::math::Matrix4d(
_sm.a1, _sm.a2, _sm.a3, _sm.a4,
_sm.b1, _sm.b2, _sm.b3, _sm.b4,
_sm.c1, _sm.c2, _sm.c3, _sm.c4,
_sm.d1, _sm.d2, _sm.d3, _sm.d4);
}

//////////////////////////////////////////////////
MaterialPtr AssimpLoader::Implementation::CreateMaterial(const aiScene* scene, unsigned mat_idx, const std::string& path)
{
if (addedMaterialIndexes.find(mat_idx) != addedMaterialIndexes.end())
return nullptr;
MaterialPtr mat = std::make_shared<Material>();
aiColor4D color;
igndbg << "Processing material with name " << scene->mMaterials[mat_idx]->GetName().C_Str() << std::endl;
@@ -150,6 +153,11 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
return mesh;
}
auto root_node = scene->mRootNode;
auto root_transformation = this->dataPtr->ConvertTransform(scene->mRootNode->mTransformation);
// TODO remove workaround, it seems imported assets are rotated by 90 degrees
// as documented here https://github.com/assimp/assimp/issues/849, remove workaround when fixed
// TODO find actual workaround to remove rotation
// root_transformation = root_transformation * root_transformation.Rotation();
// TODO recursive call for children?
// Add the materials first
for (unsigned mat_idx = 0; mat_idx < scene->mNumMaterials; ++mat_idx)
@@ -164,19 +172,13 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
ignmsg << "Processing mesh with " << node->mNumMeshes << " meshes" << std::endl;
for (unsigned mesh_idx = 0; mesh_idx < node->mNumMeshes; ++mesh_idx)
{
// TODO transformation with mTransformation
SubMesh subMesh;
auto assimp_mesh_idx = node->mMeshes[mesh_idx];
auto assimp_mesh = scene->mMeshes[assimp_mesh_idx];
auto sm = node->mTransformation;
ignition::math::Matrix4d trans(
sm.a1, sm.a2, sm.a3, sm.a4,
sm.b1, sm.b2, sm.b3, sm.b4,
sm.c1, sm.c2, sm.c3, sm.c4,
sm.d1, sm.d2, sm.d3, sm.d4);
auto trans = this->dataPtr->ConvertTransform(node->mTransformation);
trans = root_transformation * trans;
ignition::math::Matrix4d rot = trans;
rot.SetTranslation(ignition::math::Vector3d::Zero);
// TODO only rotation for normals, full transform for positions
// Now create the submesh
for (unsigned vertex_idx = 0; vertex_idx < assimp_mesh->mNumVertices; ++vertex_idx)
{
@@ -194,16 +196,14 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
normal.Normalize();
subMesh.AddVertex(vertex);
subMesh.AddNormal(normal);
// TODO index of vertex is very inefficient...
//subMesh.AddIndex(subMesh.IndexCount());
// Texture coordinates
// Iterate over sets of texture coordinates
int i = 0;
while(assimp_mesh->HasTextureCoords(i))
{
ignition::math::Vector3d texcoords;
texcoords.X(assimp_mesh->mTextureCoords[i][vertex_idx].x);
texcoords.Y(assimp_mesh->mTextureCoords[i][vertex_idx].y);
// TODO why do we need 1.0 - Y?
subMesh.AddTexCoordBySet(texcoords.X(), 1.0 - texcoords.Y(), i);
++i;
}
@@ -218,14 +218,30 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
subMesh.SetName(std::string(node->mName.C_Str()));

ignmsg << "Submesh " << node->mName.C_Str() << " has material index " << assimp_mesh->mMaterialIndex << std::endl;
subMesh.SetMaterialIndex(this->dataPtr->addedMaterialIndexes[assimp_mesh->mMaterialIndex]);
mesh->AddSubMesh(subMesh);
}
subMesh.SetMaterialIndex(assimp_mesh->mMaterialIndex);
mesh->AddSubMesh(std::move(subMesh));
}
}
// Process animations
ignmsg << "Processing " << scene->mNumAnimations << " animations" << std::endl;
ignmsg << "Scene has " << scene->mNumMeshes << " meshes" << std::endl;
// Iterate over meshes in scene not contained in root node
// this is a strict superset of the above that also contains animation meshes
for (unsigned mesh_idx = 0; mesh_idx < scene->mNumMeshes; ++mesh_idx)
{
// Skip if the mesh was found in the previous step
auto mesh_name = std::string(scene->mMeshes[mesh_idx]->mName.C_Str());
if (!mesh->SubMeshByName(mesh_name).expired())
continue;
auto assimp_mesh = scene->mMeshes[mesh_idx];
ignmsg << "New mesh found with name " << scene->mMeshes[mesh_idx]->mName.C_Str() << std::endl;
}
for (unsigned anim_idx = 0; anim_idx < scene->mNumAnimations; ++anim_idx)
{
auto anim = scene->mAnimations[anim_idx];
ignmsg << "Animation has " << anim->mNumMeshChannels << " mesh channels" << std::endl;
ignmsg << "Animation has " << anim->mNumChannels << " channels" << std::endl;
ignmsg << "Animation has " << anim->mNumMorphMeshChannels << " morph mesh channels" << std::endl;
// Process t
}
// Iterate over nodes and add a submesh for each