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

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

From Wang Rui, "Changes:

1. Rewrite the reading/writing exception handlers to work like the ive
plugin exceptions.
2. Write a header writing/checking function in ReaderWriterOSG2.cpp,
which may help decide if the stream is ascii or binary. The
readInputIterator() function will return null pointer if the input
file is nither osgb nor osgt format, which indicates that the old .osg
format could be used here, in case we've merged the two plugins
together.
3. Add a new ForceReadingImage? option in the InputStream?, which will
allocate an empty image object with the filename if specifed external
image file is missed. It may be useful for format converting in some
cases.
4. Add new osgParticle wrappers, as well as some modification to the
osgParticle headers, for instance, change isEnabled() to getEnabled().
5. Some fixes to the osg serialization wrappers."

  • 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    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
24static 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// _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.