Added creation of image directories when required

This commit is contained in:
Robert Osfield 2020-01-11 14:39:46 +00:00
parent 7b5eac73c8
commit fb1dff845f
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

@ -445,8 +445,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);
}
}
}