2015-11-12 45 views
0

和最近我一直在閱讀一段代碼,我想從中生成.obj網格文件。但它看起來像VBO沒有三角形信息。 這裏是代碼生成VBO網:如何從只有(頂點,法線,顏色,正切)的VBO網格生成網格物體文件?

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

如果沒有索引緩衝區,則面將僅僅是:

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

但是我不同意,你應該要創建一個.obj文件,您可以簡單地轉到vertexData的二進制轉儲,並在加載時跳過文本解析。

+0

然後,如果我畫網格,它會是一些單點? –