Thank you Alberto,

osg::TriangleFunctor<A> pointed me in the right direction.  I ended up using 
the following code:

osg::TriangleIndexFunctor<TriangleIndexVisitor> tif;
tempGeode.geode->getDrawable(j)->accept(tif);

With TriangleIndexVisitor defined as:

class TriangleIndexVisitor
{
public:
        CArray<int,int> indices;

        void operator()(const int v1, const int v2, const int v3)
        {
                // toss the computed indices into the indices array
                indices.Add( v1 );
                indices.Add( v2 );
                indices.Add( v3 );
        }
};

Yuen Helbig

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alberto Luaces
Sent: Wednesday, April 30, 2008 2:29 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] How do I get an array of vertices and an array 
ofindices from an osg::Geometry object?

Hi Yuen Helbig,

I think it's easier to use osg::TriangleFunctor on the Drawable:

osg::TriangleFunctor<A> tf;

tempGeode.geode->getDrawable(j)->accept(tf);

As shown in
http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01688.html#_details,
the template parameter A must be a class which defines the operator() method. 
If you define it as

void operator()( const osg::Vec3d &v1, const osg::Vec3d &v2, const osg::Vec3d 
&v3, bool temp)

(note that the three vectors are passed by reference) you can extract the 
vertex coordinates through them and also the indices from their pointers.

HTH,

Alberto

El Miércoles 30 Abril 2008ES 00:58:30 Helbig, Yuen escribió:
> Hello,
>
> I'm trying to extract an array of vertices and indices from an 
> osg::Geometry object for
>
>  collision detection purposes, my initial code looks like:
>
>  
>
> osg::Geometry* tempGeometry =
> tempGeode.geode->getDrawable(j)->asGeometry();
>
> float* tempVertexArrayPtr =
> (float*)(tempGeometry->getVertexArray()->getDataPointer());
>
> int* tempIndexArrayPtr =
> (int*)(tempGeometry->getVertexIndices()->getDataPointer());
>
>  
>
> However, tempGeometry->getVertexIndices() is NULL so I'm looking for 
> another way to
>
>  get the vertex indices.  Perhaps from the osg::PrimitiveSet in my 
> Geometry, but I'm not sure.
>
>  
>
> Anyone have any suggestions?


_______________________________________________
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