ProjectStore.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Include own headers
  2. #include "ProjectStore.hpp"
  3. // Include modules
  4. #include "MainWindow.hpp"
  5. #include "StringBasics.hpp"
  6. #include "lib3mf_implicit.hpp"
  7. #include <typeinfo>
  8. #include <iostream>
  9. ProjectStore::ProjectStore() {
  10. projectLoaded = false;
  11. //load3mfLib();
  12. }
  13. ProjectStore::ProjectStore(std::string projectFile) {
  14. }
  15. ProjectStore::~ProjectStore() {
  16. }
  17. void ProjectStore::load3mfLib() {
  18. //_wrapper = Lib3MF::CWrapper::loadLibrary();
  19. }
  20. void ProjectStore::loadMesh(std::string meshFile) {
  21. if (StringBasics::endsWithCaseInsensitive(meshFile, ".STL")) {
  22. printf("Currently unsupported.\n");
  23. } else if (StringBasics::endsWithCaseInsensitive(meshFile, ".3MF")) {
  24. Lib3MF::PWrapper _wrapper = Lib3MF::CWrapper::loadLibrary();
  25. Lib3MF::PModel _project = _wrapper->CreateModel();
  26. Lib3MF::PReader reader = _project->QueryReader("3mf");
  27. reader->ReadFromFile(meshFile);
  28. Lib3MF::PMeshObjectIterator meshIterator = _project->GetMeshObjects();
  29. if (meshIterator->Count() != 1) {
  30. printf("Not 1 mesh: %d\n", meshIterator->Count());
  31. }
  32. meshIterator->MoveNext();
  33. Lib3MF::PMeshObject mesh = meshIterator->GetCurrentMeshObject();
  34. std::vector<Lib3MF::sPosition> verticesBuffer;
  35. mesh->GetVertices(verticesBuffer);
  36. Lib3MF_uint64 vertex_count = mesh->GetVertexCount();
  37. Lib3MF_uint64 triangle_count = mesh->GetTriangleCount();
  38. for (Lib3MF_uint64 idx = 0; idx < triangle_count; ++idx) {
  39. Lib3MF::sTriangle triangle = mesh->GetTriangle(idx);
  40. Lib3MF::sPosition vertex1, vertex2, vertex3;
  41. vertex1 = mesh->GetVertex(triangle.m_Indices[0]);
  42. vertex2 = mesh->GetVertex(triangle.m_Indices[1]);
  43. vertex3 = mesh->GetVertex(triangle.m_Indices[2]);
  44. //p->append_poly();
  45. //p->append_vertex(vertex1.m_Coordinates[0], vertex1.m_Coordinates[1], vertex1.m_Coordinates[2]);
  46. //p->append_vertex(vertex2.m_Coordinates[0], vertex2.m_Coordinates[1], vertex2.m_Coordinates[2]);
  47. //p->append_vertex(vertex3.m_Coordinates[0], vertex3.m_Coordinates[1], vertex3.m_Coordinates[2]);
  48. printf("%f %f %f\n", vertex1.m_Coordinates[0], vertex1.m_Coordinates[1], vertex1.m_Coordinates[2]);
  49. printf("%f %f %f\n", vertex2.m_Coordinates[0], vertex2.m_Coordinates[1], vertex2.m_Coordinates[2]);
  50. printf("%f %f %f\n", vertex3.m_Coordinates[0], vertex3.m_Coordinates[1], vertex3.m_Coordinates[2]);
  51. }
  52. /*for (const Lib3MF::sPosition vertex: verticesBuffer) {
  53. std::cout << typeid(vertex).name() << std::endl;
  54. std::cout << typeid(vertex.m_Coordinates).name() << std::endl;
  55. std::cout << typeid(vertex.m_Coordinates[0]).name() << std::endl;
  56. printf("%f %f %f\n", (float)vertex.m_Coordinates[0], (float)vertex.m_Coordinates[1], (float)vertex.m_Coordinates[2]);
  57. }*/
  58. std::vector<Lib3MF::sTriangle> triangleBuffer;
  59. mesh->GetTriangleIndices(triangleBuffer);
  60. MainWindow* mainWindow = MainWindow::getInstance();
  61. mainWindow->getOsgWidget()->renderBaseMesh(verticesBuffer, triangleBuffer);
  62. printf("Done\n");
  63. } else {
  64. printf("Unsupported file type.\n"); // TODO: Show popup
  65. }
  66. }