|
@@ -5,14 +5,12 @@
|
|
|
#include "MainWindow.hpp"
|
|
|
#include "StringBasics.hpp"
|
|
|
|
|
|
-#include "lib3mf_implicit.hpp"
|
|
|
-
|
|
|
#include <typeinfo>
|
|
|
#include <iostream>
|
|
|
|
|
|
ProjectStore::ProjectStore() {
|
|
|
projectLoaded = false;
|
|
|
-
|
|
|
+ load3mfLib();
|
|
|
}
|
|
|
|
|
|
ProjectStore::ProjectStore(std::string projectFile) {
|
|
@@ -23,59 +21,65 @@ ProjectStore::~ProjectStore() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-void ProjectStore::load3mfLib() {
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
void ProjectStore::loadMesh(std::string meshFile) {
|
|
|
if (StringBasics::endsWithCaseInsensitive(meshFile, ".STL")) {
|
|
|
printf("Currently unsupported.\n");
|
|
|
} else if (StringBasics::endsWithCaseInsensitive(meshFile, ".3MF")) {
|
|
|
- Lib3MF::PWrapper _wrapper = Lib3MF::CWrapper::loadLibrary();
|
|
|
- Lib3MF::PModel _project = _wrapper->CreateModel();
|
|
|
+
|
|
|
+ _project = _wrapper->CreateModel();
|
|
|
+
|
|
|
Lib3MF::PReader reader = _project->QueryReader("3mf");
|
|
|
reader->ReadFromFile(meshFile);
|
|
|
+
|
|
|
Lib3MF::PMeshObjectIterator meshIterator = _project->GetMeshObjects();
|
|
|
+
|
|
|
if (meshIterator->Count() != 1) {
|
|
|
- printf("Not 1 mesh: %d\n", meshIterator->Count());
|
|
|
+
|
|
|
+ printf("Not 1 mesh: %llu\n", meshIterator->Count());
|
|
|
+ return;
|
|
|
}
|
|
|
meshIterator->MoveNext();
|
|
|
Lib3MF::PMeshObject mesh = meshIterator->GetCurrentMeshObject();
|
|
|
+
|
|
|
std::vector<Lib3MF::sPosition> verticesBuffer;
|
|
|
mesh->GetVertices(verticesBuffer);
|
|
|
-
|
|
|
- Lib3MF_uint64 vertex_count = mesh->GetVertexCount();
|
|
|
- Lib3MF_uint64 triangle_count = mesh->GetTriangleCount();
|
|
|
- for (Lib3MF_uint64 idx = 0; idx < triangle_count; ++idx) {
|
|
|
- Lib3MF::sTriangle triangle = mesh->GetTriangle(idx);
|
|
|
- Lib3MF::sPosition vertex1, vertex2, vertex3;
|
|
|
-
|
|
|
- vertex1 = mesh->GetVertex(triangle.m_Indices[0]);
|
|
|
- vertex2 = mesh->GetVertex(triangle.m_Indices[1]);
|
|
|
- vertex3 = mesh->GetVertex(triangle.m_Indices[2]);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- printf("%f %f %f\n", vertex1.m_Coordinates[0], vertex1.m_Coordinates[1], vertex1.m_Coordinates[2]);
|
|
|
- printf("%f %f %f\n", vertex2.m_Coordinates[0], vertex2.m_Coordinates[1], vertex2.m_Coordinates[2]);
|
|
|
- printf("%f %f %f\n", vertex3.m_Coordinates[0], vertex3.m_Coordinates[1], vertex3.m_Coordinates[2]);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- std::cout << typeid(vertex).name() << std::endl;
|
|
|
- std::cout << typeid(vertex.m_Coordinates).name() << std::endl;
|
|
|
- std::cout << typeid(vertex.m_Coordinates[0]).name() << std::endl;
|
|
|
- printf("%f %f %f\n", (float)vertex.m_Coordinates[0], (float)vertex.m_Coordinates[1], (float)vertex.m_Coordinates[2]);
|
|
|
- }*/
|
|
|
std::vector<Lib3MF::sTriangle> triangleBuffer;
|
|
|
mesh->GetTriangleIndices(triangleBuffer);
|
|
|
- MainWindow* mainWindow = MainWindow::getInstance();
|
|
|
- mainWindow->getOsgWidget()->renderBaseMesh(verticesBuffer, triangleBuffer);
|
|
|
- printf("Done\n");
|
|
|
+ render3MFMesh(verticesBuffer, triangleBuffer);
|
|
|
} else {
|
|
|
- printf("Unsupported file type.\n");
|
|
|
+
|
|
|
+ printf("Unsupported file type.\n");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectStore::load3mfLib() {
|
|
|
+ _wrapper = Lib3MF::CWrapper::loadLibrary();
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectStore::render3MFMesh(const std::vector<Lib3MF::sPosition> verticesBuffer, const std::vector<Lib3MF::sTriangle> triangleBuffer) {
|
|
|
+
|
|
|
+ osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
|
|
+ osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
|
|
|
+
|
|
|
+ for (const Lib3MF::sTriangle triangle: triangleBuffer) {
|
|
|
+
|
|
|
+ osg::Vec3 vertex[3] = {};
|
|
|
+ for (char i = 0; i < 3; i++) {
|
|
|
+ vertex[i] = osg::Vec3(verticesBuffer[triangle.m_Indices[i]].m_Coordinates[0], verticesBuffer[triangle.m_Indices[i]].m_Coordinates[1], verticesBuffer[triangle.m_Indices[i]].m_Coordinates[2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ osg::Vec3 edgeOne = vertex[1].operator-(vertex[0]);
|
|
|
+ osg::Vec3 edgeTwo = vertex[2].operator-(vertex[0]);
|
|
|
+ osg::Vec3 normal = edgeOne.operator^(edgeTwo);
|
|
|
+ normal.normalize();
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ printf("%f %f %f\n", vertex[i].x(), vertex[i].y(), vertex[i].z());
|
|
|
+ vertices->push_back(vertex[i]);
|
|
|
+ normals->push_back(normal);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ MainWindow* mainWindow = MainWindow::getInstance();
|
|
|
+ mainWindow->getOsgWidget()->renderBaseMesh(vertices, normals);
|
|
|
}
|