Check existence of path before reading image
When loading texture images inside the FBX plugin check that the path exists before trying to read the image. This is done to avoid unnecessary warnings inside the readRefImageFile function.
This commit is contained in:
parent
13d56b8b37
commit
645704dfd3
@ -169,16 +169,37 @@ StateSetContent FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbx
|
|||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const FbxFileTexture* fbx)
|
osg::ref_ptr<osg::Texture2D> FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const FbxFileTexture* fbx)
|
||||||
{
|
{
|
||||||
ImageMap::iterator it = _imageMap.find(fbx->GetFileName());
|
// Try to find image in cache
|
||||||
|
ImageMap::iterator it = _imageMap.find(fbx->GetFileName());
|
||||||
if (it != _imageMap.end())
|
if (it != _imageMap.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
osg::ref_ptr<osg::Image> pImage = NULL;
|
|
||||||
|
|
||||||
// Warning: fbx->GetRelativeFileName() is relative TO EXECUTION DIR
|
// Try to locate valid filename
|
||||||
// fbx->GetFileName() is as stored initially in the FBX
|
std::string filename = "";
|
||||||
if ((pImage = osgDB::readRefImageFile(osgDB::concatPaths(_dir, fbx->GetFileName()), _options)) || // First try "export dir/name"
|
|
||||||
(pImage = osgDB::readRefImageFile(fbx->GetFileName(), _options)) || // Then try "name" (if absolute)
|
// Warning: fbx->GetRelativeFileName() is relative TO EXECUTION DIR
|
||||||
(pImage = osgDB::readRefImageFile(osgDB::concatPaths(_dir, fbx->GetRelativeFileName()), _options))) // Else try "current dir/name"
|
// fbx->GetFileName() is as stored initially in the FBX
|
||||||
|
if (osgDB::fileExists(osgDB::concatPaths(_dir, fbx->GetFileName()))) // First try "export dir/name"
|
||||||
|
{
|
||||||
|
filename = osgDB::concatPaths(_dir, fbx->GetFileName());
|
||||||
|
}
|
||||||
|
else if (osgDB::fileExists(fbx->GetFileName())) // Then try "name" (if absolute)
|
||||||
|
{
|
||||||
|
filename = fbx->GetFileName();
|
||||||
|
}
|
||||||
|
else if (osgDB::fileExists(osgDB::concatPaths(_dir, fbx->GetRelativeFileName()))) // Else try "current dir/name"
|
||||||
|
{
|
||||||
|
filename = osgDB::concatPaths(_dir, fbx->GetRelativeFileName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSG_WARN << "Could not find valid file for " << fbx->GetFileName() << std::endl;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::Image> pImage = osgDB::readRefImageFile(filename, _options);
|
||||||
|
if (pImage.valid())
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Texture2D> pOsgTex = new osg::Texture2D;
|
osg::ref_ptr<osg::Texture2D> pOsgTex = new osg::Texture2D;
|
||||||
pOsgTex->setImage(pImage.get());
|
pOsgTex->setImage(pImage.get());
|
||||||
|
Loading…
Reference in New Issue
Block a user