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

		Renderable.cpp
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Arnaud
		Date:	12/2/2004

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

#include "Renderable.h"


#include "MCCountedPtrHelper.h"
#include "I3DShObject.h"


#include "Modeler.h"



void TRenderable::Create(	TRenderable**			renderable, 
							TModeler*				modeler,
							I3DShRenderable::EType	geomType)
{
	TMCCountedCreateHelper<TRenderable> result(renderable);
	result = new TRenderable(modeler, geomType);
}


TRenderable::TRenderable(TModeler* modeler, I3DShRenderable::EType geomType)
{
	MCAssert(modeler); 
	MCAssert(geomType == kType_Facet); //rest not supported yet
	fModeler		= modeler;
	fGeometryType	= geomType;
	fRenderFlags.SetMasked(TRenderableFlags::kUseScreenColorsMask); // for the flat rendering mode
}


TRenderable::~TRenderable()
{
}


MCCOMErr TRenderable::GetFMesh(real lod, FacetMesh** outMesh)
{
	ThrowIfNil(fModeler);
	fModeler->GetCurrentFacetMesh(lod, outMesh);
	return MC_S_OK;
}

const TSegmentMesh*	TRenderable::GetSegmentMesh() const
{
	ThrowIfNil(fModeler);	
	return NULL; //fModeler->GetCurrentSegmentMesh();
}

const TPointMesh* TRenderable::GetPointMesh()	const
{
	ThrowIfNil(fModeler);
	return NULL; //fModeler->GetCurrentPointMesh();
}


uint32  TRenderable::GetUVSpaceCount()
{
	ThrowIfNil(fModeler);
	ThrowIfNil(fModeler->GetPrimitive());

	TMCCountedPtr<I3DShObject> masterObject;
	fModeler->GetPrimitive()->QueryInterface(IID_I3DShObject, (void**)&masterObject);
	ThrowIfNil(masterObject);

	return masterObject->GetUVSpaceCount();
}


void TRenderable::GetBoundingBox(TBBox3D& bb)
{
	if (MCVerify(fModeler))
	{
		fModeler->GetCurrentBoundingBox(bb);
	}
}


