diff --git a/src/edit/include/edit/editor.hpp b/src/edit/include/edit/editor.hpp index 1c4fd673ff3146945da5c199816f703a382841e9..72faa8f717d9decc82c26c7aba7d4c89a545b0b3 100644 --- a/src/edit/include/edit/editor.hpp +++ b/src/edit/include/edit/editor.hpp @@ -566,6 +566,8 @@ private: /* ROFIWORLD EXPORT */ void pickSpaceJoints(rofiworld_ptr rofiworld, bool automatic); + connector_ptr pickSpaceJointUniversal(const module_ptr module); + connector_ptr pickSpaceJointGeneric(const module_ptr module); }; } diff --git a/src/edit/src/editor.cpp b/src/edit/src/editor.cpp index af0332c53d437fadf35588ede27ba134d033bade..8ac6c7bc7a0578c7c27722173d423aff85b95f44 100644 --- a/src/edit/src/editor.cpp +++ b/src/edit/src/editor.cpp @@ -2866,26 +2866,17 @@ void Editor::pickSpaceJoints(rofiworld_ptr rofiworld, bool automatic) continue; std::set<module_ptr> reachable_modules; - auto module_vg = module->getParts(); - if (module_vg->getConnections().empty()) - { - const auto voxel = module_vg->getVoxels().front(); - reachable_modules = rofiworld->reachableModules(voxel); - selected_space_joints.emplace_back(voxel); - } + + connector_ptr connector = nullptr; + + if (module->getType() == "universal") + connector = pickSpaceJointUniversal(module); else - { - connector_ptr connector = nullptr; - for (const auto &con : module_vg->getConnections()) - { - if (con->getType(false) != rofi::connector_type::shared_rotation) - connector = con; - } - ASSUMPTION(connector); - - reachable_modules = rofiworld->reachableModules(connector); - selected_space_joints.emplace_back(connector); - } + connector = pickSpaceJointGeneric(module); + + reachable_modules = rofiworld->reachableModules(connector); + selected_space_joints.emplace_back(connector); + found_modules.insert(reachable_modules.begin(), reachable_modules.end()); } @@ -2893,4 +2884,42 @@ void Editor::pickSpaceJoints(rofiworld_ptr rofiworld, bool automatic) } +connector_ptr Editor::pickSpaceJointUniversal(const module_ptr module) +{ + connector_ptr connector = nullptr; + + for (const auto &[component, id] : module->getComponentIDs()) + { + if (id == 0) + { + connector = std::dynamic_pointer_cast<rofi::Connector>(component); + break; + } + } + + ASSUMPTION(connector); + return connector; +} + +connector_ptr Editor::pickSpaceJointGeneric(const module_ptr module) +{ + auto module_vg = module->getParts(); + ASSUMPTION(!module_vg->getConnections().empty()); + + connector_ptr connector = nullptr; + + for (const auto &[component, id] : module->getComponentIDs()) + { + if (id == 0) + { + connector = std::dynamic_pointer_cast<rofi::Connector>(component); + break; + } + } + + ASSUMPTION(connector); + return connector; +} + + } diff --git a/src/filein/include/filein/rofiworld_loader.hpp b/src/filein/include/filein/rofiworld_loader.hpp index 456257e1fbbc884fd4853c12899c0973b38c1825..e3c342c4cf5bd81f5ccc59c80d3e7b59e168afd9 100644 --- a/src/filein/include/filein/rofiworld_loader.hpp +++ b/src/filein/include/filein/rofiworld_loader.hpp @@ -28,7 +28,7 @@ void export_module_unknown(boost::json::array &modules_array, const module_ptr m /* EXPORT SPACEJOINTS */ void export_spaceJoints(boost::json::array &spaceJoints_array, const rofiworld_ptr rofiworld, const std::vector<objectbase_ptr> &selected_space_joints); -void export_spaceJoint(boost::json::array &spaceJoints_array, const rofiworld_ptr rofiworld, const node_ptr node, const uint64_t component_id); +void export_spaceJoint(boost::json::array &spaceJoints_array, const rofiworld_ptr rofiworld, const node_ptr node, const uint64_t component_id, const std::string &module_type); void export_spaceJoint_point(boost::json::object &spaceJoint_object, const node_ptr node); void export_spaceJoint_joint(boost::json::object &spaceJoint_object, const node_ptr node); void export_spaceJoint_joint_matrix(boost::json::object &joint_object, const node_ptr node); @@ -43,7 +43,7 @@ void export_moduleJoint_orientation(boost::json::object &moduleJoint_object, con /* IMPORT */ -std::vector<rofiworld_ptr> import_saved_configurations(); +// std::vector<rofiworld_ptr> import_saved_configurations(); rofiworld_ptr import_rofiworld(const std::filesystem::path file_path); void get_rofiworld_data(const boost::json::array &modules_array, const boost::json::array &spaceJoints_array, const boost::json::array &moduleJoints_array); diff --git a/src/filein/src/rofiworld_loader.cpp b/src/filein/src/rofiworld_loader.cpp index 7f2f47f47dcf3b67d65f5c35983abedcf8cba968..57a93fa8eaceea8b791807d7924dc0b0b06a9aaa 100644 --- a/src/filein/src/rofiworld_loader.cpp +++ b/src/filein/src/rofiworld_loader.cpp @@ -112,22 +112,18 @@ void export_spaceJoints(boost::json::array &spaceJoints_array, const rofiworld_p for (const auto &component : selected_space_joints) { - if (const auto voxel = std::dynamic_pointer_cast<Voxel>(component)) - { - auto voxel_node = voxel->getNode(); - auto voxel_id = rofiworld->getModuleWithNode(voxel_node)->getComponentID(voxel); - export_spaceJoint(spaceJoints_array, rofiworld, voxel_node, voxel_id); - } - else if (const auto connector = std::dynamic_pointer_cast<Connector>(component)) - { - auto connector_node = connector->getNode(); - auto connector_id = rofiworld->getModuleWithNode(connector_node)->getComponentID(connector); - export_spaceJoint(spaceJoints_array, rofiworld, connector_node, connector_id); - } + const auto connector = std::dynamic_pointer_cast<Connector>(component); + ASSUMPTION(connector); + auto connector_node = connector->getNode(); + const auto module = rofiworld->getModuleWithNode(connector_node); + auto connector_id = module->getComponentID(connector); + const auto module_type = module->getType(); + export_spaceJoint(spaceJoints_array, rofiworld, connector_node, connector_id, module_type); + } } -void export_spaceJoint(boost::json::array &spaceJoints_array, const rofiworld_ptr rofiworld, const node_ptr node, const uint64_t component_id) +void export_spaceJoint(boost::json::array &spaceJoints_array, const rofiworld_ptr rofiworld, const node_ptr node, const uint64_t component_id, const std::string &module_type) { boost::json::object spaceJoint_object; @@ -166,8 +162,9 @@ void export_spaceJoint_joint(boost::json::object &spaceJoint_object, const node_ void export_spaceJoint_joint_matrix(boost::json::object &joint_object, const node_ptr node) { - auto world_mat = convertToRoFICoordinates(node->getModelMatWorld()); - // auto world_mat = node->getModelMatWorld(); + auto component_coord_convert = glm::toMat4(glm::rotation(glm::vec3(0.0f, 0.0f, -1.0f), -node->getRotationAxisZWorld())); + // auto rotation_mat = convertToRoFICoordinates(component_coord_convert); + auto rotation_mat = component_coord_convert; float epsilon = 0.00001f; bool is_identity = true; @@ -175,7 +172,7 @@ void export_spaceJoint_joint_matrix(boost::json::object &joint_object, const nod { auto id_column = glm::vec4(0.0f); id_column[i] = 1.0f; - if (!glm::all(glm::epsilonEqual(world_mat[i], id_column, epsilon))) + if (!glm::all(glm::epsilonEqual(rotation_mat[i], id_column, epsilon))) is_identity = false; } if (is_identity) @@ -189,10 +186,10 @@ void export_spaceJoint_joint_matrix(boost::json::object &joint_object, const nod for (int i = 0; i < 4; ++i) { boost::json::array row_array; - row_array.emplace_back(glm::row(world_mat, i).x); - row_array.emplace_back(glm::row(world_mat, i).y); - row_array.emplace_back(glm::row(world_mat, i).z); - row_array.emplace_back(glm::row(world_mat, i).w); + row_array.emplace_back(glm::row(rotation_mat, i).x); + row_array.emplace_back(glm::row(rotation_mat, i).y); + row_array.emplace_back(glm::row(rotation_mat, i).z); + row_array.emplace_back(glm::row(rotation_mat, i).w); sourceToDestination_array.emplace_back(row_array); } @@ -282,23 +279,23 @@ void export_moduleJoint_orientation(boost::json::object &moduleJoint_object, con moduleJoint_object.emplace("orientation", orientation); } -std::vector<rofiworld_ptr> import_saved_configurations() -{ - const std::filesystem::path rofiworlds_directory = "./data/rofi/rofiworlds"; - std::vector<rofiworld_ptr> imported_configurations; +// std::vector<rofiworld_ptr> import_saved_configurations() +// { +// const std::filesystem::path rofiworlds_directory = "./data/rofi/rofiworlds"; +// std::vector<rofiworld_ptr> imported_configurations; - for (auto const& dir_entry : std::filesystem::directory_iterator{rofiworlds_directory}) - { - if (dir_entry.path().filename().string() == "." || dir_entry.path().filename().string() == "..") - continue; +// for (auto const& dir_entry : std::filesystem::directory_iterator{rofiworlds_directory}) +// { +// if (dir_entry.path().filename().string() == "." || dir_entry.path().filename().string() == "..") +// continue; - const auto rofiworld = import_rofiworld(dir_entry); - if (rofiworld) - imported_configurations.emplace_back(rofiworld); - } +// const auto rofiworld = import_rofiworld(dir_entry); +// if (rofiworld) +// imported_configurations.emplace_back(rofiworld); +// } - return imported_configurations; -} +// return imported_configurations; +// } rofiworld_ptr import_rofiworld(const std::filesystem::path file_path) { @@ -307,6 +304,8 @@ rofiworld_ptr import_rofiworld(const std::filesystem::path file_path) boost::json::array moduleJoints_array; get_rofiworld_data(modules_array, spaceJoints_array, moduleJoints_array); + + return nullptr; } void get_rofiworld_data(const boost::json::array &modules_array, const boost::json::array &spaceJoints_array, const boost::json::array &moduleJoints_array) diff --git a/src/rofi/include/rofi/module.hpp b/src/rofi/include/rofi/module.hpp index 475d39d3211dd043cb415a153fb03a40c9df4fd8..1006d7bb230dea5eba86197567673de79ca0a1dc 100644 --- a/src/rofi/include/rofi/module.hpp +++ b/src/rofi/include/rofi/module.hpp @@ -30,7 +30,10 @@ class Module void makeNodeTree(); void setConnectorDocks(); + void setConnectorDocksUniversal(); void setComponentIDs(); + void setComponentIDsUniversal(); + void setComponentIDsGeneric(); Module(const Module &other); Module(const Module &&other); diff --git a/src/rofi/src/module.cpp b/src/rofi/src/module.cpp index ac26ba56e039452f0be64126d731fdf730815350..3e9ae9578b4f921a7dc2360401616ce80f6cd983 100644 --- a/src/rofi/src/module.cpp +++ b/src/rofi/src/module.cpp @@ -13,9 +13,12 @@ void Module::makeNodeTree() void Module::setConnectorDocks() // TO DO: change if connector placement gets changed { - if (type != "universal") - return; + if (type == "universal") + setConnectorDocksUniversal(); +} +void Module::setConnectorDocksUniversal() +{ using enum side; std::string dock; auto a_pos = glm::vec3(0.0f); @@ -46,6 +49,64 @@ void Module::setConnectorDocks() // TO DO: change if connector placement gets ch } void Module::setComponentIDs() +{ + component_ids.clear(); + + if (type == "universal") + setComponentIDsUniversal(); + else + setComponentIDsGeneric(); +} + +void Module::setComponentIDsUniversal() +{ + ASSUMPTION(connector_docks.size() == 6); + + // RoFICoMs + for (const auto &[connector, dock] : connector_docks) + { + if (dock == "A-X") + component_ids.emplace(connector, 0); + else if (dock == "A+X") + component_ids.emplace(connector, 1); + else if (dock == "A-Z") + component_ids.emplace(connector, 2); + else if (dock == "B-X") + component_ids.emplace(connector, 3); + else if (dock == "B+X") + component_ids.emplace(connector, 4); + else if (dock == "B-Z") + component_ids.emplace(connector, 5); + } + + // Bodies + auto a_pos = glm::vec3(0.0f); + voxel_ptr a_voxel; + + for (const auto &voxel : parts->getVoxels()) + { + if (voxel->getNode()->getPositionLocal() == a_pos) + { + component_ids.emplace(voxel, 8); + a_voxel = voxel; + } + else + component_ids.emplace(voxel, 9); + } + + // Shoes // Shoes do not get placed into the map as the key - connector is already placed as roficom + // for (const auto &connector : parts->getConnections()) + // { + // if (auto rot_con = std::dynamic_pointer_cast<RotationConnector>(connector); + // rot_con && rot_con->isHead()) + // { + // component_ids.emplace(connector, connector->getConnection().first.lock() == a_voxel ? 6 : 7); + // } + // } + +} + +void Module::setComponentIDsGeneric() { for (const auto connector : parts->getConnections()) { @@ -71,8 +132,8 @@ Module::Module(const Module &other) parts = VoxelGraph::copy(other.parts, node->getChildren()); name = other.name; type = other.type; - setComponentIDs(); setConnectorDocks(); + setComponentIDs(); } Module::Module(const Module &&other) { @@ -80,8 +141,8 @@ Module::Module(const Module &&other) parts = std::move(other.parts); name = std::move(other.name); type = std::move(other.type); - setComponentIDs(); setConnectorDocks(); + setComponentIDs(); } Module& Module::operator=(const Module &other) { @@ -91,6 +152,7 @@ Module& Module::operator=(const Module &other) type = other.type; component_ids = other.component_ids; setConnectorDocks(); + setComponentIDs(); return *this; } @@ -100,8 +162,8 @@ Module& Module::operator=(const Module &&other) parts = std::move(other.parts); name = std::move(other.name); type = std::move(other.type); - setComponentIDs(); setConnectorDocks(); + setComponentIDs(); return *this; } @@ -112,6 +174,7 @@ Module::Module(voxel_graph_ptr _parts, std::string &_name, std::string &_type, s ASSUMPTION(!_parts->getVoxels().empty() || !_parts->getConnections().empty()); makeNodeTree(); setConnectorDocks(); + setComponentIDs(); } Module::Module(voxel_graph_ptr _parts, std::string &&_name, std::string &&_type, std::map<objectbase_ptr, uint64_t> &&_component_ids) @@ -120,6 +183,7 @@ Module::Module(voxel_graph_ptr _parts, std::string &&_name, std::string &&_type, ASSUMPTION(!_parts->getVoxels().empty() || !_parts->getConnections().empty()); makeNodeTree(); setConnectorDocks(); + setComponentIDs(); } module_ptr Module::copy(const module_ptr other_module)