<commit_before>// Copyright © 2015 <NAME> <<EMAIL>>
// License: MIT, see the LICENSE file.

#include <exception>

#include "Raytracing/Primitives/Mesh.h"
#include "Raytracing/Ray.h"
#include "Utils/ObjReader.h"
#include "Utils/PlyReader.h"
#include "Utils/StringUtils.h"
#include "Math/Matrix4x4.h"

using namespace Raycer;

void Mesh::initialize()
{
	if (StringUtils::endsWith(meshFilePath, "obj"))
		triangles = ObjReader::readFile(meshFilePath);
	else if (StringUtils::endsWith(meshFilePath, "ply"))
		triangles = PlyReader::readFile(meshFilePath);
	else
		throw std::runtime_error("Unknown mesh file format");

	Matrix4x4 rotationX = Matrix4x4::rotateX(orientation.pitch);
	Matrix4x4 rotationY = Matrix4x4::rotateY(orientation.yaw);
	Matrix4x4 rotationZ = Matrix4x4::rotateZ(orientation.roll);
	Matrix4x4 rotation = rotationX * rotationY * rotationZ;
	Matrix4x4 scaling = Matrix4x4::scale(scale.x, scale.y, scale.z);
	Matrix4x4 translation = Matrix4x4::translate(position.x, position.y, position.z);
	Matrix4x4 transformation = translation * scaling * rotation;

	for (Triangle& triangle : triangles)
	{
		triangle.vertices[0] = transformation * triangle.vertices[0];
		triangle.vertices[1] = transformation * triangle.vertices[1];
		triangle.vertices[2] = transformation * triangle.vertices[2];

		// TODO: does not work with non-uniform scaling
		triangle.normals[0] = rotation * triangle.normals[0];
		triangle.normals[1] = rotation * triangle.normals[1];
		triangle.normals[2] = rotation * triangle.normals[2];

		triangle.normal = rotation * triangle.normal;
	}
}

void Mesh::intersect(Ray& ray) const
{
	for (const Triangle& triangle : triangles)
	{
		if (triangle.intersect(ray))
		{
			ray.intersection.materialId = materialId;
			ray.intersection.texcoord *= texcoordScale;
		}
	}
}
<commit_msg>Fixed compilation error<commit_after>// Copyright © 2015 <NAME> <<EMAIL>>
// License: MIT, see the LICENSE file.

#include <stdexcept>

#include "Raytracing/Primitives/Mesh.h"
#include "Raytracing/Ray.h"
#include "Utils/ObjReader.h"
#include "Utils/PlyReader.h"
#include "Utils/StringUtils.h"
#include "Math/Matrix4x4.h"

using namespace Raycer;

void Mesh::initialize()
{
	if (StringUtils::endsWith(meshFilePath, "obj"))
		triangles = ObjReader::readFile(meshFilePath);
	else if (StringUtils::endsWith(meshFilePath, "ply"))
		triangles = PlyReader::readFile(meshFilePath);
	else
		throw std::runtime_error("Unknown mesh file format");

	Matrix4x4 rotationX = Matrix4x4::rotateX(orientation.pitch);
	Matrix4x4 rotationY = Matrix4x4::rotateY(orientation.yaw);
	Matrix4x4 rotationZ = Matrix4x4::rotateZ(orientation.roll);
	Matrix4x4 rotation = rotationX * rotationY * rotationZ;
	Matrix4x4 scaling = Matrix4x4::scale(scale.x, scale.y, scale.z);
	Matrix4x4 translation = Matrix4x4::translate(position.x, position.y, position.z);
	Matrix4x4 transformation = translation * scaling * rotation;

	for (Triangle& triangle : triangles)
	{
		triangle.vertices[0] = transformation * triangle.vertices[0];
		triangle.vertices[1] = transformation * triangle.vertices[1];
		triangle.vertices[2] = transformation * triangle.vertices[2];

		// TODO: does not work with non-uniform scaling
		triangle.normals[0] = rotation * triangle.normals[0];
		triangle.normals[1] = rotation * triangle.normals[1];
		triangle.normals[2] = rotation * triangle.normals[2];

		triangle.normal = rotation * triangle.normal;
	}
}

void Mesh::intersect(Ray& ray) const
{
	for (const Triangle& triangle : triangles)
	{
		if (triangle.intersect(ray))
		{
			ray.intersection.materialId = materialId;
			ray.intersection.texcoord *= texcoordScale;
		}
	}
}

{'fraction_non_alphanumeric': 0.1304812834224599, 'fraction_numerical': 0.022459893048128343, 'mean_word_length': 4.608695652173913, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5696884', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1217, 'n_words': 250}