///////////////////////////////////////////////////////////////////////////////
/// @file deMesh.hpp
///
/// @brief mesh class interface
///
/// @author Assassin
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Aug 2003
/// @author Assassin
/// @remarks Creation
///
///////////////////////////////////////////////////////////////////////////////
#ifndef DEMESH_PRIV_HPP
#define DEMESH_PRIV_HPP

#include "deMesh.hpp"
#include "deWorld_Helper.hpp"
#include "deArray.hpp"

extern "C" deBoolean IdeMesh_Initialize();

class deMesh : public deWorldObject, virtual public IdeMesh
{
protected:
	~deMesh();
public:
	deMesh();
	
	WorldObjectClassDef;
	void* GetWOInterface(long interface_id);
	deBoolean DeSerializeLoad();

	deBoolean BuildFromBrushGeometry(IdeBrush* brush);
	deBoolean BuildFromVertices();
	void ClearGeometry();
	
	deBoolean AddVertices(const deMeshVertexData & vertexdata, long & indexoffset);
	deBoolean AddIndices(const deMeshIndexData & indexdata);
	
	void SetNumSubMeshes(u32 NumSubs, deBoolean Dynamic);
	deBoolean SetSurface(u32 SubNum, IdeSurface* Surface);
	IdeSurface* GetSurface(u32 SubNum);
	deBoolean SetNumFaces(u32 SubNum, u32 NumFaces);
	u32 GetNumFaces(u32 SubNum);
	deBoolean Lock(deVertex** &positions, deTexCoord2** &uvcoords, deARGB** &colors);
	deBoolean Unlock(deVertex** &positions, deTexCoord2** &uvcoords, deARGB** &colors);

	IdeVertexBuffer* GetMainVertexBuffer();
	long GetNumSubMeshes();
	IdeVertexBuffer* GetSubMeshVertexBuffer(long index);
	IdeVertexBuffer* GetSubMeshIndexBuffer(long index);
	IdeSurface* GetSubMeshSurface(long index);

	deDouble GetBoundRadius();
	void GetBBox(deAABB& outBox);
	
private:
	struct deSubMesh
	{
		IdeVertexBuffer*	IBuffer;
		IdeVertexBuffer*	VBuffer;
		IdeSurface*			Surface;
	};
	IdeVertexBuffer* m_MainVertexBuffer;
	IdeVertexBuffer* m_MainIndexBuffer;
	deTArray <deSubMesh>	m_SubMeshes;
	deTArray <deMeshVertexData>	m_VertexDataList;
	deTArray <deMeshIndexData>	m_IndexDataList;
	struct SubMeshDescriptor
	{
		deWorldID WorldID;
		deObjectID ObjectID;
	};
	deTArray <SubMeshDescriptor>	m_TempSubMeshes;
	deDouble m_BoundRadius;
	deAABB m_BBox;
};


#endif
