// ----------------------------------------------------------------------------
// Blitz-Irrlicht 1.8.3 Wrapper by Ed Musolino 2015
// Based off of Frank Dodd's Irrlicht 1.7 Freebasic Wrapper (2006-2010)
// ----------------------------------------------------------------------------

//  This software is provided 'as-is', without any express Or implied
//  warranty.  In no event will the authors be held liable For any damages
//  arising from the use of this software.

//  Permission is granted To anyone To use this software For any purpose,
//  including commercial applications, And To alter it And redistribute it
//  freely, subject To the following restrictions:

//  1. The Origin of this software must Not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgement in the product documentation would be
//     appreciated but is Not required.
//  2. Altered source versions must be clearly marked as such, And must Not be
//     misrepresented as being the original software.
//  3. This notice may Not be removed Or altered from any source distribution.
//
// /////////////////////////////////////////////////////////////////////////////

namespace irr
{

class ITimer;

namespace gui
{
	class IGUIFont;
}
namespace scene
{

class CLODSceneNode : public ISceneNode
{
public:
	CLODSceneNode(ISceneNode* parent, s32 id=-1);
	~CLODSceneNode();


	/*
	 * node functions
	 */

	// render the actual object
	virtual void render();

	// get the bounding box
	const irr::core::aabbox3df& getBoundingBox() const;

	// redirect renders here,
	virtual void OnRegisterSceneNode();

	// render to texture here,
	virtual void OnAnimate(u32 timeMs);

	// deal with children
	virtual void addChild(ISceneNode* child);
	virtual bool removeChild(ISceneNode* child);

	void AddLODMesh( float distance, IAnimatedMesh *mesh );

	void SetMaterialMapping( E_MATERIAL_TYPE source, E_MATERIAL_TYPE target );

    enum lodMode
    {
        LOD_OPAQUE,
        LOD_FADE_OUT,
		LOD_FADE_IN,
        LOD_INVISIBLE
    };

	// link for a child node recording level of detail
	struct SChildLink
	{
		SChildLink() : node(0), lod(0), fade(0x0), mode( LOD_OPAQUE ) {}

		// the scene node
		ISceneNode *	    node;

		// about the object
		s32				    lod;
        E_MATERIAL_TYPE     matType;
        u32                 fade;
        lodMode             mode;

		bool operator == (const SChildLink& other) const { return node == other.node; }
	};

	struct SLOD
	{
		SLOD(): mesh(NULL), distance(0.0f){}
		IAnimatedMesh *	mesh;
		float			distance;

		bool operator == (const SLOD& other) const { return distance == other.distance; }
	};

	core::aabbox3df Box;
	core::array<SChildLink> children;
	core::array<SLOD> lods;
	u32 fadeScale;
	void (*callback)(u32, ISceneNode *);
	bool useAlpha;
	E_MATERIAL_TYPE matmap[EMT_ONETEXTURE_BLEND+1];
};

} // scene
} // irr
