Rafa Gaitan wrote:
> Hi James,
>
> I did something similar, and is easy, but you need to use the ReaderWriter
> API, that supports serialization to a stream. Here is my code:
>
>
> void IOSocket::writeObject( const osg::Object* obj)
> {
> OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_rwMutex);
> if(!_rw.valid())
> {
> _rw =
> osgDB::Registry::instance()->getReaderWriterForExtension("osgt");
> if(!_rw.valid())
> throw SocketException("Not valid ReaderWriter for osg::Object");
> }
> std::stringstream sstr;
> _rw->writeObject(*obj,sstr);
> (*this) << sstr.str();
> }
>
>
> osg::Object* IOSocket::readObject()
> {
> OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_rwMutex);
> if(!_rw.valid())
> {
> _rw =
> osgDB::Registry::instance()->getReaderWriterForExtension("osgt");
> if(!_rw.valid())
> throw SocketException("Not valid ReaderWriter for osg::Object");
> }
> std::string str;
> (*this) >> str;
> std::cout << str << std::endl;
> std::stringstream sstr(str);
> return _rw->readObject(sstr).takeObject();
> }
>
>
>
> _rw has this definition: osg::ref_ptr<osgDB::ReaderWriter> _rw;
>
>
> and this line:
> osgDB::Registry::instance()->getReaderWriterForExtension("osgt");
>
>
> Selects the new ascii OSG serializer, but if you set "osgb" then the data is
> serialized in binary format and probably will give you better performance.
>
>
> Cheers,
> Rafa.
>
>
> --
> Rafael Gaitán Linares
> CTO at Mirage Technologies S.L - http://www.mirage-tech.com
> (http://www.mirage-tech.com)
> gvSIG3D Developer - http://gvsig3d.blogspot.com (http://gvsig3d.blogspot.com)
>
> ------------------
> Post generated by Mail2Forum
Thank you Rafael! This is what I want!
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48122#48122
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org