On Tue, Jun 15, 2010 at 11:12 AM, Nicolas Payot <[email protected]>wrote:
> Hello guys,
>
> I'm trying to retrieve the number of vertices of a mesh described in an obj
> file. I use the function osgDB::readNodeFile(fileName) to load it and the
> following one to get that number:
>
> int Mesh::getVertNum()
> {
> // Convert the node m_obj into a Group pointer and return child node at
> position 0
> osg::Geode* geode =
> dynamic_cast<osg::Geode*>(m_obj->asGroup()->getChild(0));
> osg::Geometry* geometry = geode->getDrawable(0)->asGeometry();
> osg::Vec3Array* vertex =
> dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
> return vertex->getNumElements();
> }
>
> But the thing is it doesn't give me the correct number. I tried with a
> simple cube and I obtained 24 vertices.
> Someone already had that problem in this message:
> http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2008-September/016855.html
> but
> I'm not sure to well understand, and also I still don't know how to get the
> correct number.
> Does anyone have an idea?
>
> This is correct. The obj reader constructs DrawArray objects, which
duplicate vertices in each polygon. In the case of a cube, this is actually
not too bad: a single vertex has a different normal in each of faces that
share it, so there is no opportunity for optimization by creating an indexed
mesh. If you have a more complex mesh that you think should be optimized,
you can try the new INDEX_MESH optimizer and its companions
VERTEX_POSTTRANSFORM and VERTEX_PRETRANSFORM.
Tim
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org