root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osg/Node.cpp @ 10976

Revision 10976, 2.8 kB (checked in by robert, 5 years ago)

From Wang Rui, new native binary/ascii format infrastructure and wrappers.

From Robert Osfield, refactor of Wang Rui's original osg2 into 3 parts - parts placed into osgDB, the ReaderWriter? placed into src/osg/Plugin/osg and wrappers into src/osgWrappers/serializers/osg

  • Property svn:executable set to *
Line 
1#include <osg/Node>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6// _initialBound
7static bool checkInitialBound( const osg::Node& node )
8{
9    return node.getInitialBound().valid();
10}
11
12static bool readInitialBound( osgDB::InputStream& is, osg::Node& node )
13{
14    osg::Vec3d center;
15    double radius;
16    bool valid;
17    is >> valid >> osgDB::BEGIN_BRACKET;
18    is >> osgDB::PROPERTY("Center") >> center;
19    is >> osgDB::PROPERTY("Radius") >> radius >> osgDB::END_BRACKET;
20    node.setInitialBound( osg::BoundingSphere(center, radius) );
21    return true;
22}
23
24static bool writeInitialBound( osgDB::OutputStream& os, const osg::Node& node )
25{
26    const osg::BoundingSphere& bs = node.getInitialBound();
27    os << bs.valid() << osgDB::BEGIN_BRACKET << std::endl;
28    os << osgDB::PROPERTY("Center") << osg::Vec3d(bs.center()) << std::endl;
29    os << osgDB::PROPERTY("Radius") << double(bs.radius()) << std::endl;
30    os << osgDB::END_BRACKET << std::endl;
31    return true;
32}
33
34// _descriptions
35static bool checkDescriptions( const osg::Node& node )
36{
37    return node.getDescriptions().size()>0;
38}
39
40static bool readDescriptions( osgDB::InputStream& is, osg::Node& node )
41{
42    unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
43    for ( unsigned int i=0; i<size; ++i )
44    {
45        std::string value;
46        is.readWrappedString( value );
47        node.addDescription( value );
48    }
49    is >> osgDB::END_BRACKET;
50    return true;
51}
52
53static bool writeDescriptions( osgDB::OutputStream& os, const osg::Node& node )
54{
55    const osg::Node::DescriptionList& slist = node.getDescriptions();
56    os << slist.size() << osgDB::BEGIN_BRACKET << std::endl;
57    for ( osg::Node::DescriptionList::const_iterator itr=slist.begin();
58          itr!=slist.end(); ++itr )
59    {
60        os.writeWrappedString( *itr );
61        os << std::endl;
62    }
63    os << osgDB::END_BRACKET << std::endl;
64    return true;
65}
66
67REGISTER_OBJECT_WRAPPER( Node,
68                         new osg::Node,
69                         osg::Node,
70                         "osg::Object osg::Node" )
71{
72    ADD_USER_SERIALIZER( InitialBound );  // _initialBound
73    ADD_OBJECT_SERIALIZER( ComputeBoundingSphereCallback,
74                           osg::Node::ComputeBoundingSphereCallback, NULL );  // _computeBoundCallback
75    ADD_OBJECT_SERIALIZER( UpdateCallback, osg::NodeCallback, NULL );  // _updateCallback
76    ADD_OBJECT_SERIALIZER( EventCallback, osg::NodeCallback, NULL );  // _eventCallback
77    ADD_OBJECT_SERIALIZER( CullCallback, osg::NodeCallback, NULL );  // _cullCallback
78    ADD_BOOL_SERIALIZER( CullingActive, true );  // _cullingActive
79    ADD_HEXINT_SERIALIZER( NodeMask, 0xffffffff );  // _nodeMask
80    ADD_USER_SERIALIZER( Descriptions );  // _descriptions
81    ADD_OBJECT_SERIALIZER( StateSet, osg::StateSet, NULL );  // _stateset
82}
Note: See TracBrowser for help on using the browser.