Skip to content

Commit

Permalink
Migrate to assimp 5.2.0
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <luca@openrobotics.org>
  • Loading branch information
luca-della-vedova committed May 23, 2022
1 parent 8f63b21 commit db823ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ ign_find_package(AVCODEC REQUIRED_BY av PRETTY libavcodec)
ign_find_package(AVUTIL REQUIRED_BY av PRETTY libavutil)

#------------------------------------
# Find avutil
ign_find_package(ASSIMP REQUIRED_BY graphics PRETTY assimp)
# Find assimp
ign_find_package(ASSIMP VERSION 5.2.0 REQUIRED_BY graphics PRETTY assimp)


message(STATUS "-------------------------------------------\n")
Expand Down
20 changes: 10 additions & 10 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void AssimpLoader::Implementation::RecursiveCreate(const aiScene* scene, const a
SkeletonNode *skel_node =
mesh->MeshSkeleton()->NodeByName(bone_name);
skel_node->SetInverseBindTransform(this->ConvertTransform(bone->mOffsetMatrix));
ignmsg << "Bone " << bone_name << " has " << bone->mNumWeights << " weights" << std::endl;
igndbg << "Bone " << bone_name << " has " << bone->mNumWeights << " weights" << std::endl;
for (unsigned weight_idx = 0; weight_idx < bone->mNumWeights; ++weight_idx)
{
auto vertex_weight = bone->mWeights[weight_idx];
Expand Down Expand Up @@ -163,7 +163,7 @@ void AssimpLoader::Implementation::RecursiveSkeletonCreate(const aiNode* node, S
{
// First explore this node
auto node_name = std::string(node->mName.C_Str());
ignmsg << "Exploring node " << node_name << std::endl;
//ignmsg << "Exploring node " << node_name << std::endl;
// TODO check if node or joint?
auto skel_node = new SkeletonNode(root_node, node_name, node_name, SkeletonNode::JOINT);
// Calculate transform
Expand Down Expand Up @@ -324,7 +324,6 @@ Mesh *AssimpLoader::Load(const std::string &_filename)

auto root_transformation = this->dataPtr->ConvertTransform(transform);

//root_transformation = ignition::math::Matrix4d::Identity;
// 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
// Add the materials first
Expand All @@ -347,7 +346,7 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
for (unsigned child_idx = 0; child_idx < root_node->mNumChildren; ++child_idx)
{
// Now create the meshes
// Recursive call to keep track of transforms, mesh is passed by reference and edited throughout
// Recursive call to keep track of transforms, mesh is passed by pointer and edited throughout
ignmsg << "Parsing root child " << root_node->mChildren[child_idx]->mName.C_Str() << std::endl;
this->dataPtr->RecursiveCreate(scene, root_node->mChildren[child_idx], root_transformation, mesh);
}
Expand Down Expand Up @@ -379,9 +378,10 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
ignition::math::Vector3d pos(pos_key.mValue.x, pos_key.mValue.y, pos_key.mValue.z);
ignition::math::Quaterniond quat(quat_key.mValue.w, quat_key.mValue.x, quat_key.mValue.y, quat_key.mValue.z);
ignition::math::Pose3d pose(pos, quat);
skel_anim->AddKeyFrame(chan_name, pos_key.mTime, pose);
//igndbg << "Adding animation at time " << pos_key.mTime << " with position (" << pos.X() << "," << pos.Y() << "," <<
// pos.Z() << ")" << std::endl;
// Time is in ms after 5.0.1?
skel_anim->AddKeyFrame(chan_name, pos_key.mTime / 1000.0, pose);
igndbg << "Adding animation at time " << pos_key.mTime / 1000.0 << " with position (" << pos.X() << "," << pos.Y() << "," <<
pos.Z() << ")" << std::endl;
}
}
mesh->MeshSkeleton()->AddAnimation(skel_anim);
Expand Down Expand Up @@ -409,9 +409,9 @@ void AssimpLoader::Implementation::ApplyInvBindTransform(SkeletonPtr _skeleton)
if (node->HasInvBindTransform())
{
node->SetModelTransform(node->InverseBindTransform().Inverse(), false);
igndbg << "Node " << node->Name() << " model transform is:" << std::endl << node->ModelTransform() << std::endl;
igndbg << "Parent " << node->Parent()->Name() << " transform is:" << std::endl << node->Parent()->ModelTransform() << std::endl;
igndbg << "Node " << node->Name() << " transform is:" << std::endl << node->Transform() << std::endl;
//igndbg << "Node " << node->Name() << " model transform is:" << std::endl << node->ModelTransform() << std::endl;
//igndbg << "Parent " << node->Parent()->Name() << " transform is:" << std::endl << node->Parent()->ModelTransform() << std::endl;
//igndbg << "Node " << node->Name() << " transform is:" << std::endl << node->Transform() << std::endl;
}
for (unsigned int i = 0; i < node->ChildCount(); i++)
queue.push_back(node->Child(i));
Expand Down
6 changes: 5 additions & 1 deletion graphics/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ if(USE_EXTERNAL_TINYXML2)
PRIVATE
TINYXML2::TINYXML2)

target_include_directories(${graphics_target}
PRIVATE ${ASSIMP_INCLUDE_DIRS})

# The collada exporter test uses tinyxml2, so we must link it if we're using
# an external copy. The graphics target considers tinyxml2 to be a private
# dependency, so it will not automatically get linked to this test.
Expand All @@ -49,7 +52,8 @@ else()
# directories. We do not want this to be visible to consumers of
# ignition-common.
target_include_directories(${graphics_target}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tinyxml2)
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tinyxml2
${ASSIMP_INCLUDE_DIRS})

if(TARGET UNIT_ColladaExporter_TEST)

Expand Down

0 comments on commit db823ca

Please sign in to comment.