|
我这边在做一个OSG顶点读写的实验,读写完成之后我的纹理没有了,百思不得其解,烦请各位路过的高手帮忙看看
代码如下:
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> root = new osg::Group; //根文件
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(AllFilePath[i].GetString());
osg::ref_ptr<osg::MatrixTransform> mt1 = new osg::MatrixTransform();
osg::Matrix m;
m.makeTranslate(osg::Vec3(10.0f, 0.0f, 0.0f));
mt1->setMatrix(m);
mt1->addChild(node.get());
//root->addChild(mt1.get());
InfoVisitor infoVisitor;
infoVisitor.apply(*node);
if (singleFile(node))
{
continue;
}
//singlefile函数
if(osg::Geode* geode = dynamic_cast<osg::Geode*>(node))
{
unsigned int nDrawable = geode->getNumDrawables();
int cnt = 0;
for (unsigned int j = 0; j<nDrawable; j++)
{
osg::Geometry *geom = dynamic_cast<osg::Geometry *>(geode->getDrawable(j));
if (!geom)
{
CopyFile(FilePath, name, TRUE);
return FALSE;
}
// 更改顶点坐标
osg::Vec3Array *vx = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
if (vx == 0L) continue;
osg::Vec3Array * pVertexArray = new osg::Vec3Array;
osg::Vec3 v(0, 0, 0);
osg::Vec3Array::iterator coord_index = vx->begin();
while (coord_index != vx->end())
{
v = *(coord_index++);
//提取该点的坐标,x,y
double x1 = v._v[0];
double y1 = v._v[1];
int tx1 = (int)x1;
int ty1 = (int)y1;
x1 = (double)tx1;
y1 = (double)ty1;
//修改坐标
v._v[0] = x1;// 修改x值
v._v[1] = y1;// 修改y值
cnt++;
pVertexArray->push_back(v);
}
geom->setVertexArray(pVertexArray);
}
//写入文件
osgDB::writeNodeFile(*node,writeFile);
//osgDB::Registry::instance()->writeNode(*node, mmm, osgDB::Registry::instance()->getOptions());
fclose(fpWrite);
fclose(fpWrite2);
return TRUE;
}
else
{
CopyFile(FilePath, name, TRUE);
return FALSE;
}
|
-
-
|