|
本帖最后由 一大波蓝猫 于 2013-7-2 15:28 编辑
读取了一个obj文件 获得点云坐标和面的信息 有对应的彩色图像 还有点的索引(即纹理坐标) 然后用如下代码进行纹理映射 因为三角网格比较粗糙 有地方没有三角形 所以纹理映射的结果 有空洞 请问如何能把这些洞也补上 就是用响应的彩色图像填充上呢 求指导 谢谢- ifstream objFile("./data/triangle.obj");
- string strLine;
- string s1;
- float xin, yin, zin;
- int v1, v2, v3;
- int temp = 0, tempMap = 0, nTri = 0;
- geometry->setVertexArray(triVertexs); //设置顶点数组
- geometry->setTexCoordArray(0, tc.get()); //设置纹理坐标数组
- geometry->setNormalArray(nc.get());
- geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
- while(getline(objFile, strLine)){
- if(strLine[0] == 'v'){ //读取点云数据
- temp++;
- stringstream sin(strLine);
- sin>>s1>>xin>>yin>>zin;
- //读点云的索引
- if(xin != 0.0 || yin != 0.0 || zin != 0.0){
- pointCloudMap.insert(pair<osg::Vec3, int>(osg::Vec3(xin, yin, zin), pointCloudIndex[tempMap]));
- coords->push_back(osg::Vec3(xin, yin, zin)); //设置点云坐标
- int texIndex = vertexIndex[tempMap] - 1;
- objIndexMap.insert(pair<int, osg::Vec3>(vertexIndex[tempMap], osg::Vec3(xin, yin, zin)));
- tempMap++;
- }
- }else if(strLine[0] == 'f'){ //读取拓扑连接关系
- stringstream sin(strLine);
- sin>>s1>>v1>>v2>>v3;
- triVertexs->push_back(objIndexMap[v1]);
- triVertexs->push_back(objIndexMap[v2]);
- triVertexs->push_back(objIndexMap[v3]);
- int i1 = pointCloudMap[objIndexMap[v1]];
- int i2 = pointCloudMap[objIndexMap[v2]];
- int i3 = pointCloudMap[objIndexMap[v3]];
- tc->push_back(osg::Vec2(i1%(int)width, (int)height-1-(int)(i1/width))); //设置纹理坐标
- tc->push_back(osg::Vec2(i2%(int)width, (int)height-1-(int)(i2/width)));
- tc->push_back(osg::Vec2(i3%(int)width, (int)height-1-(int)(i3/width)));
- geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,nTri*3,3));//添加三角形
- nTri++;
- }
- }
- objFile.close();
复制代码 运行效果如图
|
|