#ifndef _CSCENEFBX_H_
#define _CSCENEFBX_H_

#include <fbxsdk.h>
#include <vector>
#include <list>
#include <algorithm>

struct MATERIAL
{
	D3DXCOLOR Diffuse;
	D3DXCOLOR Ambient;
	D3DXCOLOR Specular;
	D3DXCOLOR Emission;
	float Shininess;

};

struct BornRefarence
{
	BornRefarence( unsigned char index, float weight ): index( index ), weight( weight )
	{
	}
	unsigned char index;
	float weight;
};

struct Point
{
	Point( const D3DXVECTOR3 positions ): positions( positions )
	{
	}
	D3DXVECTOR3 positions;
	std::vector<BornRefarence> bornRefarences;
};

struct Mesh
{

	Mesh(): materialIndex( -1 )
	{
	}
	std::vector<Point > points;
	std::vector<D3DXVECTOR3> normals;
	std::vector<D3DXVECTOR2> texcoords;
	std::vector<unsigned short > positionIndices;
	std::vector<unsigned short > normalIndices;
	std::vector<unsigned short > texcoordIndices;
	int materialIndex;

	// DDMTRI initInvMatrix;
	std::vector<std::vector<D3DXMATRIX>> matrixes;

};

struct FaceIndex
{
	unsigned short vIndex;
	unsigned short vtIndex;
	unsigned short vnIndex;
};

struct myNode
{

	std::string name;
	std::list<myNode*> children;
	std::vector<std::string > attributeNames;
	D3DXVECTOR3 translation;
	D3DXVECTOR3 rotation;
	D3DXVECTOR3 scaling;
	std::vector<int> textures; // とマテリアル
	std::vector<Mesh> meshes;

	static myNode* recursiveNode( FbxManager* pManager, FbxNode* pNode, bool bTexcoordVReverse, FbxTime startTime, FbxTime endTime );
	void recursiveDraw( int currentFrame );
	

	void analyzePosition( FbxMesh* pMesh );
	void analyzeNormal( FbxMesh* pMesh );
	void analyzeTexcoord( FbxMesh* pMesh, bool bRevers = false );
	void analyzeMaterial( FbxNode* pNode );
	void analyzeMaterial( FbxMesh* pMesh );
	void analyzeCluster( FbxMesh* pMesh, FbxTime startTime, FbxTime endTime );
	FbxMatrix GetGeometry( FbxNode* pNode ); // - New!!

	static std::string GetttributeTypeName( FbxNodeAttribute::EType type );

};


class CSceneFBX
{
	public:
	void	Init( void );
	void	Uninit( void );
	void	Update( void );
	void	Draw( int currentFrame );

	private:
	int			m_faceCount;
	int			m_indexCount;
	int			m_vCount;
	int			m_vtCount;
	int			m_vnCount;
	Vector3*	m_pV;
	FaceIndex*	m_pFace;
	int*		m_pFbxI;
	myNode*		m_pTopMyNode;

};

	#endif // !_CSCENEFBX_H_