How to generate mesh object file from a VBO mesh that only have (vertices, normal, color, tangent)?

时间:2015-11-12 10:38:12

标签: opengl

and recently I've been reading a piece of code, I want to generate the .obj mesh file from it. But it looks like VBO doesn't have triangle information. Here is the code generate VBO mesh:

void buildVBOMesh()
{
const vector<VertexData> &vertexData = m_graph->vertexData();

uint nrVertices = vertexData.size();
VertexBufferObjectAttribs::DATA *attrData = new VertexBufferObjectAttribs::DATA[nrVertices];

for(uint i=0; i<nrVertices; ++i)
{    
    VertexData d = vertexData[i];

    vec3 p      = d.position;
    vec3 n      = d.direction;
    vec3 v      = d.vParallel;
    vec3 t      = d.tangent;
    float thick = d.thickness;
    float lengthFromBeginning = d.lengthFromBegining;
    float lengthTotal = d.lengthTotal;

    attrData[i].vx = p.x;
    attrData[i].vy = p.y;
    attrData[i].vz = p.z;
    attrData[i].vw = 1.0f;

    attrData[i].nx = n.x;
    attrData[i].ny = n.y;
    attrData[i].nz = n.z;
    attrData[i].nw = lengthFromBeginning;

    attrData[i].cx = v.x;
    attrData[i].cy = v.y;
    attrData[i].cz = v.z;
    attrData[i].cw = thick;  

    attrData[i].tx = t.x;
    attrData[i].ty = t.y;
    attrData[i].tz = t.z;
    attrData[i].tw = lengthTotal;
}

delete m_vboMesh;
m_vboMesh = new VertexBufferObjectAttribs();
m_vboMesh->setData(attrData, GL_STATIC_DRAW, nrVertices, GL_LINES);

delete[] attrData;

}

1 个答案:

答案 0 :(得分:1)

If there is no index buffer then the faces will simply be:

f 1/1/1 2/2/2 3/3/3
f 4/4/4 5/5/5 6/6/6
# and so on. 

However I don't agree that you should be creating a .obj file, instead you can simply to a binary dump of the vertexData and skip the text parsing when loading.