static void parse_vertex(const string& data,
         vector<Vertex>& vertices_buffer,
         const vector<vec3>& vertex,
         const vector<vec3>& normal,
         const vector<vec2>& tex)
   {
      vector<string> vertices = String::split(data, " ");
      if (vertices.size() > 3)
         vertices.resize(3);

      vector<vector<string> > verts;
      for (unsigned i = 0; i < vertices.size(); i++)
      {
         Vertex out_vertex;

         vector<string> coords = String::split(vertices[i], "/", true);
         if (coords.size() == 1) // Vertex only
         {
            size_t coord = translate_index(String::stoi(coords[0]), vertex.size());

            if (coord && vertex.size() >= coord)
               out_vertex.vert = vertex[coord - 1];
         }
         else if (coords.size() == 2) // Vertex/Texcoord
         {
            size_t coord_vert = translate_index(String::stoi(coords[0]), vertex.size());
            size_t coord_tex  = translate_index(String::stoi(coords[1]), tex.size());

            if (coord_vert && vertex.size() >= coord_vert)
               out_vertex.vert = vertex[coord_vert - 1];
            if (coord_tex && tex.size() >= coord_tex)
               out_vertex.tex = tex[coord_tex - 1];
         }
         else if (coords.size() == 3 && coords[1].size()) // Vertex/Texcoord/Normal
         {
            size_t coord_vert   = translate_index(String::stoi(coords[0]), vertex.size());
            size_t coord_tex    = translate_index(String::stoi(coords[1]), tex.size());
            size_t coord_normal = translate_index(String::stoi(coords[2]), normal.size());

            if (coord_vert && vertex.size() >= coord_vert)
               out_vertex.vert = vertex[coord_vert - 1];
            if (coord_tex && tex.size() >= coord_tex)
               out_vertex.tex = tex[coord_tex - 1];
            if (coord_normal && normal.size() >= coord_normal)
               out_vertex.normal = normal[coord_normal - 1];
         }
         else if (coords.size() == 3 && !coords[1].size()) // Vertex//Normal
         {
            size_t coord_vert   = translate_index(String::stoi(coords[0]), vertex.size());
            size_t coord_normal = translate_index(String::stoi(coords[2]), normal.size());

            if (coord_vert && vertex.size() >= coord_vert)
               out_vertex.vert = vertex[coord_vert - 1];
            if (coord_normal && normal.size() >= coord_normal)
               out_vertex.normal = normal[coord_normal - 1];
         }

         vertices_buffer.push_back(out_vertex);
      }
   }
Beispiel #2
0
/* Retorna un element cargado como el registro con value index */
Element *load_register(int index) {
	Element *e = (Element *)malloc(sizeof(Element));
	e->code = REGISTRO;
	e->value = index;
	char *aux = malloc(sizeof(char)*3);
	aux = translate_index(index);
	e->name = aux;
	
	return e;
}