//*******************************************************************
//
// File: Asura_PS2_Botanicals_Shared.h
//
// Created: 21 March 2006 by Jake Turner
//
// Description: 
// Classes and structures used to hold PS2 Botanicals data
// This file is shared and used by the PC TOOL and PS2 platform code
// The tools export data in these structure and the PS2 uses them at runtime
//
//*******************************************************************

#ifdef ASURA_USE_BOTANICALS

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __ASURA_PS2_BOTANICALS_SHARED_H__
#define __ASURA_PS2_BOTANICALS_SHARED_H__

#define ASURA_PS2_BOTANICALS_CHUNK_VERSION 6

enum Asura_PS2_Botanicals_Mesh_Type
{
	ASURA_PS2_BOTANICALS_NORMAL_MESH = 0,
	ASURA_PS2_BOTANICALS_2SIDED_MESH = 1,
	ASURA_PS2_BOTANICALS_BILLBOARDS = 2,
	ASURA_PS2_BOTANICALS_IMPOSTER = 3
};

struct Asura_RenderChainNode
{
	u_short usUserData;
	u_short usNextOffset;
};

union Asura_PS2_Botanicals_QW
{
	short         i16s[8];
	u_short       u16s[8];
	float         f32s[4];
	int           i32s[4];
	u_int         u32s[4];
};

struct Asura_PS2_Botanicals_Header
{
	u_int uNumTypes;
	u_int uNumTotalComponents;
	u_int uNumTotalInstances;
	u_int uTotalHeadersSizeInBytes;
	u_int uTotalTypeInfosSizeInBytes;
};

struct Asura_PS2_Botanicals_Type_Header
{
	u_short usTypeID;
	u_short usNumModules;
	u_int uNumInstances;
};

struct Asura_PS2_Botanicals_Module_Header
{
	u_short usModuleID;
	u_short usNumInstances;
};

struct Asura_PS2_Botanicals_Component_Info
{
	int iTextureID;					// On export it is a material ID which is converted to a texture ID & material flags
	u_int uMaterialFlags;
	u_short usType;					// enum Asura_PS2_Botanicals_Mesh_Type
	u_short usNumTris;				
	float fLoDMin;
	float fLoDMax;
	float fLoDConstant1;
	float fLoDConstant2;
	u_int uComponentIndexAndType; // u_int : top 8-bits is type, bottom 24-bits is component index into component DMA data
};

struct Asura_PS2_Botanicals_Instance
{
	// This first part is EE used data only
	u_short usGlobalInstanceIndex;
	u_short usPadding;

	float fSphereBoundX;
	float fSphereBoundY;
	float fSphereBoundZ;
	float fSphereBoundR;

	// The object scale needed for the billboards and imposters
	float fScaleXYZ;

	// This should be DMA friendly packet data
	float fX;
	float fY;
	float fZ;

	// Not sure about putting a matrix in cross platform file data and structures
	// This will end up as pure QW data to be sent to the VU ucode
	Asura_Matrix_3x3 xLocal2World;

	// 8-bit per SH component instead of 32-bits (scale factor 128 = 1.0f)
	// World SH for the billboards & imposters
	u_int uWorldSH0;
	u_int uWorldSH1;
	u_int uWorldSH2;
	u_int uWorldSH3;

	// 8-bit per SH component instead of 32-bits (scale factor 128 = 1.0f)
	// Pre-rotated SH for the 3D geometry
	u_int uObjectSH0;
	u_int uObjectSH1;
	u_int uObjectSH2;
	u_int uObjectSH3;
};

struct Asura_PS2_Botanicals_Type_Info
{
	Asura_Bounding_Box xBB;
	float fInvMaxDrawDistance;
	u_int uNumComponents;
	Asura_PS2_Botanicals_Component_Info xComponentInfo[1]; // xComponentInfo[uNumComponents]
};

// The PS2 Botanicals data format Version 6 is:
//
// Asura_PS2_Botanicals_Header
// {
//    u_int uNumTypes;
//    u_int uNumTotalInstances;
//    u_int uTotalHeadersSizeInBytes;
//	  u_int uTotalTypeInfosSizeInBytes;
//	  u_int uTotalTypeDmaDataSizeInBytes;
// };
// Array of uNumTypes
// {
//    struct Asura_PS2_Botanicals_Type_Header
//    {
//       u_short usTypeID;
//   	 u_short usNumModules;
//       u_int uNumInstances;
//    };
//	  Array of usNumInstances;
//    {
//	     struct Asura_PS2_Botanicals_Instance
//		 {
//			u_short usGlobalInstanceIndex;
//			u_short usPadding;
//
//			float fSphereBoundX;
//			float fSphereBoundY;
//			float fSphereBoundZ;
//			float fSphereBoundR;
//
//			float fScaleXYZ;
//
//		    float fX;
//			float fY;
//			float fZ;
//
//			float fQuatX;
//			float fQuatY;
//			float fQuatZ;
//			float fQuatW;
//
//		    Asura_Matrix_3x3 xLocal2World;
//
//			u_int uWorldSH0;
//			u_int uWorldSH1;
//			u_int uWorldSH2;
//			u_int uWorldSH3;
//
//			u_int uSH0;
//			u_int uSH1;
//			u_int uSH2;
//			u_int uSH3;
//		 };
//    }
// }
//
// This data is separate to the Asura_PS2_Botanicals_Type_Header data because
// one day this type info data might be passed to VU1 for LoD selection
//
// Array of uNumTypes
// {
//    struct Asura_PS2_Botanicals_Type_Info
//    {
//       Asura_Bounding_Box xBB;
//		 float fInvMaxDrawDistance
// 	     u_int uNumComponents;
//		 Array of uNumComponents;
//       {
//          struct Asura_PS2_Botanicals_Component_Info
//          {
//			   u_int uMaterialID;				// On export it is a material ID which is converted to a texture ID & material flags
//			   u_int uMaterialFlags;
//			   u_int uType;					    // enum Asura_PS2_Botanicals_Mesh_Type
//			   float fLoDMin;
//			   float fLoDMax;
//			   float fLoDConstant1;
//			   float fLoDConstant2;
//			   u_int uComponentIndexAndType;	// u_int : top 8-bits is type, bottom 24-bits is component index into component DMA data
//			};
//       }
//    }
// }
//
// Array of uNumTotalComponents
// {
//    DMA data for the mesh component: referenced by a DMA CALL tag so the DMA data includes the DMA RET tag
// }
//
///////////////////////////////////////////////////////////////////////////

#endif //  #ifndef __ASURA_PS2_BOTANICALS_SHARED_H__

#endif // #ifdef ASURA_USE_BOTANICALS