#pragma once

#include "types.h"

#include <vector>
#include <ostream>

struct Mesh {
	vec3v_t positions;
	vec3v_t normals;
	vec2v_t texcoords;

	vec3v_t faceNormals;
	uvec3v_t indices;
	uintv_t patches;
	uvec4v_t edges;
	uvec3v_t adjacents;
	vec3v_t tangents;
	vec3v_t bitangents;

	Mesh();
	Mesh(Mesh &other);
	Mesh(Mesh &&other);

	Mesh& operator=(Mesh&&);

	void generateNormals();
	void generateTangentBasis();

	void generateAdjacent();
	void generateFaceNormals();
	void generateEdges();

	void moveToMean();
	void smooth();

	Mesh createPatched(float threshold) const;

	void saveAttrib(std::ostream &out, const char *prefix,
			const vec3v_t &elements) const;
	void saveAttrib(std::ostream &out, const char *prefix,
			const vec2v_t &elements) const;
	void saveFaces(std::ostream &out, const uvec3v_t &indicess,
			size_t attributes) const;
	void save(std::ostream &out) const;
	void save(std::string filename) const;
};
