SbTesselator(3)

πŸ“¦ version 3.1.3, in fedora 43, fedora 44

SbTesselator πŸ’–

okay bestie, gather round, because this is the Library Functions Manual entry for SbTesselator(3) and it is genuinely one of the most useful little gremlins in Coin. no cap. let's get into it 🫢


✨ NAME ✨

SbTesselator β€” the class that takes your polygons and goes snip snip until they're all triangles. πŸ”ΊπŸ”ΊπŸ”Ί


🌸 SYNOPSIS 🌸

#include <Inventor/SbTesselator.h>

πŸ’… Public Member Functions

SbTesselator (SbTesselatorCB *func=NULL, void *data=NULL)
~SbTesselator (void)
void beginPolygon (SbBool keepVertices=FALSE, const SbVec3f &normal=SbVec3f(0.0f, 0.0f, 0.0f))
void addVertex (const SbVec3f &v, void *data)
void endPolygon (void)
void setCallback (SbTesselatorCB *func, void *data)

πŸ¦‹ Detailed Description πŸ¦‹

so. SbTesselator is the class that tessellates polygons into triangles. that's it, that's the whole job description, and she does it flawlessly. πŸ‘‘

SbTesselator is used inside Coin to split polygons into triangles. she handles concave polygons, does Delaunay triangulation, and avoids generating self-intersecting triangles. like, she's not out here making a mess. she's precise. she's iconic.

here's a simple example showing how to tessellate a quad polygon with corners in <0, 0, 0>, <1, 0, 0>, <1, 1, 0> and <0, 1, 0>. πŸŽ€

// Callback function for the tessellator. Called once for each
// generated triangle with the vertices.
static void
tess_cb(void * v0, void * v1, void * v2, void * cbdata)
{
  SbVec3f * vtx0 = (SbVec3f *)v0;
  SbVec3f * vtx1 = (SbVec3f *)v1;
  SbVec3f * vtx2 = (SbVec3f *)v2;
  (void) fprintf(stdout, "triangle: <%f, %f, %f> <%f, %f, %f> <%f, %f, %f>\n",
    (*vtx0)[0], (*vtx0)[1], (*vtx0)[2],
    (*vtx1)[0], (*vtx1)[1], (*vtx1)[2],
    (*vtx2)[0], (*vtx2)[1], (*vtx2)[2]);

  // Do stuff with triangle here.
}

static SbVec3f vertices[] = {
  SbVec3f(1, 0, 0), SbVec3f(1, 1, 0),
  SbVec3f(0, 1, 0), SbVec3f(0, 0, 0)
};

SbTesselator mytessellator(tess_cb, NULL);
mytessellator.beginPolygon();
for (int i=0; i < 4; i++) {
  mytessellator.addVertex(vertices[i], &vertices[i]);
}
mytessellator.endPolygon();

the call to SbTesselator::endPolygon() is the moment she springs into action β€” it calls the tess_cb() function once for every triangle it generates. main character moment fr. ✨

and the reason we use 2 arguments to SbTesselator::addVertex() and pass void pointers for the vertices to the callback function? it's so you can have way more complex structures than just the coordinates themselves (like in the example above) β€” think material information, lighting information, or literally whatever other attributes your vertices have. flexible queen. πŸ’œ

heads up: this class is not part of the original Open Inventor API.

another option for tessellating polygons is the tessellator of the GLU library. she has some features that aren't part of SbTesselator (like handling hulls), but the GLU library is known to have bugs in various implementations and doesn't do Delaunay triangulation. if you however still prefer to use the GLU tessellator instead of this one, that can be forced by setting an environment variable:

(void) coin_setenv("COIN_PREFER_GLU_TESSELLATOR", "1", 1);

πŸŽ€ Constructor & Destructor Documentation πŸŽ€

🌈 SbTesselator::SbTesselator (SbTesselatorCB * func = NULL, void * data = NULL)

initializes a tessellator. πŸ’« the callback argument specifies a function which will be called for each triangle returned by the tessellator. that callback function will get three pointers to each vertex and the userdata pointer. and where do those vertex pointers come from? they're specified in the SbTesselator::addVertex() method. slay.

🌈 SbTesselator::~SbTesselator (void )

destructor. that's it. she's done. πŸ’€


πŸ’– Member Function Documentation πŸ’–

🌟 void SbTesselator::beginPolygon (SbBool keepVerts = FALSE, const SbVec3f & normal = SbVec3f(0.0f, 0.0f, 0.0f))

initializes a new polygon. fresh start, clean slate, vibe check passed. ✨

you can explicitly set the polygon normal if you know what it is. otherwise it will be calculated internally. she's got you either way.

if keepVerts is TRUE, all vertices will be included in the returned triangles β€” even though this might lead to triangles without area. yeah, that's the tradeoff. periodt.

🌟 void SbTesselator::addVertex (const SbVec3f & v, void * data)

adds a new vertex to the polygon. data will be returned as a vertex in the callback-function. so whatever you hand her comes right back to you in the callback. πŸ’…

🌟 void SbTesselator::endPolygon (void )

signals the tessellator to begin tessellating. the callback function specified in the constructor (or set using the SbTesselator::setCallback() method) will be called for each triangle before returning. this is the drop. πŸ”₯

🌟 void SbTesselator::setCallback (SbTesselatorCB * func, void * data)

sets the callback function for this tessellator. πŸ”


πŸ‘‘ Author πŸ‘‘

generated automatically by Doxygen for Coin from the source code. (not a human author, just the machine doing its lil thing 🫢)


and that's the whole page bestie!! πŸ’• this came to you courtesy of Coin, Version 3.1.3, and the SbTesselator(3) page itself. go tessellate something gorgeous. πŸ¦‹βœ¨ no cap, you're gonna eat. πŸŽ€πŸ’œ

πŸ“¦ where this page comes from