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 #include -#include Waypoint::Waypoint(unsigned frame, QVector3D pos) @@ -39,7 +38,32 @@ Drone::Drone() { // qWarning() << "TinyObjReader: " << reader.Warning(); // } auto& attrib = reader.GetAttrib(); - mesh = new OpenGLMesh(QVector(attrib.vertices.begin(), attrib.vertices.end())); + auto& shapes = reader.GetShapes(); + + QVector 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(attrib.vertices.begin(), attrib.vertices.end())); mesh_initialized = true; } OpenGLWidget::instance->meshes.append(*mesh);