OpenScadRenderer.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Include own headers
  2. #include "OpenScadRenderer.hpp"
  3. // Include dependencies
  4. #include <iostream>
  5. #include <fstream>
  6. #include <sstream>
  7. const char* openScadBase =
  8. "$fn = 100;\n"
  9. "module optiTrackPointBase(translation, rotation) {\n"
  10. "translate(translation) rotate(rotation) cylinder(10, 1, 1, false);\n"
  11. "}\n";
  12. #if __APPLE__
  13. std::string openScadPath = "/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD";
  14. #elif __unix__
  15. std::string openScadPath = "openscad";
  16. #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(_WIN64)
  17. // Currently unsupported
  18. #endif
  19. void OpenScadRenderer::render(std::vector<TrackPoint*> points) {
  20. std::ofstream scadFile;
  21. scadFile.open("/tmp/output.scad");
  22. scadFile << openScadBase;
  23. scadFile << "import(\"testbutton.stl\");\n";
  24. for (TrackPoint* point: points) {
  25. osg::Vec3 translation = point->getTranslation();
  26. osg::Vec3 rotation = point->getRotation();
  27. scadFile << "optiTrackPointBase([" << translation.x() << "," << translation.y() << "," << translation.z() << "], [" << rotation.x() << "," << rotation.y() << "," << rotation.z() << "]);\n";
  28. }
  29. scadFile.close();
  30. //std::string command = openScadPath + " -o " + std::filesystem::temp_directory_path() + "/output.3mf " + std::filesystem::temp_directory_path() + "/output.scad";
  31. //system(command);
  32. }