diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-04-10 02:51:43 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-04-10 02:51:43 -0400 |
commit | 0b0629450e2553b2f890094290528b565d607e38 (patch) | |
tree | 16d34a6123f3e50153b5fcd6466de5057cc960a0 /wave-sim/src/graphics/meshloader.cpp | |
parent | ad313dcf57437ec0d40dddbce622a11c2bc2bc23 (diff) | |
parent | 47cd8a592ecad52c1b01f27d23476c0a5afeb7f1 (diff) |
Merge branch 'shaders'
Diffstat (limited to 'wave-sim/src/graphics/meshloader.cpp')
-rw-r--r-- | wave-sim/src/graphics/meshloader.cpp | 53 |
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() +{ + +} |