After BrepIncremental mesh of TopoDS_shape, how to retrieve a contiguous coordinate data of polytriangles?

for (TopExp_Explorer exp(aMesher.Shape(), TopAbs_FACE); exp.More(); exp.Next())
{
const TopoDS_Face& face = TopoDS::Face(exp.Current());
TopLoc_Location loc;
facing = BRep_Tool::Triangulation(face, loc);

TColgp_Array1OfPnt tab(1, (facing->NbNodes()));
tab = facing->Nodes();
Poly_Array1OfTriangle tri(1, facing->NbTriangles());
tri = facing->Triangles();

for (Standard_Integer i = 1; i <= facing->NbTriangles(); i++)
{
Poly_Triangle trian = tri.Value(i);
Standard_Integer index1, index2, index3;
trian.Get(index1, index2, index3);

const gp_XYZ& pt1 = tab.Value(index1).XYZ();
const gp_XYZ& pt2 = tab.Value(index2).XYZ();
const gp_XYZ& pt3 = tab.Value(index3).XYZ();

gp_XYZ v1 = pt2 - pt1;
gp_XYZ v2 = pt3 - pt2;

gp_XYZ normal = v1^v2;
normal.Normalize();

gl_vertex.vertices[NbTria + 0].position = glm::vec3(pt1.X(), pt1.Y(), pt1.Z()); // 0
gl_vertex.vertices[NbTria + 1].position = glm::vec3(pt2.X(), pt2.Y(), pt2.Z()); // 1
gl_vertex.vertices[NbTria + 2].position = glm::vec3(pt3.X(), pt3.Y(), pt3.Z()); //2
NbTria+=3;
}
glBufferData(GL_ARRAY_BUFFER, 3*totalTriangles * sizeof(glm::vec3),gl_vertex.vertices , GL_STATIC_DRAW);

Because glBufferData only takes contiguous memory of data ,here I am copying the coordinates to create a continous memory(gl_vertex.vertices). Does "poly_trianglulations" sets contiguous memory of triangle vertices, atleast for each face? If yes, how to retrieve them without duplicating them?

Kirill Gavrilov's picture

Poly_Triangulation allocates a continuous array for vertices, but it uses double precision, while OpenGL expects single precision floating point values. So you have to convert values anyway.