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

		TreePrim.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

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

#ifndef __TreePrim__
#define __TreePrim__  

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "TreePrimDef.h"
#include "BasicPrimitive.h"
#include "PublicUtilities.h"

// Define the TreePrim CLSID ( see the COMModelerTreeDef.h file to get R_CLSID_TreePrim 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 :  
		TreePrim();

		STANDARD_RELEASE;
  
		// IExDataExchanger methods :
		virtual void*		MCCOMAPI		GetExtensionDataBuffer();
		virtual int32		MCCOMAPI		GetParamsBufferSize		() const	{ return sizeof(fData);}
		virtual MCCOMErr 	MCCOMAPI		ExtensionDataChanged();
		virtual int16		MCCOMAPI		GetResID();
  
		// I3DExGeometricPrimitiv methods
		// Geometric Calls
		virtual void	 	MCCOMAPI        GetBoundingBox(TBBox3D& bbox);
		virtual MCCOMErr	MCCOMAPI		GetNbrLOD(int16& nbrLod);
		virtual MCCOMErr	MCCOMAPI		GetFacetMesh(uint32 index, FacetMesh** outMesh); // index is the lod number
		

		// Shading Calls
		virtual uint32		MCCOMAPI		GetUVSpaceCount();
		virtual MCCOMErr 	MCCOMAPI        GetUVSpace( uint32 uvSpaceID, UVSpaceInfo* uvSpaceInfo);
		  		
		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
};

#endif // __TreePrimitive__