YangShiXing, One method is to define a node visitor that stops on geodes, traverses the geodes drawables, and adds the drawables to a vertex array. Below is an example that only works with geometry drawables and Vec3Arrays (which are most common I think).
I'm not positive that pointers are necessary for the Vec3Array without looking
at documentation.
Good Luck,
Chase
class VertexExtractor : public osg::NodeVisitor
{
public:
osg::ref_ptr<osg::Vec3Array> extracted_verts;
VertexExtractor() :
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
extracted_verts = new osg::Vec3Array;
}
void apply( osg::Geode& geode )
{
// Cycle through all drawables, getting the vertex arrays from
geometries
// and adding those vertices to the member variable
extracted_verts
for( unsigned int i=0; i < geode.getNumDrawables(); ++i )
{
osg::Geometry* geom = dynamic_cast<osg::Geometry>(
geode.getDrawable(i) );
if( !geom )
continue;
osg::Vec3Array* verts = dynamic_cast<osg::Vec3Array*>(
geom->getVertexArray() );
if( !verts )
continue;
// Add all of these vertices to my list of extracted
vertices.
extracted_verts->insert( extracted_verts->end(),
verts->begin(), verts->end() );
}
}
};
If my_model_node is the node you want vertices from, the do:
VertexExtractor ve;
my_model_node->accept(ve);
osg::Vec3Array* models_vertices = ve.extracted_verts->clone(
osg::CopyOp )
-----Original Message-----
From: [EMAIL PROTECTED] on behalf of ??
Sent: Sat 6/16/2007 3:05 AM
To: [email protected]
Subject: [osg-users] Want to know how to get all of the vertexs of a model?
Hi , I am sorry for my poor English, and I want to know how to get all of
the vertexs of a model , can you give me a tutorials~~ Best regards~
YangShiXing
<<winmail.dat>>
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
