c++编译STL文件反转其法线

 

项目场景:

利用c++编译STL反转法线


问题描述:

STL格式模型如何生成,如何反转法线,反转之后模型有什么变化


原因分析:

可适用于STL文件格式底层学习


解决方案:

#include 

#include 

#include 

#include

using namespace std;

 

int main()

{

ifstream in("F:\\VScunfang\\inlet.stl"); //txt文件与源代码要在一个文件夹内

string filename;

string line;

string temp;

vector<string>  m_vec;

if (in) // 有该文件

{

while (getline(in, line)) // line中不包括每行的换行符

{

m_vec.push_back(line); //读取每一行并保存到容器中

}

 

//反转法线方向

ofstream ofs;

ofs.open("F:\\VScunfang\\inlet反转法线.stl", ios::out);

//交换坐标并输出

ofs << "solid C47C" << endl;

for (int i = 2; i < m_vec.size(); i = i + 7)

{

ofs << "facet normal 0 0 1" << endl;

temp = m_vec[i+2];

m_vec[i+2] = m_vec[i+3];

m_vec[i+3] = temp;

for (int j= i; j < i+6; j++)

{

ofs << m_vec[j] << "  " << endl;

cout << m_vec[j] << "" << endl;

}

}

ofs << "endsolid C47C" << endl;

}

else // 没有该文件

{

cout << "no such file" << endl;

}

 

return 0;

}

你可能感兴趣的:(STL,c++,linux)