[osg-users] Tessellation

134 views
Skip to first unread message

Bob Slobodan

unread,
Jun 4, 2012, 4:21:38 AM6/4/12
to osg-...@lists.openscenegraph.org
Hi,

The idea is simple, I have a class named "Surface" that handles polygons (each instance handles one polygon). Basically, when a surface has more than 3 vertices, I tessellate it to be sure that it will be properly rendered. My problem is that I now need to separate the different polygons created by the tesselation. If I understood how it works, when OSG tessellates, it modifies the geometry.

So my question is simple : How can I retrieve the different vertex array from the geometry. I don't completely understand how it works.

Thank you!

Cheers,
Bob

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48010#48010





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Bob Slobodan

unread,
Jun 4, 2012, 8:31:03 AM6/4/12
to osg-...@lists.openscenegraph.org
Really no one has a clue about how to do it ?

I tried to look at the getPrimList and the getContours functions of the tessallator but it seems the array are the same as before the tesselation. I also tried to look at the PrimitiveSetList of my geometry but I can only find one after the tessellation (I thought the tesselation would add new PrimitiveSet) and I really don't see where to get the information that I need to create my new surfaces.
No one has a clue ?

Thank you!

Cheers,
Bob

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48022#48022

Robert Osfield

unread,
Jun 4, 2012, 10:20:57 AM6/4/12
to osg-...@lists.openscenegraph.org
On 4 June 2012 13:31, Bob Slobodan <qgal...@msn.com> wrote:
> Really no one has a clue about how to do it ?

More likely that no one has a real clue what you are asking and after.

Getting a vertex array from an osg::Geometry is easy... just look at
the Geometry header and you'll find a getVertexArray() method, but I'm
guessing this isn't really what you are asking, which then leaves
wonder what you actually mean.

> I tried to look at the getPrimList and the getContours functions of the tessallator but it seems the array are the same as before the tesselation. I also tried to look at the PrimitiveSetList of my geometry but I can only find one after the tessellation (I thought the tesselation would add new PrimitiveSet) and I really don't see where to get the information that I need to create my new surfaces.
> No one has a clue ?

Yep, no one has a clue what you actually mean :-)

Robert.

Bob Slobodan

unread,
Jun 4, 2012, 11:01:11 AM6/4/12
to osg-...@lists.openscenegraph.org
Hi,
Sorry, my bad.

Basically, I want to "triangulate" polygons. I have polygon with more than 3 vertices and I want to retrieve the "sub-polygons" (simple triangles) using the osg tesselation tool.

Here is some code. In my "surface" class, after creating my geometry, I tessellate it if it has more than 3 vertex :


Code:

geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,vertices->size()));

tessellator = new osgUtil::Tessellator();

if(vertices.size()>3){
tessellator->setTessellationType(osgUtil::Tessellator::TESS_TYPE_POLYGONS);
tessellator->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO);
tessellator->retessellatePolygons(*geometry);
}




And what I would like to do now is to get the list of "triangles" from my geometry.

By looking at the code of the OSG tesselator, I understood that it creates new PrimitiveSet but I can't figure out how exactly how to do it.

Sorry again and thank you!

Bob

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48027#48027

Robert Osfield

unread,
Jun 4, 2012, 11:53:16 AM6/4/12
to osg-...@lists.openscenegraph.org
On 4 June 2012 16:01, Bob Slobodan <qgal...@msn.com> wrote:
> And what I would like to do now is to get the list of "triangles" from my geometry.

You original asked for vertices... now you want triangles... is that
because you now know how to get the vertices, or is it that you now
know what you want more precisely??

> By looking at the code of the OSG tesselator, I understood that it creates new PrimitiveSet but I can't figure out how exactly how to do it.

How to do what? Do the tessellation - your code you posted does that
so I presume you mean how do you get the PrimitiveSet's which is
pretty easy just look at the header for osg::Geometry and you'll find
getPrimitiveSets().

Is that you are asking how to get the primitive data from a
PrimitiveSet??? Again go have a look at the headers it'll tell you
how to access the data within.

Might I also ask you for what purpose you want to know the
vertices/primitive data? What are you trying to do with it?

Robert.

Bob Slobodan

unread,
Jun 5, 2012, 5:50:23 AM6/5/12
to osg-...@lists.openscenegraph.org
Hi,


>
> You original asked for vertices... now you want triangles... is that
> because you now know how to get the vertices, or is it that you now
> know what you want more precisely??


I knew how to get the vertex array, but the problem is that I don't know how to get the vertices for each sub-polygon (triangles) generated by the tessellation.


> Is that you are asking how to get the primitive data from a
> PrimitiveSet


Basically yes. My problem is that I don't really get how the tesselation works and how to create new polygons using the geometry modified by the tessellation. I thought that the tesselation would simply add new PrimitiveSet such as DrawArrays and that I could have created my new polygons using the getFirst() and getCount() function of DrawArrays with my vertexArray. Unfortunately, when I look at my geometry after the tesselation, it only has DrawElementsUByte, and I don't see how I could get a list of triangles from this PrimitiveSet. I've looked at the DOC, the headers and the source but I don't see what to do.


> Might I also ask you for what purpose you want to know the
> vertices/primitive data? What are you trying to do with it?


For my project, I had to create a class that handles Surfaces (it displays anykind of polygon and it has some useful tools). And I have to implement a tool that "triangulate" the polygon and create new Surfaces with each triangle ; so instead of trying to implement my own tessellation algo, I thought I would simply use the osg tessellation.

I'm really sorry for my lack of precision in my previous posts. And thank you a lot for taking the time to help me.

Cheers,
Bob

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48043#48043

Robert Osfield

unread,
Jun 5, 2012, 6:06:57 AM6/5/12
to osg-...@lists.openscenegraph.org
Hi Bob,

The OSG's DrawElements* encapsulate OpenGL's glDrawElements call, so
it might be best if you just looked up OpenGL documentation online in
books to see how the indices in the DrawElementsUByte/UShort map to
triangles.

Another alternative to looking at the low level primitives is to use a
functor like the TriangleIndexFunctor or TriangleFunctor. Have a
search through the OSG code base to see places where this used.

Robert.

Jason Daly

unread,
Jun 5, 2012, 9:40:39 AM6/5/12
to osg-...@lists.openscenegraph.org
On 06/05/2012 05:50 AM, Bob Slobodan wrote:
> Basically yes. My problem is that I don't really get how the tesselation works and how to create new polygons using the geometry modified by the tessellation. I thought that the tesselation would simply add new PrimitiveSet such as DrawArrays and that I could have created my new polygons using the getFirst() and getCount() function of DrawArrays with my vertexArray. Unfortunately, when I look at my geometry after the tesselation, it only has DrawElementsUByte, and I don't see how I could get a list of triangles from this PrimitiveSet. I've looked at the DOC, the headers and the source but I don't see what to do.

Note that DrawElementsUByte essentially is-a std::vector<GLubyte> which
stores indices into the vertex attribute arrays. Traverse the vector to
get the indices, then look up the specific vertex position, normal, etc,
in the appropriate vertex attribute array.

--"J"

Bob Slobodan

unread,
Jun 5, 2012, 10:50:43 AM6/5/12
to osg-...@lists.openscenegraph.org
Hi,


> Another alternative to looking at the low level primitives is to use a
> functor like the TriangleIndexFunctor or TriangleFunctor. Have a
> search through the OSG code base to see places where this used.


Exactly what I was searching for.

Thanks a lot !!!

Cheers,
Bob

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48053#48053
Reply all
Reply to author
Forward
0 new messages