/****************************************************************************************

		COMTreePrim.h

		Copyright (c)1990 - 1999 MetaCreations. All rights reserved.

		Author:	Jerome Bignon
		Date:	05/17/99

		Revision History

		when		who			what & why
		==========	==========	======================================================
		05/17/99	Jerome		Creation
		07/22/99	Mael		added GetPolygonInfo

*****************************************************************************************/

#ifndef __COMTREEPRIM__
#define __COMTREEPRIM__  

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "I3DShModule.h"
#include "ModelerDef.h"
#include "ITreePrim.h"
#include "BasicPrimitive.h"
#include "IModelerView.h"
#include "ModelerView.h"
#include "PublicUtilities.h"

// Define the COMTreePrim CLSID ( see the ModelerTreeDef.h file to get R_CLSID_COMTreePrim value )
extern const MCGUID CLSID_TreePrim;

struct TreeData
{
	int16 fNbBranches;		// Number of branches of the 3D Tree 
	real  fAngle;			// Angle for branches
	int16 fRecursiv;		// Recursivity number for tree construction
};
 

// Tree Object definition : 
// TreePrimitive Object :

class TreePrim : public TBasicPrimitive, public ITreePrim
{
	public :  
		TreePrim();

		virtual MCCOMErr 	MCCOMAPI QueryInterface			(const MCIID &riid, void** ppvObj);
 		virtual uint32 		MCCOMAPI AddRef 				();
		STANDARD_RELEASE;
  
		// IExDataExchanger methods :
		virtual void*		MCCOMAPI GetExtensionDataBuffer();
		virtual int32		MCCOMAPI GetParamsBufferSize		() const	{ return sizeof(fData);}
		virtual MCCOMErr 	MCCOMAPI ExtensionDataChanged();
		virtual int16		MCCOMAPI GetResID();
  
		// I3DExGeometricPrimitive methods
		// Geometric Calls
		virtual void		MCCOMAPI GetBoundingBox(TBBox3D& bbox);
		virtual MCCOMErr    MCCOMAPI EnumPatches	 (EnumPatchesCallback callback, void* privData, boolean& closed);
		virtual MCCOMErr    MCCOMAPI GetNbrLOD(int16 &nbrLod);
		virtual MCCOMErr	MCCOMAPI GetFacetMesh(uint32 index, FacetMesh** outMesh); // index is the lod number
		virtual boolean     MCCOMAPI CanBeSplit();
		virtual MCCOMErr    MCCOMAPI SplitPrimitive(TMCCountedPtrArray<I3DExGeometricPrimitive>& subParts, TMCArray<TTransform3D>& subPartPositions);

		virtual boolean		MCCOMAPI AutoSwitchToModeler() const;
									

		// Shading Calls
		virtual uint32		MCCOMAPI GetUVSpaceCount();
		virtual MCCOMErr 	MCCOMAPI GetUVSpace( uint32 uvSpaceID, UVSpaceInfo* uvSpaceInfo);
		virtual MCCOMErr    MCCOMAPI UV2XYZ(TVector2* uv, uint32 uvSpaceID, TVector3* resultPosition, boolean* inUVSpace); // Optional - Return E_NOTIMPL if not implemented
		virtual MCCOMErr    MCCOMAPI GetUVSpaceRDS5(uint32 uvSpaceID, UVSpaceInfoRDS5* uvSpaceInfoRDS5); // To be implemented only if your primitive existed in RDS 5 or earlier, so that UV spaces can be mapped properly to the new 0..1 boundaries
		virtual MCCOMErr    MCCOMAPI AppendToRenderables( const TTransform3D& 	worldFromModelTfm,
															 TRenderableAndTfmArray& renderableAndTfm );
  		

		virtual boolean		MCCOMAPI SetData(const TreeData& data);		
		virtual TreeData	MCCOMAPI GetData()
		{
			return fData;
		};

		virtual	boolean		MCCOMAPI GetIfDataChanged();
		
	protected:	
		MCCOMErr UpdateBoundingBox( TVector3 *Coordinate );
		TVector3 Rotate( TVector3 &Vertex , TVector3 &angle );
		TVector3 Normal( TVertex3D	*fVertices );
	
		TVector3 Cube(FacetMeshAccumulator *accum, real SizeZ , real SizeXY , TVector3 &angle , TVector3 &translate);
		MCCOMErr GetFacetsTree(FacetMeshAccumulator *accum, int level , TVector3 angle , TVector3 translate );

		TBBox3D  fTreeBox;    // BoundingBox
		TreeData fData;       // Tree Data
		boolean	 fDataChanged;// true if Datas changed
};

//TBasicUnknown* MakeModelerCOMObject(const MCCLSID &classId);

#endif // __TreePrimitive__