Files
OpenSceneGraph/src/osgWrappers/serializers/osg/Group.cpp
2011-06-02 20:38:13 +00:00

43 lines
1.1 KiB
C++

#include <osg/Group>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
static bool checkChildren( const osg::Group& node )
{
return node.getNumChildren()>0;
}
static bool readChildren( osgDB::InputStream& is, osg::Group& node )
{
unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osg::ref_ptr<osg::Object> obj = is.readObject();
osg::Node* child = dynamic_cast<osg::Node*>( obj.get() );
if ( child ) node.addChild( child );
}
is >> osgDB::END_BRACKET;
return true;
}
static bool writeChildren( osgDB::OutputStream& os, const osg::Group& node )
{
unsigned int size = node.getNumChildren();
os << size << osgDB::BEGIN_BRACKET << std::endl;
for ( unsigned int i=0; i<size; ++i )
{
os << node.getChild(i);
}
os << osgDB::END_BRACKET << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( Group,
new osg::Group,
osg::Group,
"osg::Object osg::Node osg::Group" )
{
ADD_USER_SERIALIZER( Children ); // _children
}