#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_TEXTURING_COPY_H__
#define __TOOLS_TEXTURING_COPY_H__

#include "Misc/list_tem.hpp"
#include "Core/Asura_Maths.h"

struct TextureCopyPolygon;
struct PolygonID;
///////////////////////////////////////////////////////////////////////////////////////
/*
This class is used for handling copying texturing between multiple polygons
*/

class Tools_Texturing_Copy
{
	public :
		static void Initialise();
		static void Shutdown();

		static void CopyFromMultiple_Start();
		static void CopyToMultiple_Start();

		static void PolygonSelected(PolygonID polygon);

		static void ClearLists();

	private :
		static List<TextureCopyPolygon*> CopyFromList;		
		static List<TextureCopyPolygon*> CopyToList;
		static TextureCopyPolygon* CopyFromRef1;
		static TextureCopyPolygon* CopyFromRef2;
		static TextureCopyPolygon* CopyToRef1;
		static TextureCopyPolygon* CopyToRef2;

		static void NoteSelectedPolygons(List<TextureCopyPolygon*>& CopyList);
		static void CalculateAdjacencies(List<TextureCopyPolygon*>& CopyList);
		static bool ValidateBeforeCopy();

		static void CreateChoiceOverlay();

		static void CopyTopologically();
		static void CopyAbsolute();
		static int DoTopologicalPolygonMatch(int offset);
		
		static void CopyTexturingBetweenPolygons(TextureCopyPolygon* from,TextureCopyPolygon* to,bool reflect);

		static void GetMatrixForCopy(TextureCopyPolygon* p1,TextureCopyPolygon* p2,Asura_Matrix_3x3& output_mat,float& length);
		static bool GetTransformationBetweenCopyLists(Asura_Matrix_3x3& mat,Asura_Vector_3& centre_from,Asura_Vector_3& centre_to,float& scale);
};

///////////////////////////////////////////////////////////////////////////////////////

struct TextureCopyPolygon
{
	TextureCopyPolygon(const PolygonID&);
	int ModuleIndex;
	int PolyIndex;

	int NumVerts;
	Asura_Vector_3 Vert[4];//world positions of vertices
	Asura_Vector_3 Normal;//polygon normal

	TextureCopyPolygon* Adjacent[4];//array of adjacent polygons (max 1 per side)
	int Offset;//vertex offset compared to the polygon that it has been matched with
	bool Matched; 


	void CalculateVertices(bool reflect);
	Asura_Vector_3 CalculateCentre();
	void Transform(const Asura_Matrix_3x3& mat,const Asura_Vector_3& centre_from,const Asura_Vector_3& centre_to,const float& scale);
	bool PolygonMatches(TextureCopyPolygon* poly);
};








#endif //__TOOLS_TEXTURING_COPY_H__
