Garmaine Staff asked 2 years ago

I am writing a program to parse an stl file and read each into a structure, and then insert it into a vector. There should be 12 of these "facets".

However, when I use "myObj.facet.size()" I get the number 86. This is clearly incorrect. This is a cube that is made up two triangles per face. 6 sides on a cube * 2 = 12 I have printed out the contents of these objects and there are 12 of them, this is correct.

class Facet {
        std::vector<float> normal;
        std::vector< std::vector <float> > loop;

class Obj {
        std::string name;
        std::vector<Facet> facet;
        int load(std::string inFile);


#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>

#include "./object.hpp"

int main()
    Obj myObj;
    std::string fileName = "cube.stl";
    std::cout << "Loaded object name is : " << << std::endl;
    std::cout << "Facet has the size : " << myObj.facet.size() << std::endl;

    for(int i = 0 ; i < myObj.facet.size(); i++){
        std::cout << i << " - ";
        std::copy(myObj.facet[i].normal.begin(), myObj.facet[i].normal.end(), std::ostream_iterator<float>(std::cout, " "));
        std::cout << '\n';

    return 0;   

Because there is a significant amount code, but basic I will link to my github repo. This includes the stl file that is being parsed cube.stl, and the output in output.txt