From David Gurhrie, "Here is the updated txp loader code that we modified before to store
some of the material codes in the userdata field. It now takes an option string to enable adding the extra data and doesn't add it by default."
This commit is contained in:
@@ -54,6 +54,11 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin
|
||||
TXPArchive* archive = txpNode->getArchive();
|
||||
if (archive)
|
||||
{
|
||||
if (options && options->getOptionString().find("loadMaterialsToStateSet")!=std::string::npos)
|
||||
{
|
||||
archive->SetMaterialAttributesToStateSetVar(true);
|
||||
}
|
||||
|
||||
int id = _archiveId++;
|
||||
archive->setId(id);
|
||||
// txpNode->setArchive(getArchive(id,osgDB::getFilePath(fileName)));
|
||||
|
||||
@@ -69,7 +69,8 @@ TXPArchive::TXPArchive():
|
||||
_neExtents(0.0,0.0),
|
||||
_majorVersion(-1),
|
||||
_minorVersion(-1),
|
||||
_isMaster(false)
|
||||
_isMaster(false),
|
||||
_loadMaterialsToStateSet(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -194,6 +195,8 @@ bool TXPArchive::loadMaterial(int ix)
|
||||
osg_material->setAlpha(osg::Material::FRONT_AND_BACK ,(float)alpha);
|
||||
osg_state_set->setAttributeAndModes(osg_material, osg::StateAttribute::ON);
|
||||
|
||||
SetUserDataToMaterialAttributes(*osg_state_set, *mat);
|
||||
|
||||
if( alpha < 1.0f )
|
||||
{
|
||||
osg_state_set->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "trpage_sys.h"
|
||||
#include "trpage_read.h"
|
||||
#include "trpage_geom.h"
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osg/BoundingBox>
|
||||
@@ -43,6 +44,7 @@
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Node>
|
||||
#include <osg/PagedLOD>
|
||||
#include <osg/Array>
|
||||
#include <osgSim/LightPointNode>
|
||||
#include <osgText/Font>
|
||||
|
||||
@@ -166,7 +168,7 @@ namespace txp
|
||||
{
|
||||
return GetTexMapEntry(id).get();
|
||||
}
|
||||
|
||||
|
||||
// Returns scenegraph representing the Tile.
|
||||
// For version 2.1 and over this function can only be call
|
||||
// with lod = 0, since the archive tile table will contain
|
||||
@@ -198,7 +200,31 @@ namespace txp
|
||||
majorVer = _majorVersion;
|
||||
minorVer = _minorVersion;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// This section brought to you by A. Danklefsen and the team @
|
||||
// Alion Science And Technology 2/12/07
|
||||
//
|
||||
// This will allow you to have smc / fid / swc / stp values and
|
||||
// places them on the userdata of the state set. this way your own
|
||||
// terrain loader / parser can know these values
|
||||
void SetUserDataToMaterialAttributes(osg::StateSet& osg_state_set, const trpgMaterial& mat)
|
||||
{
|
||||
if(!_loadMaterialsToStateSet)
|
||||
return;
|
||||
|
||||
int attr_values = 0;
|
||||
osg::ref_ptr<osg::IntArray> ourValueArray = new osg::IntArray();
|
||||
for(int attrIter = 0 ; attrIter < 4; ++attrIter)
|
||||
{
|
||||
mat.GetAttr(attrIter, attr_values);
|
||||
ourValueArray->push_back(attr_values);
|
||||
}
|
||||
osg_state_set.setUserData(ourValueArray.get());
|
||||
}
|
||||
|
||||
void SetMaterialAttributesToStateSetVar(bool value) {_loadMaterialsToStateSet = value;}
|
||||
|
||||
protected:
|
||||
|
||||
// Destructor
|
||||
@@ -252,7 +278,9 @@ namespace txp
|
||||
int _majorVersion, _minorVersion;
|
||||
|
||||
bool _isMaster;
|
||||
|
||||
|
||||
bool _loadMaterialsToStateSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -490,7 +490,9 @@ void TXPParser::loadLocalMaterials()
|
||||
|
||||
osg_material->setAlpha(osg::Material::FRONT_AND_BACK ,(float)alpha);
|
||||
osg_state_set->setAttributeAndModes(osg_material, osg::StateAttribute::ON);
|
||||
|
||||
|
||||
_archive->SetUserDataToMaterialAttributes(*osg_state_set, *mat);
|
||||
|
||||
if( alpha < 1.0f )
|
||||
{
|
||||
osg_state_set->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
@@ -1457,16 +1459,20 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
|
||||
_parse->loadMaterial(matId);
|
||||
tmp_ss = (*_parse->getMaterials())[matId];
|
||||
}
|
||||
if((sset!=0L) && sset.valid())
|
||||
if(sset.valid())
|
||||
{
|
||||
if(tmp_ss.valid())
|
||||
{
|
||||
{
|
||||
osg::StateAttribute* texenv0 = tmp_ss->getTextureAttribute(0,osg::StateAttribute::TEXENV);
|
||||
if(texenv0)
|
||||
sset->setTextureAttribute(n_mat,texenv0);
|
||||
osg::StateAttribute* tex0 = tmp_ss->getTextureAttribute(0,osg::StateAttribute::TEXTURE);
|
||||
if(tex0)
|
||||
sset->setTextureAttributeAndModes(n_mat,tex0,osg::StateAttribute::ON);
|
||||
// submitted by a. danklefsen
|
||||
// Alion science and Technology 2/12/07
|
||||
// copy fid/smc codes over to this new state set from the prev state set.
|
||||
sset->setUserData(tmp_ss->getUserData());
|
||||
}
|
||||
// sset->merge(*tmp_ss.get());
|
||||
}
|
||||
@@ -1601,7 +1607,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Detected potential memory leak in TXPParerse.cpp"<<std::endl;
|
||||
osg::notify(osg::WARN)<<"Detected potential memory leak in TXPParser.cpp"<<std::endl;
|
||||
}
|
||||
|
||||
return (void *) 1;
|
||||
|
||||
Reference in New Issue
Block a user