
//**************************************************************************/
// Copyright (c) 2008 Autodesk, Inc.
// All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
//
//**************************************************************************/
// DESCRIPTION:
// CREATED: October 2008
//**************************************************************************/

namespace mudbox {

/// Represents one level of subdivision details in a geometry.
class MBDLL_DECL SubdivisionLevel : virtual public Mesh
{
	DECLARE_CLASS;

protected:
	/// Do not use constructors directly. Use CreateInstances() instead.
	SubdivisionLevel( FaceType eFaceType = typeQuadric );

public:
	/// Returns the geometry that this mesh belongs to.
	virtual class Geometry *Geometry( void ) const;
	/// Returns the next (one detail higher) level.
	virtual SubdivisionLevel *NextLevel( void );
	/// Returns the previous (one detail lower) level.
	virtual SubdivisionLevel *PrevLevel( void );
	/// Returns the index in the level list of the geometry.
	virtual unsigned int Index( void ) const;
	/// Returns the maximum reachable face count on the level. Equals to the total face count of the previous level * 4.
	virtual unsigned int TotalFaceCount( void ) const;
	/// Subdivides the level to a higher detail.
	virtual SubdivisionLevel *Subdivide( bool bProcessUV = true );
	/// Copy the content of this SubdivisionLevel to another one.
	virtual void CopyTo( SubdivisionLevel *pDestination ) const;
	/// Updates the previous level with all the changes on the current level.
	virtual void ApplyChanges( void );
	/// Creates the UV layout if not exists or recreates if forced. The calculation is based on the uv layout of the previous
	/// level; if it does not exist it will be created recursively down to level0. If level 0 has no UV the funcion does nothing.
	virtual void RecreateUVs( bool bForced = false );

	static void SetUVCreation( bool bCreateUV );
	static const Store<unsigned int> &QuadIndexTable( unsigned int iLevel );
	static const Store<unsigned int> &QuadVertexIndexTable( unsigned int iLevel );
	static const Store<unsigned int> &InvertedQuadIndexTable( unsigned int iLevel );
	virtual void CheckMeshGrid( unsigned int iBaseFaceIndex, unsigned int iLevel ) const;
	virtual void ConvertToRelative();
	virtual void ConvertToAbsolute();
};

}; // end of namespace mudbox
