Hi Rob,

If you want to access the vertex attribute data (such as colours,
normals, tex coords)  then you are probably best to do a
dynamic_cast<Geometry*> on the drawable and then access the data that
way.  If the drawable isn't a geometry then you'll need to use a cast
to whatever object it is.

Robert.

On Mon, Jul 26, 2010 at 11:07 PM, Rob Radtke <r...@stellarscience.com> wrote:
> Thank you Robert for the detailed explanation of TriangleFunctor and
> TriangleIndexFunctor.  Those classes have proven to be very useful to me.
>  I'm curious to know if there is a good way to use those classes in a manner
> that allows you to also access attributes for each vertex.  In particular,
> I'm interested in accessing texture coordinate and/or color attributes (for
> v1, v2 and v3) inside of my 'operator()(const int v1, const int v2, const
> int v3)' implementation.
>
> I have had some limited success using a custom ConstAttributeFunctor
> subclass to accumlate attributes inside of a ' NodeVisitor::apply(
> osg::Geode&)' override, but I'm struggling with devising the best plan for
> mapping each vertex back to the appropriate attribute.  My current solution
> is very messy and I doublt it's very robust.  Is there a prescribed way to
> do this?
>
> Thanks,
> Rob Radtke
>
> -----Original Message-----
> From: osg-users-boun...@lists.openscenegraph.org
> [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert
> Osfield
> Sent: 12 March 2010 10:57
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] Need help to understand this code snippet
> withaccept
> and operator
>
> Hi Fred,
>
> The TriangleIndexFunctor is a template helper class for making it
> easier to access the triangles held in osg::Drawable.  The actual
> geometry primitives held within different osg::Drawable subclasses
> could be of any type and any arrangement, so casting osg::Drawable to
> osg::Geometry etc. and then accessing the primitives directly and then
> working out how to interpret the triangles from this is rather
> complex, tedious and prone to poor performance unless you are very
> careful.
>
> To address the tight coupling of accessors to implementations, the
> osg::Drawable has an accept(osg::Drawable::PrimitiveFunctor&) method
> exists to allow a subclass from osg::Drawable to pass details on the
> geometry primitives that it has to the functor in a generic way - thus
> hiding the local implementation details of that Drawable and enabling
> your own custom PrimitiveFunctor to work with a wide range of Drawable
> without needing to know the implementation details.  While this
> achieves good decoupling the PrimitiveFunctor still has to handle all
> the different types of primitives - polygons, tri strips, quads, qaud
> strips, lines etc, which is still pretty complicated to implement.
>
> To address the complexity of handling all the different types of
> primitives the TriangleIndexFunctor template class exists to decompose
> all the descriptions of generic primitives into the simple triangles
> marked by their corner indices.  For you the app developer all you
> then need to do is create you little functor that implements the void
> operator()(const int v1, const int v2, const int v3) method as per the
> example, and then pass the resulting templated class to the drawable
> to get all the triangle information.  The use of templates also
> ensures good performance.
>
> If it wasn't for PrimtiiveFunctor and
> TriangleFunctor/TriangleIndexFunctor accessing geometry would be very
> tedious and error prone task - lots of casts, switch statements and
> book keeping.  These helper classes might seem a bit convoluted at
> first look, they really make life much easier.  Go have a search
> through the OSG code base, there are plenty of examples of
> TriangleFunctor/TriangleIndexFunctor in action - especially in
> src/osgUtil.
>
> Cheers,
> Robert.
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to