查看: 717|回复: 1

请教读写之后无纹理的问题

[复制链接]

该用户从未签到

发表于 2019-12-3 11:49:34 | 显示全部楼层 |阅读模式
我这边在做一个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;
        }
0.jpg
1.jpg

该用户从未签到

发表于 2019-12-15 10:12:45 | 显示全部楼层
纹理坐标是怎么设置的?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表