From 7c160ae6819f94ed52173fde4e35a03e7d2f5bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 17 Dec 2024 21:09:54 +0100 Subject: [PATCH] Formatter wants to say something?? --- src/esp/bindings/CMakeLists.txt | 4 +-- src/utils/datatool/CMakeLists.txt | 4 +-- src/utils/datatool/SceneLoader.cpp | 54 +++++++++++++++++++----------- src/utils/viewer/viewer.cpp | 23 ++++++------- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/esp/bindings/CMakeLists.txt b/src/esp/bindings/CMakeLists.txt index 71a7e8c122..4bb94d528e 100644 --- a/src/esp/bindings/CMakeLists.txt +++ b/src/esp/bindings/CMakeLists.txt @@ -54,9 +54,7 @@ target_link_libraries( PUBLIC habitat_sim ) if(BUILD_ASSIMP_SUPPORT) - target_link_libraries( - habitat_sim_bindings PUBLIC MagnumPlugins::AssimpImporter - ) + target_link_libraries(habitat_sim_bindings PUBLIC MagnumPlugins::AssimpImporter) endif() if(BUILD_WITH_AUDIO) diff --git a/src/utils/datatool/CMakeLists.txt b/src/utils/datatool/CMakeLists.txt index 2db9c943ad..d9579658a9 100644 --- a/src/utils/datatool/CMakeLists.txt +++ b/src/utils/datatool/CMakeLists.txt @@ -34,7 +34,5 @@ target_link_libraries( MagnumPlugins::UfbxImporter ) if(BUILD_ASSIMP_SUPPORT) - target_link_libraries( - datatool PUBLIC MagnumPlugins::AssimpImporter - ) + target_link_libraries(datatool PUBLIC MagnumPlugins::AssimpImporter) endif() diff --git a/src/utils/datatool/SceneLoader.cpp b/src/utils/datatool/SceneLoader.cpp index ce54bbf3fa..a5c001ca40 100644 --- a/src/utils/datatool/SceneLoader.cpp +++ b/src/utils/datatool/SceneLoader.cpp @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include namespace Cr = Corrade; namespace Mn = Magnum; @@ -44,9 +44,10 @@ SceneLoader::SceneLoader() MeshData SceneLoader::load(const AssetInfo& info) { MeshData mesh; - Cr::Containers::Pointer importer = importerManager_.loadAndInstantiate("AnySceneImporter"); + Cr::Containers::Pointer importer = + importerManager_.loadAndInstantiate("AnySceneImporter"); ESP_CHECK(importer && importer->openFile(info.filepath), - "Error opening" << info.filepath); + "Error opening" << info.filepath); if (info.type == metadata::attributes::AssetType::InstanceMesh) { // dummy colormap @@ -74,8 +75,9 @@ MeshData SceneLoader::load(const AssetInfo& info) { /* Get all meshes */ Cr::Containers::Array meshes; Cr::Containers::Optional meshData; - for(Mn::UnsignedInt i = 0; i != importer->meshCount(); ++i) { - Cr::Containers::Optional meshData = importer->mesh(i); + for (Mn::UnsignedInt i = 0; i != importer->meshCount(); ++i) { + Cr::Containers::Optional meshData = + importer->mesh(i); ESP_CHECK(meshData, "Error loading mesh data from" << info.filepath); arrayAppend(meshes, *std::move(meshData)); } @@ -84,44 +86,58 @@ MeshData SceneLoader::load(const AssetInfo& info) { Cr::Containers::Optional scene = importer->scene(0); ESP_CHECK(scene, "Error loading scene data from" << info.filepath); - Cr::Containers::Array>> meshesMaterials = scene->meshesMaterialsAsArray(); + Cr::Containers::Array>> + meshesMaterials = scene->meshesMaterialsAsArray(); /* Add an extra transform to align to habitat's gravity. Keeping the original Eigen expression just to avoid some silly error, worthy of a future cleanup. */ const quatf alignSceneToEspGravityEigen = quatf::FromTwoVectors(info.frame.gravity(), esp::geo::ESP_GRAVITY); - const Mn::Matrix4 alignSceneToEspGravity = Mn::Matrix4::from(Mn::Quaternion{alignSceneToEspGravityEigen}.toMatrix(), {}); - Cr::Containers::Array transformations = Mn::SceneTools::absoluteFieldTransformations3D(*scene, Mn::Trade::SceneField::Mesh, alignSceneToEspGravity); + const Mn::Matrix4 alignSceneToEspGravity = Mn::Matrix4::from( + Mn::Quaternion{alignSceneToEspGravityEigen}.toMatrix(), {}); + Cr::Containers::Array transformations = + Mn::SceneTools::absoluteFieldTransformations3D( + *scene, Mn::Trade::SceneField::Mesh, alignSceneToEspGravity); /* Apply those transforms to meshes, concatenate them all together */ Cr::Containers::Array flattenedMeshes; - for(std::size_t i = 0; i != meshesMaterials.size(); ++i) { - arrayAppend(flattenedMeshes, Mn::MeshTools::transform3D( - meshes[meshesMaterials[i].second().first()], transformations[i])); + for (std::size_t i = 0; i != meshesMaterials.size(); ++i) { + arrayAppend( + flattenedMeshes, + Mn::MeshTools::transform3D( + meshes[meshesMaterials[i].second().first()], transformations[i])); } - Mn::Trade::MeshData concatenated = Mn::MeshTools::concatenate(flattenedMeshes); + Mn::Trade::MeshData concatenated = + Mn::MeshTools::concatenate(flattenedMeshes); /* Extract data from the nice and tidy Magnum MeshData into a bunch of STL vectors, worthy of a future cleanup as well */ { mesh.vbo.resize(concatenated.vertexCount()); - concatenated.positions3DInto(Cr::Containers::arrayCast(Cr::Containers::arrayView(mesh.vbo))); + concatenated.positions3DInto(Cr::Containers::arrayCast( + Cr::Containers::arrayView(mesh.vbo))); } - if(concatenated.hasAttribute(Mn::Trade::MeshAttribute::Normal)) { + if (concatenated.hasAttribute(Mn::Trade::MeshAttribute::Normal)) { mesh.nbo.resize(concatenated.vertexCount()); - concatenated.normalsInto(Cr::Containers::arrayCast(Cr::Containers::arrayView(mesh.nbo))); + concatenated.normalsInto(Cr::Containers::arrayCast( + Cr::Containers::arrayView(mesh.nbo))); } - if(concatenated.hasAttribute(Mn::Trade::MeshAttribute::TextureCoordinates)) { + if (concatenated.hasAttribute( + Mn::Trade::MeshAttribute::TextureCoordinates)) { mesh.tbo.resize(concatenated.vertexCount()); - concatenated.textureCoordinates2DInto(Cr::Containers::arrayCast(Cr::Containers::arrayView(mesh.tbo))); + concatenated.textureCoordinates2DInto( + Cr::Containers::arrayCast( + Cr::Containers::arrayView(mesh.tbo))); } - if(concatenated.hasAttribute(Mn::Trade::MeshAttribute::Color)) { + if (concatenated.hasAttribute(Mn::Trade::MeshAttribute::Color)) { mesh.cbo.resize(concatenated.vertexCount()); /* The colors are generally four-component, copy just the first 3 components */ Cr::Containers::Array colors = concatenated.colorsAsArray(); Cr::Utility::copy(stridedArrayView(colors).slice(&Mn::Color4::rgb), - Cr::Containers::arrayCast(Cr::Containers::arrayView(mesh.cbo))); + Cr::Containers::arrayCast( + Cr::Containers::arrayView(mesh.cbo))); } } diff --git a/src/utils/viewer/viewer.cpp b/src/utils/viewer/viewer.cpp index cc5b1a55c3..db94fec6a8 100644 --- a/src/utils/viewer/viewer.cpp +++ b/src/utils/viewer/viewer.cpp @@ -208,12 +208,11 @@ class Viewer : public Mn::Platform::Application { private: // Keys for moving/looking are recorded according to whether they are // currently being pressed - std::map keysPressed = { - {Key::Left, false}, {Key::Right, false}, - {Key::Up, false}, {Key::Down, false}, - {Key::A, false}, {Key::D, false}, - {Key::S, false}, {Key::W, false}, - {Key::X, false}, {Key::Z, false}}; + std::map keysPressed = {{Key::Left, false}, {Key::Right, false}, + {Key::Up, false}, {Key::Down, false}, + {Key::A, false}, {Key::D, false}, + {Key::S, false}, {Key::W, false}, + {Key::X, false}, {Key::Z, false}}; MouseInteractionMode mouseInteractionMode = LOOK; @@ -1901,8 +1900,8 @@ void Viewer::pointerPressEvent(PointerEvent& event) { // Read the object Id - takes unscaled mouse position, and scales it in // objectPicker - unsigned int pickedObject = - objectPickingHelper_->getObjectId(Mn::Vector2i{event.position()}, windowSize()); + unsigned int pickedObject = objectPickingHelper_->getObjectId( + Mn::Vector2i{event.position()}, windowSize()); // if an object is selected, create a visualizer createPickedObjectVisualizer(pickedObject); @@ -2174,9 +2173,8 @@ void Viewer::keyPressEvent(KeyEvent& event) { setSceneInstanceFromListAndShow(curSceneInstanceIDX_); } else { ESP_DEBUG() << "Cycling to" - << ((event.modifiers() & Modifier::Shift) - ? "previous" - : "next") + << ((event.modifiers() & Modifier::Shift) ? "previous" + : "next") << "SceneInstance"; setSceneInstanceFromListAndShow(getNextSceneInstanceIDX( (event.modifiers() & Modifier::Shift) ? -1 : 1)); @@ -2330,8 +2328,7 @@ void Viewer::keyPressEvent(KeyEvent& event) { // add an ArticulatedObject from provided filepath std::string ArtObjConfigFilepath; - if (event.modifiers() & Modifier::Shift && - !cachedAOConfig_.empty()) { + if (event.modifiers() & Modifier::Shift && !cachedAOConfig_.empty()) { // quick-reload the most recently loaded URDF ESP_WARNING() << "Articulated Object config quick-reload: " << cachedAOConfig_;