From Alberto Farre:

"Here there are fixes for several flt loader problems.

First one was an small bug when root database was an empty string we got a database path "/" instead of "./".
Second one is more complex. Flt loader works in two passes, first one reads flt database and second one builds osg scenegraph. Special care must be taken for properly tracking database path as nested files are entered. Because textures are loaded in second pass, mentioned care should be taken once again. I wrote time ago a piece of code and I placed it in both files fltFile.cpp and flt2osg.cpp. After a long period offline I have seen the portion of code at flt2osg was missing, I just made some tests and I could see it is still required.

Finally, I have seen that pool.cpp always try to make IMAGE cache instead of reading what Options says.

Aditonally, I recently wrote an osg change, now it has external references "a la flt" what is called osg::ProxyNode. As part of the change now flt loader builds external references as ProxyNodes. I made the same mistake like pool.cpp and always made ARCHIVE cache instead of see what Options says, it has also been fixed."
This commit is contained in:
Robert Osfield 2005-04-04 11:18:02 +00:00
parent aa8dbea11c
commit d9828731d8
3 changed files with 115 additions and 77 deletions

View File

@ -81,8 +81,8 @@ FltFile::FltFile(
}
else
{
// If they aren't both set, then they must both be NULL.
assert( (pLtPtAppearancePool==NULL) && (pLtPtAppearancePool==NULL) );
// If they aren't both set, then they must both be NULL.
assert( (pLtPtAppearancePool==NULL) && (pLtPtAppearancePool==NULL) );
// use internal light point palettes
_useInternalLtPtPalettes = true;
setLtPtAppearancePool( new LtPtAppearancePool );
@ -225,10 +225,10 @@ bool FltFile::readFile(const std::string& fileName)
if (rec.getFlightVersion() >= 1580)
{
if (!(pSExternal->dwFlags & ExternalRecord::LIGHT_POINT_PALETTE_OVERRIDE))
{
{
pLtPtAppearancePool = _pFltFile->getLtPtAppearancePool();
pLtPtAnimationPool = _pFltFile->getLtPtAnimationPool();
}
}
}
}
@ -244,8 +244,7 @@ bool FltFile::readFile(const std::string& fileName)
{
osg::ref_ptr<osgDB::ReaderWriter::Options> options =
_pFltFile->getOptions() ? _pFltFile->getOptions() :
new osgDB::ReaderWriter::Options;
new osgDB::ReaderWriter::Options;
//Path for Nested external references
osgDB::FilePathList& fpl = options->getDatabasePathList();
const std::string& filePath = osgDB::getFilePath(filename);
@ -258,7 +257,7 @@ bool FltFile::readFile(const std::string& fileName)
}
else
{
pushAndPopPath = (fpl.empty() ? "." : fpl.back()) + "/" + filePath;
pushAndPopPath = (fpl.empty() | fpl.back().empty() ? "." : fpl.back()) + "/" + filePath;
}
char optionsString[256];
@ -279,6 +278,8 @@ bool FltFile::readFile(const std::string& fileName)
}
pExternalFltFile->readModel(filename);
fpl.pop_back();
}
rec.setExternal(pExternalFltFile);
@ -348,3 +349,4 @@ std::string FltFile::getDesiredUnitsString() const
}
}

View File

@ -128,75 +128,82 @@ flt::AttrData* TexturePool::getTexture(int nIndex, osgDB::ReaderWriter::Options*
if (nitr != _textureNameMap.end())
{
const std::string& textureName = (*nitr).second;
flt::AttrData* textureAttrData = 0;
// Valid index, find the texture
// Get AttrData containing texture from registry pool.
flt::AttrData* textureAttrData = Registry::instance()->getTexture(textureName);
if (textureAttrData)
if(options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_IMAGES)
{
// Add texture to local pool to be ab121le to get by index.
addTexture(nIndex, textureAttrData);
// Valid index, find the texture
// Get AttrData containing texture from registry pool.
textureAttrData = Registry::instance()->getTexture(textureName);
if (textureAttrData)
{
// Add texture to local pool to be ab121le to get by index.
addTexture(nIndex, textureAttrData);
return textureAttrData;
}
}
CERR<<"setTexture attempting to load ("<<textureName<<")"<<std::endl;
unsigned int unit = 0;
// Read texture and attribute file
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(textureName, options ? options : osgDB::Registry::instance()->getOptions());
if (image.valid())
{
std::string attrName(textureName);
attrName += ".attr";
textureAttrData = dynamic_cast<flt::AttrData*>(osgDB::readObjectFile(attrName, options ? options : osgDB::Registry::instance()->getOptions() ));
// if not found create default StateSet for the AttrData
if (textureAttrData == NULL)
{
textureAttrData = new flt::AttrData;
textureAttrData->stateset = new osg::StateSet;
osg::Texture2D* osgTexture = new osg::Texture2D;
osgTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
osgTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
textureAttrData->stateset->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
osg::TexEnv* osgTexEnv = new osg::TexEnv;
osgTexEnv->setMode(osg::TexEnv::MODULATE);
textureAttrData->stateset->setTextureAttribute( unit, osgTexEnv );
}
osg::Texture2D *osgTexture = dynamic_cast<osg::Texture2D*>(textureAttrData->stateset->getTextureAttribute( unit, osg::StateAttribute::TEXTURE));
if (osgTexture == NULL)
{
osgTexture = new osg::Texture2D;
textureAttrData->stateset->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
}
osgTexture->setImage(image.get());
}
else
{
CERR<<"setTexture attempting to load ("<<textureName<<")"<<std::endl;
unsigned int unit = 0;
// Read texture and attribute file
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(textureName, options ? options : osgDB::Registry::instance()->getOptions());
if (image.valid())
{
std::string attrName(textureName);
attrName += ".attr";
textureAttrData = dynamic_cast<flt::AttrData*>(osgDB::readObjectFile(attrName, options ? options : osgDB::Registry::instance()->getOptions() ));
// if not found create default StateSet for the AttrData
if (textureAttrData == NULL)
{
textureAttrData = new flt::AttrData;
textureAttrData->stateset = new osg::StateSet;
osg::Texture2D* osgTexture = new osg::Texture2D;
osgTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
osgTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
textureAttrData->stateset->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
osg::TexEnv* osgTexEnv = new osg::TexEnv;
osgTexEnv->setMode(osg::TexEnv::MODULATE);
textureAttrData->stateset->setTextureAttribute( unit, osgTexEnv );
}
osg::Texture2D *osgTexture = dynamic_cast<osg::Texture2D*>(textureAttrData->stateset->getTextureAttribute( unit, osg::StateAttribute::TEXTURE));
if (osgTexture == NULL)
{
osgTexture = new osg::Texture2D;
textureAttrData->stateset->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
}
osgTexture->setImage(image.get());
}
else
{
// invalid image file, register an empty state set AttrData
textureAttrData = new flt::AttrData;
textureAttrData->stateset = new osg::StateSet;
}
// Add new texture to registry pool
// ( umm... should this have reference to the texture unit? RO. July2002)
Registry::instance()->addTexture(textureName, textureAttrData);
// Also add to local pool to be able to get texture by index.
// ( umm... should this have reference to the texture unit? RO. July2002)
addTexture(nIndex, textureAttrData);
CERR<<"Registry::instance()->addTexture("<<textureName<<", "<<textureAttrData<<")"<<std::endl;
CERR<<"pTexturePool->addTexture("<<nIndex<<", "<<textureAttrData<<")"<<std::endl;
// invalid image file, register an empty state set AttrData
textureAttrData = new flt::AttrData;
textureAttrData->stateset = new osg::StateSet;
}
// Add new texture to registry pool
// ( umm... should this have reference to the texture unit? RO. July2002)
if(options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_IMAGES)
{
Registry::instance()->addTexture(textureName, textureAttrData);
}
// Also add to local pool to be able to get texture by index.
// ( umm... should this have reference to the texture unit? RO. July2002)
addTexture(nIndex, textureAttrData);
CERR<<"Registry::instance()->addTexture("<<textureName<<", "<<textureAttrData<<")"<<std::endl;
CERR<<"pTexturePool->addTexture("<<nIndex<<", "<<textureAttrData<<")"<<std::endl;
return textureAttrData;
}
@ -317,3 +324,4 @@ LtPtAnimationPool::add(int nIndex, PoolLtPtAnimation* anim)

View File

@ -2431,15 +2431,38 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
osg::Group* external = NULL;
if (pFile)
{
//Path for Nested external references
osgDB::ReaderWriter::Options *options = pFile->getOptions();
#ifdef USE_PROXYNODE_FOR_EXTERNAL_FILES
external = dynamic_cast<osg::Group*> (osgDB::Registry::instance()->getFromObjectCache(rec->getFilename()));
if(external)
if(options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES)
{
osg::Group *tempParent = visitAncillary(osgParent, *external, rec);
tempParent->addChild(external);
return external;
external = dynamic_cast<osg::Group*> (osgDB::Registry::instance()->getFromObjectCache(rec->getFilename()));
if(external)
{
osg::Group *tempParent = visitAncillary(osgParent, *external, rec);
tempParent->addChild(external);
return external;
}
}
#endif
osgDB::FilePathList& fpl = options->getDatabasePathList();
const std::string& filePath = osgDB::getFilePath(rec->getFilename());
std::string pushAndPopPath;
//If absolute path
if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) ||
(filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) )
{
pushAndPopPath = filePath;
}
else
{
pushAndPopPath = (fpl.empty() | fpl.back().empty() ? "." : fpl.back()) + "/" + filePath;
}
fpl.push_back(pushAndPopPath);
pFile->setDesiredUnits( rec->getFltFile()->getDesiredUnits() );
external = pFile->convert();
if (external)
@ -2467,7 +2490,8 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
proxynode->setCenterMode(osg::ProxyNode::USE_BOUNDING_SPHERE_CENTER);
proxynode->addChild(external, rec->getFilename());
tempParent->addChild(proxynode);
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), proxynode);
if(options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES)
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), proxynode);
#else
tempParent->addChild(external);
#endif
@ -2486,7 +2510,8 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
proxynode->setCenterMode(osg::ProxyNode::USE_BOUNDING_SPHERE_CENTER);
proxynode->addChild(model, rec->getFilename());
tempParent->addChild(proxynode);
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), proxynode);
if(options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES)
osgDB::Registry::instance()->addEntryToObjectCache(rec->getFilename(), proxynode);
#else
//tempParent->addChild(model);
#endif
@ -2500,6 +2525,8 @@ osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord*
}
}
}
fpl.pop_back();
}
return external;
}
@ -3272,3 +3299,4 @@ void ConvertFromFLT::setMeshTexCoordinates ( const uint32 &numVerts, const Local
return;
}