Discussion:
Get geometry data from a Node
www.hesicong.net
2007-03-05 15:14:03 UTC
Permalink
Hello,
I load some data from a 3ds file using osgDB::readNodeFile() function,
and store the Node to osg::Node* machineNode.
Then I want to get all the vertex data from this Node. I tried to
convert the point directly to osg::Geometry*, but I get wrong data.
Here is my code:
osg::Node* machineNode=NULL;
machineNode=osgDB::readNodeFile("F:/machine.3DS");

osg::Geometry* geo=(osg::Geometry*)machineNode;
osg::Array* ar=geo->getVertexArray();
int size=ar->getDataSize();
size variant is a negative number, so I say the data should be wrong.
Please tell me how to get the vertex data from this node, thanks very much!
Thrall, Bryan
2007-03-05 15:41:12 UTC
Permalink
Post by www.hesicong.net
Hello,
I load some data from a 3ds file using osgDB::readNodeFile() function,
and store the Node to osg::Node* machineNode.
Then I want to get all the vertex data from this Node. I tried to
convert the point directly to osg::Geometry*, but I get wrong data.
osg::Node* machineNode=NULL;
machineNode=osgDB::readNodeFile("F:/machine.3DS");
osg::Geometry* geo=(osg::Geometry*)machineNode;
osg::Array* ar=geo->getVertexArray();
int size=ar->getDataSize();
size variant is a negative number, so I say the data should be wrong.
Please tell me how to get the vertex data from this node, thanks very much!
osgDB::readNodeFile() returns an osg::Node, but osg::Geometry is not a
Node, it is a osg::Drawable. So, at the very least, readNodeFile in this
case will return an osg::Geode (which is a Node, and will contain
Drawables which might be Geometry), but I don't know any thing about the
OSG 3DS reader, so it might return a more complicated structure of Nodes
than that.
--
Bryan Thrall
FlightSafety International
Bryan.Thrall-***@public.gmane.org
Alberto Luaces
2007-03-05 15:47:23 UTC
Permalink
Post by Thrall, Bryan
    osg::Geometry* geo=(osg::Geometry*)machineNode;
osgDB::readNodeFile() returns an osg::Node, but osg::Geometry is not a
Node, it is a osg::Drawable. So, at the very least, readNodeFile in this
case will return an osg::Geode (which is a Node, and will contain
Drawables which might be Geometry), but I don't know any thing about the
OSG 3DS reader, so it might return a more complicated structure of Nodes
than that.
In addition of what Bryan said, I would stress the use of C++ type casts like
dynamic_cast, which could be used to verify safely if the Node returned is
indeed a Geode.

Continue reading on narkive:
Loading...