Added support for "-O OutputTextureFiles" options string in .osg plugin to

allow texture files to be written out when writing out a .osg file.
This commit is contained in:
Robert Osfield 2005-09-19 14:07:44 +00:00
parent ea1ea88a17
commit d1108ea862
9 changed files with 121 additions and 15 deletions

View File

@ -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;

View File

@ -16,11 +16,10 @@
#include <osg/Object>
#include <osgDB/Export>
#include <osgDB/ReaderWriter>
#include <string>
#include <map>
#include <fstream>
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<const ReaderWriter::Options> _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;
};

View File

@ -16,6 +16,7 @@
#include <osg/Notify>
#include <sstream>
#include <stdio.h>
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;
}

View File

@ -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());

View File

@ -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<const Texture1D&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
if (texture.getImage())
{
fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(texture.getImage()->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 "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;
}
}
return true;

View File

@ -3,6 +3,7 @@
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
#include "osgDB/WriteFile"
using namespace osg;
using namespace osgDB;
@ -65,14 +66,26 @@ bool Texture2D_readLocalData(Object& obj, Input& fr)
return iteratorAdvanced;
}
bool Texture2D_writeLocalData(const Object& obj, Output& fw)
{
const Texture2D& texture = static_cast<const Texture2D&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
if (texture.getImage())
{
fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(texture.getImage()->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 "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;
}
}
return true;

View File

@ -3,6 +3,7 @@
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
#include "osgDB/WriteFile"
using namespace osg;
using namespace osgDB;
@ -56,14 +57,26 @@ bool Texture3D_readLocalData(Object& obj, Input& fr)
return iteratorAdvanced;
}
bool Texture3D_writeLocalData(const Object& obj, Output& fw)
{
const Texture3D& texture = static_cast<const Texture3D&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
if (texture.getImage())
{
fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(texture.getImage()->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 "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;
}
}
return true;

View File

@ -3,6 +3,7 @@
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
#include "osgDB/WriteFile"
using namespace osg;
using namespace osgDB;
@ -60,9 +61,21 @@ bool TextureCubeMap_readLocalData(Object& obj, Input& fr)
#define WRITE_IMAGE(FACE) \
{\
const osg::Image* image = texture.getImage(osg::TextureCubeMap::FACE);\
if (image && !(image->getFileName().empty())) \
if (image)\
{\
fw.indent() << "image "<<#FACE<<" "<<image->getFileName()<<std::endl;\
std::string fileName = image->getFileName();\
if (fw.getOutputTextureFiles())\
{\
if (fileName.empty())\
{\
fileName = fw.getTextureFileNameForOutput();\
}\
osgDB::writeImageFile(*image, fileName);\
}\
if (!fileName.empty())\
{\
fw.indent() << "image "<<#FACE<<" "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;\
}\
}\
}

View File

@ -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 TextureRectangle_writeLocalData(const Object& obj, Output& fw)
{
const TextureRectangle& texture = static_cast<const TextureRectangle&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
if (texture.getImage())
{
fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(texture.getImage()->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 "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;
}
}
return true;