coolbear

读取二进制格式的STL模型文件

std::ifstream fin;
fin.open(stlFilePath, std::ios::in | std::ios::binary);
bool isBinary=true;//判断stl是否是二进制流文件
fin.seekg(0, std::ios::end);
std::streamoff stlFileSize=fin.tellg();//文件大小
char buf[4];
fin.seekg(80, std::ios::beg);
fin.read(buf, 4);
int triNum=*(int*)(buf);//三角面个数
if ((80+4+triNum*50)!=stlFileSize)
{
 isBinary=false;
}
//一个STL里面的facet占50个字节
float normal[3];//三角面法向量3*sizeof(float)=12字节
float v1[3]; //第一个顶点3*sizeof(float)=12字节
float v2[3]; //第二个顶点3*sizeof(float)=12字节
float v3[3]; //第三个顶点3*sizeof(float)=12字节
short attribute;//2字节,属性信息(暂未使用)
for (int meshId=0; meshId<triNum; meshId++)
{
fin.read((char*)normal, 12);
fin.read((char*)v1, 12);
fin.read((char*)v2, 12);
fin.read((char*)v3, 12);
fin.read((char*)&attribute, sizeof(short));
}

分类:

技术点:

相关文章:

  • 2021-11-15
  • 2021-09-05
  • 2021-08-08
  • 2022-02-17
  • 2022-02-21
  • 2021-10-04
猜你喜欢
  • 2021-12-17
  • 2022-12-23
  • 2021-11-30
  • 2021-07-23
  • 2022-12-23
  • 2021-11-09
  • 2021-12-27
相关资源
相似解决方案