From 562bafb1dacf3e4a76ea0bca15a96fb5fa809269 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20=C5=A0toura=C4=8D?= <525032@mail.muni.cz>
Date: Sat, 18 May 2024 23:39:18 +0200
Subject: [PATCH] fix cube north orientations

---
 src/edit/src/editor.cpp          | 8 ++++++--
 src/filein/src/module_loader.cpp | 8 ++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/edit/src/editor.cpp b/src/edit/src/editor.cpp
index 4618254..e06ab20 100644
--- a/src/edit/src/editor.cpp
+++ b/src/edit/src/editor.cpp
@@ -1017,7 +1017,9 @@ void Editor::initializeCube()
     using namespace rofi;
 
     module_type_voxel_graphs[cube] = std::make_shared<VoxelGraph>();
-    auto cube_node = Node::create();
+    const auto rot = glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, 0.0f, -1.0f)) 
+                     * glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, -1.0f, 0.0f));
+    auto cube_node = Node::create(glm::vec3(0.0f), rot);
     auto cube_voxel = module_type_voxel_graphs[cube]->addVoxel(cube_node);
     addVoxelMesh(cube_node);
     cube_node->addObject(cube_voxel);
@@ -1227,7 +1229,9 @@ void Editor::setModuleNodeHierarchyCube(voxel_graph_ptr vg)
             con_node->getParent().lock()->transferChild(con_node, body_node, true);
     }
 
-    body_node->rotateRotationQuat(glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
+    const auto rot = glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, 0.0f, -1.0f)) 
+                     * glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, -1.0f, 0.0f));
+    body_node->rotateRotationQuat(rot);
 }
 
 void Editor::setModuleNodeHierarchyUniversal(voxel_graph_ptr vg)
diff --git a/src/filein/src/module_loader.cpp b/src/filein/src/module_loader.cpp
index 1434ec4..2e4b926 100644
--- a/src/filein/src/module_loader.cpp
+++ b/src/filein/src/module_loader.cpp
@@ -844,12 +844,8 @@ std::map<uint64_t, objectbase_ptr> import_rigid_joints(voxel_graph_ptr vg,
             auto node = Node::create(voxel_side_direction * 0.5f, get_connector_face_rotation(voxel_side_direction));
 
             // adjust cube North
-            // if (node->getRotationAxisZLocal() == enum_to_vec(side::z_neg))
-            //     node->rotateRotationQuat(glm::rotation(node->getRotationAxisXLocal(), enum_to_vec(side::y_neg)));
-            // else if (node->getRotationAxisZLocal() == enum_to_vec(side::z_pos))
-            //     node->rotateRotationQuat(glm::rotation(node->getRotationAxisXLocal(), enum_to_vec(side::y_pos)));
-            // else
-            //     node->rotateRotationQuat(glm::rotation(node->getRotationAxisXLocal(), enum_to_vec(side::x_pos)));
+            if (at_voxel_side == side::x_neg || at_voxel_side == side::x_pos || at_voxel_side == side::z_pos)
+                node->rotateRotationQuat(glm::angleAxis(glm::radians(180.0f), node->getRotationAxisZLocal()));
 
             auto connector = vg->addConnector(node, connector_type::open);
             id_roficom_pairs.emplace(to, connector);
-- 
GitLab