aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drone_controller.cc28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 9241d30..0a69fd1 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -6,7 +6,6 @@
#include <QJsonArray>
#include <QDebug>
-#include <Qt3DRender/QMesh>
Waypoint::Waypoint(unsigned frame, QVector3D pos)
@@ -39,7 +38,32 @@ Drone::Drone() {
// qWarning() << "TinyObjReader: " << reader.Warning();
// }
auto& attrib = reader.GetAttrib();
- mesh = new OpenGLMesh(QVector<float>(attrib.vertices.begin(), attrib.vertices.end()));
+ auto& shapes = reader.GetShapes();
+
+ QVector<float> verts;
+
+ for (size_t s = 0; s < shapes.size(); s++) {
+ // Loop over faces(polygon)
+ size_t index_offset = 0;
+ for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) {
+ size_t fv = shapes[s].mesh.num_face_vertices[f];
+
+ // Loop over vertices in the face.
+ for (size_t v = 0; v < fv; v++) {
+ tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v];
+ tinyobj::real_t vx = attrib.vertices[3*idx.vertex_index+0];
+ tinyobj::real_t vy = attrib.vertices[3*idx.vertex_index+1];
+ tinyobj::real_t vz = attrib.vertices[3*idx.vertex_index+2];
+ verts.append(vx);
+ verts.append(vy);
+ verts.append(vz);
+ }
+ index_offset += fv;
+ }
+ }
+
+ mesh = new OpenGLMesh(verts);
+ // mesh = new OpenGLMesh(QVector<float>(attrib.vertices.begin(), attrib.vertices.end()));
mesh_initialized = true;
}
OpenGLWidget::instance->meshes.append(*mesh);