Shared Vertex Buffer

I'm pretty new to OpenCascade, currently evaluating the library. So maybe this question is easy to answer for sombody more experienced...

I need to extract vertex and index data for my shapes in order to feed my proprietary render engine. I managed to create a primitive shape, mesh it and walk through the faces and access the triangulation data like so:

opencascade::handle<Poly_Triangulation> tri = BRep_Tool::Triangulation(currentFace, loc);

I can also read the vertex data and index data just fine from there. However, there seems to be one vertex buffer per face.

My question is this: Can such a shape also be triangulated such that there is a common vertex buffer which is shared among faces avoiding duplicate vertices?

I know that in the general case this is not much of an optimization, as there aren't too many duplicates. But my render engine appreciates only having to load one vertex buffer...

Kirill Gavrilov's picture

Sharing vertex data is not always useful / applicable. For instance, box have 6 vertices, so that one TopoDS_Vertex is shared by more than a single TopoDS_Face, and technically you may imagine a single indexed triangulation of a box with just 6 vertices - but then you realize, that the same vertex needs a different normal for each TopoDS_Face...

Of course, there are scenarios, where a pair of TopoDS_Face has a smooth connection like GeomAbs_G2. Then you may try manually stitching Poly_Triangulation of these faces based on Poly_PolygonOnTriangulation of shared TopoDS_Edge's.

But I would say this is certainly an over-optimization, which may spare a little amount of vertex data for visualization in normal cases - something that could be analyzed and probed when (and if) you will observe real performance issues. It doesn't worth implementing such aggressive optimizations at the beginning.