diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index b257c3949..9b12b9099 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -607,7 +607,7 @@ osg::Node* createCube(float size,float alpha, unsigned int numSlices, float slic float halfSize = size*0.5f; float y = halfSize; - float dy =-size/(float)(numSlices-1)*sliceEnd; + float dy =-size*1.4/(float)(numSlices-1)*sliceEnd; //y = -halfSize; //dy *= 0.5; diff --git a/include/osgDB/Output b/include/osgDB/Output index 0d67fbdd5..c97a09bf4 100644 --- a/include/osgDB/Output +++ b/include/osgDB/Output @@ -16,11 +16,10 @@ #include -#include +#include #include #include - #include namespace osgDB { @@ -36,6 +35,10 @@ class OSGDB_EXPORT Output : public std::ofstream virtual ~Output(); + + void setOptions(const ReaderWriter::Options* options) { _options = options; } + const ReaderWriter::Options* getOptions() const { return _options.get(); } + void open(const char *name); // comment out temporarily to avoid compilation problems, RO Jan 2002. @@ -79,12 +82,18 @@ class OSGDB_EXPORT Output : public std::ofstream virtual std::string getFileNameForOutput(const std::string& filename) const; const std::string& getFileName() const { return _filename; } + void setOutputTextureFiles(bool flag) { _outputTextureFiles = true; } + bool getOutputTextureFiles() const { return _outputTextureFiles; } + + virtual std::string getTextureFileNameForOutput(); protected: virtual void init(); + osg::ref_ptr _options; + int _indent; int _indentStep; @@ -96,6 +105,8 @@ class OSGDB_EXPORT Output : public std::ofstream std::string _filename; PathNameHint _pathNameHint; + bool _outputTextureFiles; + unsigned int _textureFileNameNumber; }; diff --git a/src/osgDB/Output.cpp b/src/osgDB/Output.cpp index 2e1c1b6c8..f8d2a3eac 100644 --- a/src/osgDB/Output.cpp +++ b/src/osgDB/Output.cpp @@ -16,6 +16,7 @@ #include +#include #include using namespace std; @@ -43,6 +44,8 @@ void Output::init() _indentStep = 2; _numIndicesPerLine = 10; _pathNameHint = AS_IS; + _outputTextureFiles = false; + _textureFileNameNumber = 0; } void Output::open(const char *name) @@ -157,3 +160,20 @@ std::string Output::getFileNameForOutput(const std::string& filename) const return filename; } } + +std::string Output::getTextureFileNameForOutput() +{ + std::string fileName = osgDB::getNameLessExtension(_filename); + if (_textureFileNameNumber>0) + { + std::ostringstream o; + o << '_' << _textureFileNameNumber; + fileName += o.str(); + } + + fileName += ".dds"; + ++_textureFileNameNumber; + + return fileName; +} + diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index ca4f877db..08b348d01 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -101,6 +101,10 @@ class OSGReaderWriter : public ReaderWriter iss >> prec; fout.precision(prec); } + if (opt=="OutputTextureFiles") + { + fout.setOutputTextureFiles(false); + } } } } @@ -111,6 +115,7 @@ class OSGReaderWriter : public ReaderWriter if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; Output fout(fileName.c_str()); + fout.setOptions(options); if (fout) { setPrecision(fout,options); @@ -125,6 +130,7 @@ class OSGReaderWriter : public ReaderWriter virtual WriteResult writeObject(const Object& obj,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const { Output foutput; + foutput.setOptions(options); std::ios &fios = foutput; fios.rdbuf(fout.rdbuf()); @@ -147,6 +153,7 @@ class OSGReaderWriter : public ReaderWriter Output fout(fileName.c_str()); + fout.setOptions(options); if (fout) { setPrecision(fout,options); @@ -161,6 +168,7 @@ class OSGReaderWriter : public ReaderWriter virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const { Output foutput; + foutput.setOptions(options); std::ios &fios = foutput; fios.rdbuf(fout.rdbuf()); diff --git a/src/osgPlugins/osg/Texture1D.cpp b/src/osgPlugins/osg/Texture1D.cpp index 39daacbc8..7b63ff03c 100644 --- a/src/osgPlugins/osg/Texture1D.cpp +++ b/src/osgPlugins/osg/Texture1D.cpp @@ -3,6 +3,7 @@ #include "osgDB/Registry" #include "osgDB/Input" #include "osgDB/Output" +#include "osgDB/WriteFile" using namespace osg; using namespace osgDB; @@ -61,9 +62,22 @@ bool Texture1D_writeLocalData(const Object& obj, Output& fw) { const Texture1D& texture = static_cast(obj); - if (texture.getImage() && !(texture.getImage()->getFileName().empty())) + if (texture.getImage()) { - fw.indent() << "file "<getFileName()))<< std::endl; + std::string fileName = texture.getImage()->getFileName(); + if (fw.getOutputTextureFiles()) + { + if (fileName.empty()) + { + fileName = fw.getTextureFileNameForOutput(); + } + osgDB::writeImageFile(*texture.getImage(), fileName); + } + + if (!fileName.empty()) + { + fw.indent() << "file "<(obj); - if (texture.getImage() && !(texture.getImage()->getFileName().empty())) + if (texture.getImage()) { - fw.indent() << "file "<getFileName()))<< std::endl; + std::string fileName = texture.getImage()->getFileName(); + if (fw.getOutputTextureFiles()) + { + if (fileName.empty()) + { + fileName = fw.getTextureFileNameForOutput(); + } + osgDB::writeImageFile(*texture.getImage(), fileName); + } + + if (!fileName.empty()) + { + fw.indent() << "file "<(obj); - if (texture.getImage() && !(texture.getImage()->getFileName().empty())) + if (texture.getImage()) { - fw.indent() << "file "<getFileName()))<< std::endl; + std::string fileName = texture.getImage()->getFileName(); + if (fw.getOutputTextureFiles()) + { + if (fileName.empty()) + { + fileName = fw.getTextureFileNameForOutput(); + } + osgDB::writeImageFile(*texture.getImage(), fileName); + } + + if (!fileName.empty()) + { + fw.indent() << "file "<getFileName().empty())) \ + if (image)\ {\ - fw.indent() << "image "<<#FACE<<" "<getFileName()<getFileName();\ + if (fw.getOutputTextureFiles())\ + {\ + if (fileName.empty())\ + {\ + fileName = fw.getTextureFileNameForOutput();\ + }\ + osgDB::writeImageFile(*image, fileName);\ + }\ + if (!fileName.empty())\ + {\ + fw.indent() << "image "<<#FACE<<" "<(obj); - if (texture.getImage() && !(texture.getImage()->getFileName().empty())) + if (texture.getImage()) { - fw.indent() << "file "<getFileName()))<< std::endl; + std::string fileName = texture.getImage()->getFileName(); + if (fw.getOutputTextureFiles()) + { + if (fileName.empty()) + { + fileName = fw.getTextureFileNameForOutput(); + } + osgDB::writeImageFile(*texture.getImage(), fileName); + } + + if (!fileName.empty()) + { + fw.indent() << "file "<