<commit_before>#pragma once

#include <stdexcept>
#include "../GLTransform.h"
#include "../IGLComponent.h"
#include <stdexcept>
#include <vector>
#include <map>

struct texCoord {
	texCoord(float u, float v = 0.0f) : u(u), v(v) { }
	float u, v;
};

struct material {
	material() {
		ka[0] = 0.2f; ka[1] = 0.2f; ka[2] = 0.2f;
		kd[0] = 0.8f; kd[1] = 0.8f; kd[2] = 0.8f;
		ks[0] = 1.0f; ks[1] = 1.0f; ks[2] = 1.0f;
		tr = 1.0f;
		ns = 0.0f;
		illum = 1;
	}
	float ka[3];
	float kd[3];
	float ks[3];
	float tr; // Aka d
	float ns;
	int illum;
	// TODO: Add maps
	GLuint ambientMap;
	GLuint diffuseMap;
	GLuint specularMap;
};

// Helper structs for OBJ loading
// Stores unique combinations of indices
struct VertexIndices {
		unsigned int vertex;
		unsigned int normal;
		unsigned int uv;
		unsigned int color;
};

// Stores a face with all indices
struct FaceIndices {
	VertexIndices v[3];
};

class GLMesh : public Sigma::IGLComponent {
public:
    SET_COMPONENT_ID("GLMesh");
	GLMesh(const int entityID); // Ctor that sets the entity ID.
	/**
	 * \brief Creates a new IGLComponent.
	 *
	 * \param[in] int entityID The entity this component belongs to.
	 * \returns IGLCompoent* the newly created component.
	 */
	void InitializeBuffers() ;
	virtual void Render(glm::mediump_float *view, glm::mediump_float *proj);

	/**
	 * \brief Returns the number of elements to draw for this component.
	 *
	 * Call this multiple times to get the elements for each mesh group. A return of 0 indicates all
	 * mesh groups have been returned, and the call loop should end.
	 * \param[in] const unsigned int group The mesh group to render.
	 * \returns unsigned int The number of elements to draw for the given mesh group.
	 */
	unsigned int MeshGroup_ElementCount(const unsigned int group = 0) const {
		if (group < (groupIndex.size() - 1)) {
			return (groupIndex[group+1] - groupIndex[group]) * 3;
		} else if (group > (groupIndex.size() - 1)) {
			return 0;
		} else {
			return (this->faces.size() - groupIndex[group]) * 3;
		}
	}

	void LoadMesh(std::string fname);

	void ParseMTL(std::string fname);

	/**
	 * \brief Add a vertex to the list.
	 *
	 * \param[in] const Sigma::Vertex & v The vertex to add. It is copied.
	 */
	void AddVertex(const Sigma::Vertex& v) {
		this->verts.push_back(v);
	}

	/**
	 * \brief Gets a vertex.
	 *
	 * Returns the vertex at the specific index.
	 * \param[in] const unsigned int index The index of the vertex to get.<commit_msg>Fixed an OOB issue with GLMesh::MeshGroup_ElementCount<commit_after>#pragma once

#include <stdexcept>
#include "../GLTransform.h"
#include "../IGLComponent.h"
#include <stdexcept>
#include <vector>
#include <map>

struct texCoord {
	texCoord(float u, float v = 0.0f) : u(u), v(v) { }
	float u, v;
};

struct material {
	material() {
		ka[0] = 0.2f; ka[1] = 0.2f; ka[2] = 0.2f;
		kd[0] = 0.8f; kd[1] = 0.8f; kd[2] = 0.8f;
		ks[0] = 1.0f; ks[1] = 1.0f; ks[2] = 1.0f;
		tr = 1.0f;
		ns = 0.0f;
		illum = 1;
	}
	float ka[3];
	float kd[3];
	float ks[3];
	float tr; // Aka d
	float ns;
	int illum;
	// TODO: Add maps
	GLuint ambientMap;
	GLuint diffuseMap;
	GLuint specularMap;
};

// Helper structs for OBJ loading
// Stores unique combinations of indices
struct VertexIndices {
		unsigned int vertex;
		unsigned int normal;
		unsigned int uv;
		unsigned int color;
};

// Stores a face with all indices
struct FaceIndices {
	VertexIndices v[3];
};

class GLMesh : public Sigma::IGLComponent {
public:
    SET_COMPONENT_ID("GLMesh");
	GLMesh(const int entityID); // Ctor that sets the entity ID.
	/**
	 * \brief Creates a new IGLComponent.
	 *
	 * \param[in] int entityID The entity this component belongs to.
	 * \returns IGLCompoent* the newly created component.
	 */
	void InitializeBuffers() ;
	virtual void Render(glm::mediump_float *view, glm::mediump_float *proj);

	/**
	 * \brief Returns the number of elements to draw for this component.
	 *
	 * Call this multiple times to get the elements for each mesh group. A return of 0 indicates all
	 * mesh groups have been returned, and the call loop should end.
	 * \param[in] const unsigned int group The mesh group to render.
	 * \returns unsigned int The number of elements to draw for the given mesh group.
	 */
	unsigned int MeshGroup_ElementCount(const unsigned int group = 0) const {
		if (this->groupIndex.size() == 0) {
			return 0;
		}
		if ((group + 1) < (this->groupIndex.size())) {
			return (this->groupIndex[group+1] - this->groupIndex[group]) * 3;
		} else if (group > (this->groupIndex.size() - 1)) {
			return 0;
		} else {
			return (this->faces.size() - this->groupIndex[group]) * 3;
		}
	}

	void LoadMesh(std::string fname);

	void ParseMTL(std::string fname);

	/**
	 * \brief Add a vertex to the list.
	 *
	 * \param[in] const Sigma::Vertex & v The vertex to add. It is copied.
	 */
	void AddVertex(const Sigma::Vertex& v) {
		this->verts.push_back(v);
	}

	/**
	 * \brief Gets a vertex.
	 *
	 * Returns the vertex at the specific index.
	 * \param[in] const unsigned int index The index of the vertex to get.
{'fraction_non_alphanumeric': 0.1333862643906312, 'fraction_numerical': 0.018658197697499008, 'mean_word_length': 3.3105218135158254, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7425806', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1767, 'n_words': 603}