<commit_before>#include<Render/mesh.hpp>

using namespace render;

Mesh::Mesh():
	engine(&Engine::get())
{
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	glGenBuffers(1, &ebo);

	glGenBuffers(3, vbos);

	positions_ = std::vector<
		core::math::cartesian::CartThree<>
		>(
				{
				{ 1.0f,  1.0f,  1.0f, },
				{-1.0f,  1.0f,  1.0f, },
				{ 1.0f, -1.0f,  1.0f, },
				{ 1.0f,  1.0f, -1.0f, },
				{-1.0f, -1.0f, -1.0f, },
				{ 1.0f, -1.0f, -1.0f, },
				{-1.0f,  1.0f, -1.0f, },
				{-1.0f, -1.0f,  1.0f, },
				}
		 );

	colors_= std::vector<
		core::math::cartesian::CartThree<>
		>(
				{
				{ 1.0f,  1.0f,  1.0f, },
				{ 0.0f,  1.0f,  1.0f, },
				{ 1.0f,  0.0f,  1.0f, },
				{ 1.0f,  1.0f,  0.0f, },
				{ 0.0f,  0.0f,  0.0f, },
				{ 1.0f,  0.0f,  0.0f, },
				{ 0.0f,  1.0f,  0.0f, },
				{ 0.0f,  0.0f,  1.0f, },
				}
		 );

	faces_ = std::vector<Face>(
			{ 
			{ 0, 1, 6, },
			{ 0, 3, 6, },
			{ 0, 2, 5, },
			{ 0, 3, 5, },
			{ 0, 1, 7, },
			{ 0, 2, 7, },
			{ 4, 5, 2, },
			{ 4, 7, 2, },
			{ 4, 6, 1, },
			{ 4, 7, 1, },
			{ 4, 6, 3, },
			{ 4, 5, 3, },
			}
			);

};

Mesh& Mesh::loadFromFile(const std::string filename){
	filename_ = filename;

    Assimp::Importer importer;

	const aiScene* pScene = importer.ReadFile(
		filename.c_str(),
		aiProcess_Triangulate
		| aiProcess_GenSmoothNormals
		| aiProcess_FlipUVs
		| aiProcess_JoinIdenticalVertices
	);

    if (pScene) {
		positions_.clear();
		//colors_.clear();
		//normals_.clear();
		//faces_.clear();
		
		int vertIndexOffset = 0;

		for(int meshI = 0; meshI < pScene->mNumMeshes; meshI++){
			const auto mesh = pScene->mMeshes[meshI];

			const auto vertPos = mesh->mVertices;
			const auto vertPosN = mesh-> mNumVertices;
			for(int vertPosI = 0; vertPosI < vertPosN; vertPosI++){
				const auto vert = vertPos[vertPosI];
				positions_.push_back({vert.x, vert.y, vert.z,});
			}

			const auto faces = mesh->mFaces;
			const auto facesN = mesh->mNumFaces;
			for(int faceI = 0; faceI < facesN; faceI++){
				const auto face = faces[faceI];
				const auto points = face.mIndices;
				faces_.push_back({
					points[0] + vertIndexOffset,
					points[1] + vertIndexOffset,
					points[2] + vertIndexOffset,
				});
			}

			std::cout << mesh->HasFaces() << ','
				<< mesh->HasNormals() << ','
				<< mesh->HasPositions() << std::endl;

			vertIndexOffset += vertPosN;
		}
    }
    else {
        printf("Error parsing '%s': '%s'\n", filename.c_str(), importer.GetErrorString());
    }

	return *this;
}

void Mesh::loadPositions(){

	glBindBuffer(GL_ARRAY_BUFFER, vbos[0]);

	glBufferData(
			GL_ARRAY_BUFFER,
			sizeof(positions_[0].data()) * 3 * positions_.size(),
			positions_.data(),
			GL_STATIC_DRAW
			);

	GLint attributePosition = glGetAttribLocation(programToken_, "position");

	glEnableVertexAttribArray(attributePosition);
	glVertexAttribPointer(
			attributePosition,
			3,
			GL_FLOAT,
			GL_FALSE,
			0,
			0
			);<commit_msg>feat(colors): can load mesh colors yay<commit_after>#include<Render/mesh.hpp>

using namespace render;

Mesh::Mesh():
	engine(&Engine::get())
{
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	glGenBuffers(1, &ebo);

	glGenBuffers(3, vbos);

	positions_ = std::vector<
		core::math::cartesian::CartThree<>
		>(
				{
				{ 1.0f,  1.0f,  1.0f, },
				{-1.0f,  1.0f,  1.0f, },
				{ 1.0f, -1.0f,  1.0f, },
				{ 1.0f,  1.0f, -1.0f, },
				{-1.0f, -1.0f, -1.0f, },
				{ 1.0f, -1.0f, -1.0f, },
				{-1.0f,  1.0f, -1.0f, },
				{-1.0f, -1.0f,  1.0f, },
				}
		 );

	colors_= std::vector<
		core::math::cartesian::CartThree<>
		>(
				{
				{ 1.0f,  1.0f,  1.0f, },
				{ 0.0f,  1.0f,  1.0f, },
				{ 1.0f,  0.0f,  1.0f, },
				{ 1.0f,  1.0f,  0.0f, },
				{ 0.0f,  0.0f,  0.0f, },
				{ 1.0f,  0.0f,  0.0f, },
				{ 0.0f,  1.0f,  0.0f, },
				{ 0.0f,  0.0f,  1.0f, },
				}
		 );

	faces_ = std::vector<Face>(
			{ 
			{ 0, 1, 6, },
			{ 0, 3, 6, },
			{ 0, 2, 5, },
			{ 0, 3, 5, },
			{ 0, 1, 7, },
			{ 0, 2, 7, },
			{ 4, 5, 2, },
			{ 4, 7, 2, },
			{ 4, 6, 1, },
			{ 4, 7, 1, },
			{ 4, 6, 3, },
			{ 4, 5, 3, },
			}
			);

};

Mesh& Mesh::loadFromFile(const std::string filename){
	filename_ = filename;

    Assimp::Importer importer;

	const aiScene* pScene = importer.ReadFile(
		filename.c_str(),
		aiProcess_Triangulate
		| aiProcess_GenSmoothNormals
		| aiProcess_FlipUVs
		| aiProcess_JoinIdenticalVertices
	);

	std::cout << "num of mats: " << pScene->mNumMaterials << std::endl;

	const auto materials = pScene->mMaterials;

    if (pScene) {
		positions_.clear();
		colors_.clear();
		normals_.clear();
		faces_.clear();
		
		int vertIndexOffset = 0;

		for(int meshI = 0; meshI < pScene->mNumMeshes; meshI++){
			const auto mesh = pScene->mMeshes[meshI];

			const auto vertN = mesh->mNumVertices;
			const auto materialI = mesh->mMaterialIndex;
			const auto material = materials[materialI];

			aiColor3D color (0.f,0.f,0.f);
			material->Get(AI_MATKEY_COLOR_DIFFUSE,color);

			const auto vertPoss = mesh->mVertices;
			const auto vertNors= mesh->mNormals;
			for(int vertI = 0; vertI < vertN; vertI++){
				const auto pos = vertPoss[vertI];
				positions_.push_back({pos.x, pos.y, pos.z,});

				const auto nor = vertNors[vertI];
				normals_.push_back({nor.x, nor.y, nor.z,});

				colors_.push_back({color.r, color.g, color.b,});
			}

			const auto faces = mesh->mFaces;
			const auto facesN = mesh->mNumFaces;
			for(int faceI = 0; faceI < facesN; faceI++){
				const auto face = faces[faceI];
				const auto points = face.mIndices;
				faces_.push_back({
						points[0] + vertIndexOffset,
						points[1] + vertIndexOffset,
						points[2] + vertIndexOffset,
						});
			}

			std::cout << mesh->HasFaces() << ','
				<< mesh->HasNormals() << ','
				<< mesh->HasPositions() << std::endl;

			vertIndexOffset += vertN;
		}
	}
	else {
		printf("Error parsing '%s': '%s'\n", filename.c_str(), importer.GetErrorString());
	}

	return *this;
}

void Mesh::loadPositions(){

	glBindBuffer(GL_ARRAY_BUFFER, vbos[0]);

	glBufferData(
			GL_ARRAY_BUFFER,
			sizeof(positions_[0].data()) * 3 * positions_.size(),
			positions_.data(),
			GL_STATIC_DRAW
			);

	GLint attributePosition = glGetAttribLocation(programToken_, "position");

	glEnableVertexAttribArray(attributePosition);
	glVertexAttribPointer(
			attributePosition,
			3,
			GL_FLOAT,
			GL_FALSE,
			0,
			0
			);
{'fraction_non_alphanumeric': 0.1933806146572104, 'fraction_numerical': 0.04728132387706856, 'mean_word_length': 2.7067757009345796, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 38, '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': '5281851', 'n_tokens_mistral': 3279, 'n_tokens_neox': 2699, 'n_words': 502}