Changeset 6296

Show
Ignore:
Timestamp:
03/01/07 13:10:52
Author:
robert
Message:

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."

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/src/osgPlugins/txp/ReaderWriterTXP.cpp

    r6291 r6296  
    5555            if (archive)  
    5656            { 
     57                if (options && options->getOptionString().find("loadMaterialsToStateSet")!=std::string::npos) 
     58                { 
     59                   archive->SetMaterialAttributesToStateSetVar(true); 
     60                } 
     61 
    5762                int id = _archiveId++; 
    5863                archive->setId(id); 
  • OpenSceneGraph/trunk/src/osgPlugins/txp/TXPArchive.cpp

    r6291 r6296  
    7070    _majorVersion(-1), 
    7171    _minorVersion(-1), 
    72     _isMaster(false) 
     72    _isMaster(false), 
     73    _loadMaterialsToStateSet(false) 
    7374{ 
    7475} 
     
    195196        osg_state_set->setAttributeAndModes(osg_material, osg::StateAttribute::ON); 
    196197         
     198        SetUserDataToMaterialAttributes(*osg_state_set, *mat); 
     199 
    197200        if( alpha < 1.0f ) 
    198201        { 
  • OpenSceneGraph/trunk/src/osgPlugins/txp/TXPArchive.h

    r6291 r6296  
    3737#include "trpage_sys.h" 
    3838#include "trpage_read.h" 
     39#include "trpage_geom.h" 
    3940 
    4041#include <osg/Referenced> 
     
    4445#include <osg/Node> 
    4546#include <osg/PagedLOD> 
     47#include <osg/Array> 
    4648#include <osgSim/LightPointNode> 
    4749#include <osgText/Font> 
     
    167169        return GetTexMapEntry(id).get(); 
    168170    } 
    169      
     171    
    170172    // Returns scenegraph representing the Tile. 
    171173    // For version 2.1 and over this function can only be call 
     
    199201        minorVer = _minorVersion; 
    200202    } 
    201          
     203    
     204   ////////////////////////////////////////////////////////////////// 
     205   // This section brought to you by A. Danklefsen and the team @ 
     206   // Alion Science And Technology 2/12/07 
     207   // 
     208   // This will allow you to have smc / fid / swc / stp values and  
     209   // places them on the userdata of the state set. this way your own 
     210   // terrain loader / parser can know these values 
     211   void SetUserDataToMaterialAttributes(osg::StateSet& osg_state_set, const trpgMaterial& mat) 
     212   { 
     213      if(!_loadMaterialsToStateSet) 
     214         return;  
     215 
     216      int attr_values = 0; 
     217      osg::ref_ptr<osg::IntArray> ourValueArray = new osg::IntArray(); 
     218      for(int attrIter = 0 ; attrIter < 4; ++attrIter) 
     219      { 
     220         mat.GetAttr(attrIter, attr_values); 
     221         ourValueArray->push_back(attr_values); 
     222      } 
     223      osg_state_set.setUserData(ourValueArray.get()); 
     224   } 
     225 
     226   void SetMaterialAttributesToStateSetVar(bool value) {_loadMaterialsToStateSet = value;} 
     227 
    202228    protected: 
    203229 
     
    253279 
    254280    bool _isMaster; 
    255      
     281    
     282    bool _loadMaterialsToStateSet; 
     283 
    256284    }; 
    257285 
  • OpenSceneGraph/trunk/src/osgPlugins/txp/TXPParser.cpp

    r6291 r6296  
    491491            osg_material->setAlpha(osg::Material::FRONT_AND_BACK ,(float)alpha); 
    492492            osg_state_set->setAttributeAndModes(osg_material, osg::StateAttribute::ON); 
    493              
     493 
     494            _archive->SetUserDataToMaterialAttributes(*osg_state_set, *mat); 
     495 
    494496            if( alpha < 1.0f ) 
    495497            { 
     
    14581460                tmp_ss = (*_parse->getMaterials())[matId]; 
    14591461            } 
    1460             if((sset!=0L) && sset.valid())  
     1462            if(sset.valid())  
    14611463            { 
    14621464                if(tmp_ss.valid()) 
    1463        
     1465                 
    14641466                    osg::StateAttribute* texenv0 = tmp_ss->getTextureAttribute(0,osg::StateAttribute::TEXENV); 
    14651467                    if(texenv0)  
     
    14681470                    if(tex0)  
    14691471                        sset->setTextureAttributeAndModes(n_mat,tex0,osg::StateAttribute::ON); 
     1472                    // submitted by a. danklefsen 
     1473                    // Alion science and Technology 2/12/07 
     1474                    // copy fid/smc codes over to this new state set from the prev state set. 
     1475                    sset->setUserData(tmp_ss->getUserData()); 
    14701476                } 
    14711477//                sset->merge(*tmp_ss.get()); 
     
    16021608    else 
    16031609    { 
    1604         osg::notify(osg::WARN)<<"Detected potential memory leak in TXPParerse.cpp"<<std::endl; 
     1610        osg::notify(osg::WARN)<<"Detected potential memory leak in TXPParser.cpp"<<std::endl; 
    16051611    } 
    16061612