OpenScadRenderer.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. // Include own headers
  2. #include "OpenScadRenderer.hpp"
  3. // Include modules
  4. #include "PlatformSupport.hpp"
  5. // Include dependencies
  6. #include <iostream>
  7. #include <fstream>
  8. #include <filesystem>
  9. const char* openScadBase =
  10. "$fn = 100;\n"
  11. "module optiTrackPointBase(translation, rotation, length, radius) {\n"
  12. "translate(translation) rotate(rotation) cylinder(length, radius, radius, false);\n"
  13. "}\n";
  14. void OpenScadRenderer::renderOptiTrack(std::vector<OptiTrackPoint*> points) {
  15. std::ofstream scadFile;
  16. scadFile.open(std::filesystem::temp_directory_path().u8string() + fileDelimiter + "trackpointapp_export_optitrack.scad");
  17. scadFile << openScadBase;
  18. scadFile << "import(\"trackpointapp_export.3mf\");\n";
  19. for (OptiTrackPoint* point: points) {
  20. osg::Vec3 translation = point->getTranslation();
  21. osg::Vec3 rotation = point->getRotation();
  22. scadFile << "optiTrackPointBase([" << translation.x() << "," << translation.y() << "," << translation.z() << "], [" << rotation.x() << "," << rotation.y() << "," << rotation.z() << "], " << point->getLength() << ", " << point->getRadius() << ");\n";
  23. }
  24. scadFile.close();
  25. std::string command = openScadPath + " -o " + std::filesystem::temp_directory_path().u8string() + fileDelimiter + "trackpointapp_render_optitrack.3mf " + std::filesystem::temp_directory_path().u8string() + fileDelimiter + "trackpointapp_export_optitrack.scad";
  26. system(command.c_str());
  27. }