aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorccolin2020-12-22 18:15:19 +0100
committerccolin2020-12-22 18:15:19 +0100
commitc0116528a7b618d185ac688b31e0fa8752924375 (patch)
treeb4d4e5132d63dd9c8282847bc8b6a5398848bf6d
parent1026231bb4a413e80359413182da22655c36555d (diff)
use Qt resources for the drone model
-rw-r--r--projet.pro2
-rw-r--r--resources.qrc7
-rw-r--r--src/drone_controller.cc16
3 files changed, 21 insertions, 4 deletions
diff --git a/projet.pro b/projet.pro
index 5882ee4..78954f1 100644
--- a/projet.pro
+++ b/projet.pro
@@ -4,6 +4,8 @@ TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += qt debug
+RESOURCES += resources.qrc
+
SOURCES += src/main.cc
SOURCES += src/main_window.cc
SOURCES += src/opengl_mesh.cc
diff --git a/resources.qrc b/resources.qrc
new file mode 100644
index 0000000..d7d5020
--- /dev/null
+++ b/resources.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+ <qresource>
+ <file>mdl/dji600.obj</file>
+ <file>mdl/dji600.mtl</file>
+ </qresource>
+</RCC>
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 406a031..c625ca0 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -6,6 +6,7 @@
#include <QJsonArray>
#include <QDebug>
+#include <QFile>
Waypoint::Waypoint(unsigned frame, QVector3D pos)
@@ -25,12 +26,19 @@ OpenGLMesh *Drone::mesh = nullptr;
Drone::Drone() {
if (!mesh_initialized) {
- tinyobj::ObjReaderConfig reader_config;
- reader_config.mtl_search_path = "../mdl/"; // Path to material files
+ QFile obj_file(":/mdl/dji600.obj");
+ QFile mtl_file(":/mdl/dji600.mtl");
+ obj_file.open(QIODevice::ReadOnly | QIODevice::Text);
+ mtl_file.open(QIODevice::ReadOnly | QIODevice::Text);
+ std::string obj = obj_file.readAll().toStdString();
+ std::string mtl = mtl_file.readAll().toStdString();
+ tinyobj::ObjReaderConfig cfg;
+ cfg.triangulate = true;
+ cfg.vertex_color = false;
tinyobj::ObjReader reader;
- if (!reader.ParseFromFile("../mdl/dji600.obj", reader_config)) {
+ if (!reader.ParseFromString(obj, mtl, cfg)) {
if (!reader.Error().empty()) {
- qWarning() << "Erreur lors de la lecture de ../mdl/dji600.obj";
+ qWarning() << "Erreur lors de la lecture de du modèle";
}
exit(1);
}