From 1c0d030b9564eca8945bd8b1bad6a9a156a3d35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0toura=C4=8D?= <525032@mail.muni.cz> Date: Tue, 21 May 2024 20:03:27 +0200 Subject: [PATCH] fix import spaceJoint rotation, change pad has padboard in 0, 0, 0 now --- src/edit/src/editor.cpp | 4 ++-- src/filein/src/module_loader.cpp | 4 ++-- src/filein/src/rofiworld_loader.cpp | 21 ++++++++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/edit/src/editor.cpp b/src/edit/src/editor.cpp index b339c03..893e7ed 100644 --- a/src/edit/src/editor.cpp +++ b/src/edit/src/editor.cpp @@ -1197,13 +1197,13 @@ void Editor::generatePad(std::size_t &width, std::size_t &height) float x_pos = static_cast<float>(x); float y_pos = static_cast<float>(y); - auto open_con_node = Node::create(glm::vec3(x_pos, y_pos, 0.0f), get_connector_face_rotation(glm::vec3(0.0f, 0.0f, -1.0f))); + auto open_con_node = Node::create(glm::vec3(x_pos, y_pos, -0.5f), get_connector_face_rotation(glm::vec3(0.0f, 0.0f, -1.0f))); open_con_node->rotateRotationQuat(glm::rotation(open_con_node->getRotationAxisXLocal(), glm::vec3(0.0f, 1.0f, 0.0f))); auto open_connector = module_type_voxel_graphs[pad]->addConnector(open_con_node, connector_type::open); addConnectorMesh(open_con_node, connector_type::fixed); open_con_node->addObject(open_connector); - auto pad_board_node = Node::create(glm::vec3(x_pos, y_pos, 0.5f), glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f))); + auto pad_board_node = Node::create(glm::vec3(x_pos, y_pos, 0.0f), glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f))); auto pad_board = module_type_voxel_graphs[pad]->addPadBoard(pad_board_node); scene->addMesh(pad_board_node, pad_board_mesh); pad_board_node->addObject(pad_board); diff --git a/src/filein/src/module_loader.cpp b/src/filein/src/module_loader.cpp index af1b500..829c38f 100644 --- a/src/filein/src/module_loader.cpp +++ b/src/filein/src/module_loader.cpp @@ -747,11 +747,11 @@ voxel_graph_ptr import_pad(const boost::json::array &components_array, const boo float x_pos = static_cast<float>(x); float y_pos = static_cast<float>(y); - auto open_con_node = Node::create(glm::vec3(x_pos, y_pos, 0.0f), get_connector_face_rotation(glm::vec3(0.0f, 0.0f, -1.0f))); + auto open_con_node = Node::create(glm::vec3(x_pos, y_pos, -0.5f), get_connector_face_rotation(glm::vec3(0.0f, 0.0f, -1.0f))); open_con_node->rotateRotationQuat(glm::rotation(open_con_node->getRotationAxisXLocal(), glm::vec3(0.0f, 1.0f, 0.0f))); auto open_connector = vg->addConnector(open_con_node, connector_type::open); - auto pad_board_node = Node::create(glm::vec3(x_pos, y_pos, 0.5f), glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f))); + auto pad_board_node = Node::create(glm::vec3(x_pos, y_pos, 0.0f), glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f))); auto pad_board = vg->addPadBoard(pad_board_node); vg->join(open_connector, pad_board, enum_to_vec(side::y_pos)); diff --git a/src/filein/src/rofiworld_loader.cpp b/src/filein/src/rofiworld_loader.cpp index 060e3c8..f0b9809 100644 --- a/src/filein/src/rofiworld_loader.cpp +++ b/src/filein/src/rofiworld_loader.cpp @@ -427,12 +427,12 @@ module_ptr import_pad(const uint64_t width, const uint64_t height) float x_pos = static_cast<float>(x); float y_pos = static_cast<float>(y); - auto open_con_node = Node::create(glm::vec3(x_pos, y_pos, 0.0f), get_connector_face_rotation(glm::vec3(0.0f, 0.0f, -1.0f))); + auto open_con_node = Node::create(glm::vec3(x_pos, y_pos, -0.5f), get_connector_face_rotation(glm::vec3(0.0f, 0.0f, -1.0f))); open_con_node->rotateRotationQuat(glm::rotation(open_con_node->getRotationAxisXLocal(), glm::vec3(0.0f, 1.0f, 0.0f))); auto open_connector = vg->addConnector(open_con_node, connector_type::open); component_ids.emplace(open_connector, id_counter); - auto pad_board_node = Node::create(glm::vec3(x_pos, y_pos, 0.5f), glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f))); + auto pad_board_node = Node::create(glm::vec3(x_pos, y_pos, 0.0f), glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f))); auto pad_board = vg->addPadBoard(pad_board_node); vg->join(open_connector, pad_board, enum_to_vec(side::y_pos)); @@ -503,12 +503,19 @@ void import_spaceJoint_joint(rofiworld_ptr rofiworld, const module_ptr module, c const auto editor_rotation_mat = convert_to_editor_import_coordinates(rofi_rotation_mat); - // TO DO rotate somehow + const auto root_connector = std::dynamic_pointer_cast<rofi::Connector>(module->getComponentByID(0)); + ASSUMPTION(root_connector); - // const auto root_connector = std::dynamic_pointer_cast<rofi::Connector>(module->getComponentByID(0)); - // ASSUMPTION(root_connector); - // rofiworld->rebuildNodeTree(module, root_connector->getNode()); - // root_connector->getNode()->setRotationQuat(editor_rotation_mat); + auto node = root_connector->getNode(); + glm::mat4 mat = editor_rotation_mat; + while (!node->getParent().expired()) + { + mat = mat * glm::inverse(node->getModelMatLocal()); + node = node->getParent().lock(); + } + + rofiworld->rebuildNodeTree(module, module->getNode()); + module->getNode()->setRotationQuat(mat); } -- GitLab