fix model loading

This commit is contained in:
ccolin 2020-12-22 17:37:12 +01:00
parent f20a0f978d
commit e87f0b5256

View File

@ -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);