module gedo.video.animation;



private import gedo.video.ggl;
private import gedo.text.parser;



public class Animation
{
public:
	this(Parser a, uint cb)
	{
		_name = a.gets();

		_matrices.length = a.geti();

		foreach(inout boneMatrices; _matrices)
		{
			boneMatrices.length = cb;
			foreach(inout matrixBoneToWorld; boneMatrices)
			{
				foreach(inout m; matrixBoneToWorld.m)
				{
					m = a.getf();
				}
			}
		}
	}


	GGL_Matrix[] matrices(uint frame, GGL_Matrix[] buffer)
	{
		if(frame & 1)
		{
			auto a = frame>>1;
			auto b = a + 1;

			foreach(i, inout blendMatrix; buffer)
			{
				foreach(j, inout m; blendMatrix.m)
				{
					m = (_matrices[a][i].m[j] + _matrices[b][i].m[j]) * 0.5;
				}
			}

			return buffer;
		}
		else
		{
			return _matrices[frame>>1];
		}
	}


	char[] name()
	{
		return _name;
	}


	uint frameCount()
	{
		return (_matrices.length - 1) * 2;
	}


	uint boneCount()
	{
		if(_matrices.length > 0)
		{
			return _matrices[0].length;
		}
		else
		{
			return 0;
		}
	}


	uint size()
	{
		return _matrices.length * boneCount * GGL_Matrix.sizeof;
	}


private:
	GGL_Matrix[][] _matrices;
	char[]         _name;
}

