Search code examples
qtqt3d

How to get mesh triangles


I'm creating meshes with Qt3D. I check if the mesh is actually built with triangles:

qDebug() << "mesh primitive type: " << mesh->primitiveType();

which returns:

Qt3DRender::QGeometryRenderer::PrimitiveType(Triangles)

Therefore, my mesh primitive type is definitely triangle.


Now I'm trying to access to triangles of the mesh, but I don't know how. There is the following API to get the data and its type which can be either VertexBuffer or IndexBuffer:

mesh->geometry()->attributes().at(i)->buffer()->data();
mesh->geometry()->attributes().at(i)->buffer()->type();

But I don't know how to extract triangles one-by-one using the above APIs. Can anybody help me.


Eventually, I'm going to export the triangles as STL file with such a format.


Solution

  • Finally, I used index buffer and vertex buffer to access mesh triangles and export them in STL file format. The method is described here:

    Understanding the mesh created by Qt3D