You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.3 KiB

#include "STLMesh.h"
#include "Mesh.h"
#include <fstream>
#include <iostream>
#include "ExternalLib/glm/glm.hpp"
/******************
* Constructors *
******************/
STLMesh::STLMesh()
{}
STLMesh::STLMesh(std::string filePath)
{
// Populate STLMesh from a .stl file
std::string input;
glm::vec3 position, normal;
std::ifstream file(filePath);
if ( !file.is_open())
{
std::cerr << "Couldn't open " << filePath << std::endl;
exit(4);
}
std::getline(file, input); // skip header
while( file.good() )
{
// skip "facet" & "normal"
file >> input; file >> input;
// get normal
file >> normal.x; file >> normal.y; file >> normal.z;
// skip "outer" & "loop"
file >> input; file >> input;
// get verices
for(int i=0; i<3; i++)
{
//skip "vertex"
file >> input;
// set vertices x,y,z
file >> position.x; file >> position.y; file >> position.z;
// Push informations into "vertices" ( ! WARNING : ONE NORMAL PER FACET ! )
vertices.push_back({position, normal});
}
//skip "endloop" & "endfacet"
file >> input; file >> input;
}
file.close();
}