|
我想把模型的所有的纹理名称变换一下,先得到texture2D,然后将符合的纹理读取并赋予,这样的话每次的内存都会增加,根据王锐老师《osg指南》里面说法采用了 setUnRefImageDataAfterApply ,还是不对,现贴代码如下,请各位老师指教。还有程序不合理之处也请指出,麻烦各位了。
-
- for (unsigned int i = 0; i <texSize; i++)
- {
- osg::ref_ptr<osg::Texture2D> texture =dynamic_cast<osg::Texture2D*>(pStateSet->getTextureAttribute(i,osg::StateAttribute::TEXTURE));
-
- unsigned int nImages = texture->getNumImages();
- for (unsigned int j = 0; j < nImages; j++)
- {
- std::string imageName=texture->getImage(j)->getFileName();
- std::vector<Name_PP>::const_iterator iter=_Name_PP->begin();
- while(iter!=_Name_PP->end())
- {
- if(imageName==iter->imgName.c_str())
- {
- std::string temp=fileName.substr(0,fileName.size()-3);
- temp=temp.append("jpg");
- osg::ref_ptr<osg::Image> pImage=new osg::Image;
- pImage=osgDB::readImageFile(temp);
- if(!pImage)
- return false;
- pImage->setFileName(temp);
- texture->setImage(pImage);
-
- }
- iter++;
- }
- }
- pGeometry->setTexCoordArray(0,TexCoor);
-
- texture->setUnRefImageDataAfterApply(true);
- }
复制代码 |
|