Added creation of image directories when required

This commit is contained in:
Robert Osfield 2020-01-11 14:39:46 +00:00
parent 61c7ee76c5
commit 457d12d9b2
2 changed files with 15 additions and 1 deletions

View File

@ -495,6 +495,12 @@ void OutputStream::writeImage( const osg::Image* img )
imageFileName = "image.dds";
}
std::string imagePath = osgDB::getFilePath(imageFileName);
if (!imagePath.empty() && !osgDB::fileExists(imagePath))
{
osgDB::makeDirectory(imagePath);
}
bool result = osgDB::writeImageFile( *img, imageFileName );
OSG_NOTICE << "OutputStream::writeImage(): Write image data to external file " << imageFileName << std::endl;
if ( !result )

View File

@ -446,8 +446,16 @@ OBJWriterNodeVisitor::OBJMaterial::OBJMaterial(osg::Material* mat, osg::Texture*
if ((img) && (!img->getFileName().empty()))
{
image = img->getFileName();
if(outputTextureFiles)
if (outputTextureFiles)
{
std::string imagePath = osgDB::getFilePath(image);
if (!imagePath.empty() && !osgDB::fileExists(imagePath))
{
osgDB::makeDirectory(imagePath);
}
osgDB::writeImageFile(*img, image, options);
}
}
}