| 1 | #include <osg/Node> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | static bool checkInitialBound( const osg::Node& node ) |
|---|
| 8 | { |
|---|
| 9 | return node.getInitialBound().valid(); |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | static bool readInitialBound( osgDB::InputStream& is, osg::Node& node ) |
|---|
| 13 | { |
|---|
| 14 | osg::Vec3d center; |
|---|
| 15 | double radius; |
|---|
| 16 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 17 | is >> osgDB::PROPERTY("Center") >> center; |
|---|
| 18 | is >> osgDB::PROPERTY("Radius") >> radius; |
|---|
| 19 | is >> osgDB::END_BRACKET; |
|---|
| 20 | node.setInitialBound( osg::BoundingSphere(center, radius) ); |
|---|
| 21 | return true; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | static bool writeInitialBound( osgDB::OutputStream& os, const osg::Node& node ) |
|---|
| 25 | { |
|---|
| 26 | const osg::BoundingSphere& bs = node.getInitialBound(); |
|---|
| 27 | os << 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 | |
|---|
| 35 | static bool checkDescriptions( const osg::Node& node ) |
|---|
| 36 | { |
|---|
| 37 | return node.getDescriptions().size()>0; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | static 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 | |
|---|
| 53 | static 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 | |
|---|
| 67 | REGISTER_OBJECT_WRAPPER( Node, |
|---|
| 68 | new osg::Node, |
|---|
| 69 | osg::Node, |
|---|
| 70 | "osg::Object osg::Node" ) |
|---|
| 71 | { |
|---|
| 72 | ADD_USER_SERIALIZER( InitialBound ); |
|---|
| 73 | ADD_OBJECT_SERIALIZER( ComputeBoundingSphereCallback, |
|---|
| 74 | osg::Node::ComputeBoundingSphereCallback, NULL ); |
|---|
| 75 | ADD_OBJECT_SERIALIZER( UpdateCallback, osg::NodeCallback, NULL ); |
|---|
| 76 | ADD_OBJECT_SERIALIZER( EventCallback, osg::NodeCallback, NULL ); |
|---|
| 77 | ADD_OBJECT_SERIALIZER( CullCallback, osg::NodeCallback, NULL ); |
|---|
| 78 | ADD_BOOL_SERIALIZER( CullingActive, true ); |
|---|
| 79 | ADD_HEXINT_SERIALIZER( NodeMask, 0xffffffff ); |
|---|
| 80 | ADD_USER_SERIALIZER( Descriptions ); |
|---|
| 81 | ADD_OBJECT_SERIALIZER( StateSet, osg::StateSet, NULL ); |
|---|
| 82 | } |
|---|