summaryrefslogtreecommitdiff
path: root/wave-sim/src/graphics/meshloader.cpp
diff options
context:
space:
mode:
authorSebastian Park <SebPark03@gmail.com>2024-04-10 02:45:04 -0400
committerSebastian Park <SebPark03@gmail.com>2024-04-10 02:45:04 -0400
commit47cd8a592ecad52c1b01f27d23476c0a5afeb7f1 (patch)
tree36b9abaff4e92a4a6df0d5ecb0e43e05c3aefd48 /wave-sim/src/graphics/meshloader.cpp
parentfd19124693bb32835ad97802ba1950cd5202dbd2 (diff)
initial
Diffstat (limited to 'wave-sim/src/graphics/meshloader.cpp')
-rw-r--r--wave-sim/src/graphics/meshloader.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/wave-sim/src/graphics/meshloader.cpp b/wave-sim/src/graphics/meshloader.cpp
new file mode 100644
index 0000000..84e78c7
--- /dev/null
+++ b/wave-sim/src/graphics/meshloader.cpp
@@ -0,0 +1,53 @@
+#include "graphics/meshloader.h"
+
+#define TINYOBJLOADER_IMPLEMENTATION
+#include "util/tiny_obj_loader.h"
+
+#include <iostream>
+
+#include <QString>
+#include <QFile>
+#include <QTextStream>
+#include <QRegularExpression>
+
+using namespace Eigen;
+
+bool MeshLoader::loadTetMesh(const std::string &filepath, std::vector<Eigen::Vector3d> &vertices, std::vector<Eigen::Vector4i> &tets)
+{
+ QString qpath = QString::fromStdString(filepath);
+ QFile file(qpath);
+
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ std::cout << "Error opening file: " << filepath << std::endl;
+ return false;
+ }
+ QTextStream in(&file);
+
+ QRegularExpression vrxp("v (-?\\d*\\.?\\d+) +(-?\\d*\\.?\\d+) +(-?\\d*\\.?\\d+)");
+ QRegularExpression trxp("t (\\d+) +(\\d+) +(\\d+) +(\\d+)");
+
+ while(!in.atEnd()) {
+ QString line = in.readLine();
+ auto match = vrxp.match(line);
+ if(match.hasMatch()) {
+ vertices.emplace_back(match.captured(1).toDouble(),
+ match.captured(2).toDouble(),
+ match.captured(3).toDouble());
+ continue;
+ }
+ match = trxp.match(line);
+ if(match.hasMatch()) {
+ tets.emplace_back(match.captured(1).toInt(),
+ match.captured(2).toInt(),
+ match.captured(3).toInt(),
+ match.captured(4).toInt());
+ }
+ }
+ file.close();
+ return true;
+}
+
+MeshLoader::MeshLoader()
+{
+
+}