Added prelimarny support for reading archives via the .net plugin
This commit is contained in:
parent
06f1b602e7
commit
ddb0d6bd4f
@ -129,9 +129,11 @@ int main( int argc, char **argv )
|
||||
itr!=files.end();
|
||||
++itr)
|
||||
{
|
||||
std::cout<<"reading "<<*itr<<std::endl;
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(*itr);
|
||||
if (obj.valid())
|
||||
{
|
||||
std::cout<<" write to archive "<<*itr<<std::endl;
|
||||
archive->writeObject(*obj, *itr);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line paramters");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindigs.");
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
@ -39,9 +42,13 @@ int main( int argc, char **argv )
|
||||
viewer.getUsage(*arguments.getApplicationUsage());
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
bool helpAll = arguments.read("--help-all");
|
||||
unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) |
|
||||
((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) |
|
||||
((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 );
|
||||
if (helpType)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
arguments.getApplicationUsage()->write(std::cout, helpType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,12 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
|
||||
virtual bool acceptsExtension(const std::string& /*extension*/) { return true; }
|
||||
|
||||
/** open the archive.*/
|
||||
/** open the archive for reading, writing or to create an empty archive for writing to.*/
|
||||
virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096) = 0;
|
||||
|
||||
/** open the archive for reading.*/
|
||||
virtual bool open(std::istream& fin) = 0;
|
||||
|
||||
/** close the archive.*/
|
||||
virtual void close() = 0;
|
||||
|
||||
|
@ -161,8 +161,12 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
CREATE
|
||||
};
|
||||
|
||||
/** open an archive for reading, writing or or to create an empty archive for writing to.*/
|
||||
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
|
||||
/** open an archive for reading.*/
|
||||
virtual ReadResult openArchive(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
|
||||
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/Archive>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/Group>
|
||||
#include <osg/Timer>
|
||||
@ -85,11 +86,18 @@ class NetReader : public osgDB::ReaderWriter
|
||||
enum ObjectType
|
||||
{
|
||||
OBJECT,
|
||||
ARCHIVE,
|
||||
IMAGE,
|
||||
HEIGHTFIELD,
|
||||
NODE
|
||||
};
|
||||
|
||||
virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options)
|
||||
{
|
||||
if (status!=READ) return ReadResult(ReadResult::FILE_NOT_HANDLED);
|
||||
else return readFile(ARCHIVE,fileName,options);
|
||||
}
|
||||
|
||||
virtual ReadResult readObject(const std::string& fileName, const Options* options)
|
||||
{
|
||||
return readFile(OBJECT,fileName,options);
|
||||
@ -115,6 +123,7 @@ class NetReader : public osgDB::ReaderWriter
|
||||
switch(objectType)
|
||||
{
|
||||
case(OBJECT): return rw->readObject(fin,options);
|
||||
case(ARCHIVE): return rw->openArchive(fin,options);
|
||||
case(IMAGE): return rw->readImage(fin,options);
|
||||
case(HEIGHTFIELD): return rw->readHeightField(fin,options);
|
||||
case(NODE): return rw->readNode(fin,options);
|
||||
@ -127,7 +136,7 @@ class NetReader : public osgDB::ReaderWriter
|
||||
{
|
||||
osg::Timer_t start = osg::Timer::instance()->tick();
|
||||
|
||||
osg::notify(osg::DEBUG_INFO) << "osgPlugin .net: start load" << inFileName << std::endl;
|
||||
osg::notify(osg::NOTICE) << "osgPlugin .net: start load" << inFileName << std::endl;
|
||||
|
||||
std::string hostname;
|
||||
std::string serverPrefix;
|
||||
@ -196,6 +205,7 @@ class NetReader : public osgDB::ReaderWriter
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
*/
|
||||
|
||||
|
||||
std::string fileName;
|
||||
int index = inFileName.find(":");
|
||||
// If we haven't been given a hostname as an option
|
||||
@ -224,6 +234,10 @@ class NetReader : public osgDB::ReaderWriter
|
||||
if( !serverPrefix.empty() )
|
||||
fileName = serverPrefix + '/' + fileName;
|
||||
|
||||
osg::notify(osg::WARN) << "hostname " << hostname << std::endl;
|
||||
osg::notify(osg::WARN) << "filename " << fileName << std::endl;
|
||||
|
||||
|
||||
// Invoke the reader corresponding to the extension
|
||||
osgDB::ReaderWriter *reader =
|
||||
osgDB::Registry::instance()->getReaderWriterForExtension( osgDB::getFileExtension(fileName));
|
||||
@ -248,9 +262,9 @@ class NetReader : public osgDB::ReaderWriter
|
||||
}
|
||||
|
||||
// Fetch from the network
|
||||
iosockinet sio (sockbuf::sock_stream);
|
||||
osg::ref_ptr<iosockinet> sio = new iosockinet(sockbuf::sock_stream);
|
||||
try {
|
||||
sio->connect( hostname.c_str(), port );
|
||||
sio->rdbuf()->connect( hostname.c_str(), port );
|
||||
}
|
||||
catch( sockerr e )
|
||||
{
|
||||
@ -258,13 +272,13 @@ class NetReader : public osgDB::ReaderWriter
|
||||
return ReadResult::FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
sio << "GET /" << fileName << " HTTP/1.1\n" << "Host:\n\n";
|
||||
sio.flush();
|
||||
*sio << "GET /" << fileName << " HTTP/1.1\n" << "Host:\n\n";
|
||||
sio->flush();
|
||||
|
||||
char linebuff[256];
|
||||
do
|
||||
{
|
||||
sio.getline( linebuff, sizeof( linebuff ));
|
||||
sio->getline( linebuff, sizeof( linebuff ));
|
||||
|
||||
std::istringstream iss(linebuff);
|
||||
std::string directive;
|
||||
@ -329,13 +343,20 @@ class NetReader : public osgDB::ReaderWriter
|
||||
|
||||
|
||||
if( reader != 0L )
|
||||
readResult = readFile(objectType, reader, sio, local_opt.get() );
|
||||
readResult = readFile(objectType, reader, *sio, local_opt.get() );
|
||||
|
||||
double ms = osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick());
|
||||
|
||||
osg::notify(osg::DEBUG_INFO) << "osgPlugin .net: " << fileName <<
|
||||
" fetched from server. in" << ms <<" ms"<< std::endl;
|
||||
|
||||
if (objectType==ARCHIVE && readResult.validArchive())
|
||||
{
|
||||
// attach the socket istream to the archive to keep it alive.
|
||||
osgDB::Archive* archive = readResult.getArchive();
|
||||
archive->setUserData(sio.get());
|
||||
}
|
||||
|
||||
if( !localCacheDir.empty() && cacheMode & Write )
|
||||
{
|
||||
std::string cacheFile = localCacheDir + '/' + fileName;
|
||||
|
@ -11,6 +11,8 @@
|
||||
#ifndef _SOCKINET_H
|
||||
#define _SOCKINET_H
|
||||
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include "sockstream.h"
|
||||
|
||||
#if defined(__CYGWIN__) || !defined(WIN32)
|
||||
@ -112,7 +114,7 @@ class isockinet: public isockstream
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
};
|
||||
|
||||
class osockinet: public osockstream
|
||||
class osockinet: public osg::Referenced, public osockstream
|
||||
{
|
||||
public:
|
||||
osockinet (const sockbuf::sockdesc& sd);
|
||||
@ -121,10 +123,9 @@ class osockinet: public osockstream
|
||||
~osockinet ();
|
||||
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
};
|
||||
|
||||
class iosockinet: public iosockstream
|
||||
class iosockinet: public osg::Referenced, public iosockstream
|
||||
{
|
||||
public:
|
||||
iosockinet (const sockbuf::sockdesc& sd);
|
||||
@ -133,7 +134,6 @@ class iosockinet: public iosockstream
|
||||
~iosockinet ();
|
||||
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
};
|
||||
|
||||
#endif // _SOCKINET_H
|
||||
|
@ -353,6 +353,12 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig
|
||||
}
|
||||
}
|
||||
|
||||
bool OSGA_Archive::open(std::istream& fin)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"OSGA_Archive::open"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
void OSGA_Archive::close()
|
||||
{
|
||||
_input.close();
|
||||
|
@ -20,6 +20,9 @@ class OSGA_Archive : public osgDB::Archive
|
||||
/** open the archive.*/
|
||||
virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096);
|
||||
|
||||
/** open the archive for reading.*/
|
||||
virtual bool open(std::istream& fin);
|
||||
|
||||
/** close the archive.*/
|
||||
virtual void close();
|
||||
|
||||
|
@ -39,6 +39,18 @@ public:
|
||||
return archive.get();
|
||||
}
|
||||
|
||||
/** open an archive for reading.*/
|
||||
virtual ReadResult openArchive(std::istream& fin,const Options*)
|
||||
{
|
||||
osg::ref_ptr<OSGA_Archive> archive = new OSGA_Archive;
|
||||
if (!archive->open(fin))
|
||||
{
|
||||
return ReadResult(ReadResult::FILE_NOT_HANDLED);
|
||||
}
|
||||
|
||||
return archive.get();
|
||||
}
|
||||
|
||||
virtual ReadResult readImage(const std::string& file,const Options* options)
|
||||
{
|
||||
ReadResult result = openArchive(file,osgDB::Archive::READ);
|
||||
|
@ -981,7 +981,7 @@ void ViewerEventHandler::getUsage(osg::ApplicationUsage& usage) const
|
||||
usage.addKeyboardMouseBinding("f","Toggle fullscreen");
|
||||
usage.addKeyboardMouseBinding("h","Display help");
|
||||
usage.addKeyboardMouseBinding("o","Write scene graph to \"saved_model.osg\"");
|
||||
usage.addKeyboardMouseBinding("O PrtSrn","Write camera images to \"saved_image*.rgb\"");
|
||||
usage.addKeyboardMouseBinding("O PrtSrn","Write camera images to \"saved_image*.jpg\"");
|
||||
usage.addKeyboardMouseBinding("s","Toggle instrumention");
|
||||
usage.addKeyboardMouseBinding("v","Toggle block and vsync");
|
||||
usage.addKeyboardMouseBinding("z","Start recording camera path.");
|
||||
|
Loading…
Reference in New Issue
Block a user