Skip to content

Commit 2ef04d4

Browse files
authored
Handle glTF Y-Up frame convention on mesh load (#1482)
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 72813d1 commit 2ef04d4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rviz_rendering/src/rviz_rendering/mesh_loader_helpers/assimp_loader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ Ogre::MeshPtr AssimpLoader::meshFromAssimpScene(const std::string & name, const
209209

210210
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(name, ROS_PACKAGE_NAME);
211211

212+
const std::string ext = std::filesystem::path(name).extension().string();
213+
if (ext == ".gltf" || ext == ".glb" || ext == ".vrm") {
214+
// Transform mesh from glTF Y-Up space to ROS Z-Up space
215+
// by applying a 90 degree rotation about the X-axis,
216+
// effectively going from (x, y, z) to (x, -z, y)
217+
aiMatrix4x4 transform;
218+
aiMatrix4x4::RotationX(AI_MATH_HALF_PI, transform);
219+
scene->mRootNode->mTransformation = scene->mRootNode->mTransformation * transform;
220+
}
221+
212222
Ogre::AxisAlignedBox axis_aligned_box(Ogre::AxisAlignedBox::EXTENT_NULL);
213223
float radius = 0.0f;
214224
buildMesh(scene, scene->mRootNode, mesh, axis_aligned_box, radius, material_table);

0 commit comments

Comments
 (0)