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

		IPreviewMaker.h

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

		Author:	Ray Dream
		Date:	04/20/99

		Revision History

		when		who			what & why
		==========	==========	======================================================
		11/10/99	Thierry		added SetUseDefaultBackgroundColor

*****************************************************************************************/
#ifndef __IPREVIEWMAKER__
#define __IPREVIEWMAKER__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCBasicDefines.h"
#include "MCBasicTypes.h"
#include "MCCountedObject.h"
#include "Vector3Fwd.h"

class TMCPoint;
class TMCRect;
class TMCOffscreen;
class TMCPixelBucket;

struct TRenderArea;

struct I3DShScene;
struct I3DShObject;
struct I3DShCamera;
struct I3DShMasterShader;
struct I3DShInstance;
struct I3DRenderingCallbacks;

//****** Globally Unique Ids *************************************************

MCDEFINE_GUID(IID_IPreviewMaker, 0xe3986334, 0x46cd, 0x11d3, 0xa7, 0xda, 0x0, 0x60, 0x97, 0xb, 0xc5, 0x21);

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

/// \addtogroup ShellInterface
/// \{

/// Interface for a preview maker, used for generating scene previews.  Use I3DShUtilities::CreatePreviewMaker()
/// to create it, then use to draw previews.
struct IPreviewMaker : public IMCUnknown
{
public:
	
	/// Used to specify rendering quality of a preview
	struct TRenderingQuality
	{
		TRenderingQuality() : fShadowOn(false),fOverSampling(1),fLightThroughTransparency(false) {}

		boolean		fShadowOn;		///< true if shadows should be on
		int32		fOverSampling;	///< 0 None, 1 Fast, 2 Good
		boolean		fLightThroughTransparency;	///< True if light through transprency should bon
	};

	enum {kFlatMode, kSphereMode, kObjectMode, kSceneMode};


	// Accessors

	//                    SetTemplateScene
	/// Set the template scene to use for the preview (for other than kSceneMode)
	///
	/// \param scene		The template scene to use. It must contains an instance named "Object",
	///						this instance will be used when you set the object to preview.
	/// \param fitIntoBBox	If true, after replacing the object of the instance "Object", the
	///						bounding box of this instance will remain the same.
	/// \param bbox         If fitIntoBBox is true, set the bounding box of the object.
	virtual void	MCCOMAPI SetTemplateScene		(I3DShScene* scene, boolean fitIntoBBox, const TBBox3D& bbox) = 0;

	// ****************************************************************************
	//								SetSceneToPreview
	// 
	/// Set the scene to preview (for kSceneMode)
	/// 
	/// \param scene  
	/// 
	virtual void	MCCOMAPI SetSceneToPreview		(I3DShScene* scene) = 0;

	// ****************************************************************************
	//								SetPreviewMode
	// 
	/// Set the preview mode (flat, sphere, object or scene)
	/// 
	/// \param previewMode   kFlatMode, kSphereMode, kObjectMode or kSceneMode
	/// 
	virtual void	MCCOMAPI SetPreviewMode			(int16 previewMode) = 0;

	// ****************************************************************************
	//								SetMasterShader
	// 
	/// Set the master shader on the object of the preview
	/// 
	/// \param master  the master shader.
	/// \param withDisplacement   If true object will use the displacement shader of the master shader.
	/// 
	virtual void	MCCOMAPI SetMasterShader		(I3DShMasterShader* master, boolean withDisplacement = false) = 0;

	// ****************************************************************************
	//								SetCamera
	// 
	/// Set the camera from where we want to see the preview scene.
	/// 
	/// \param camera  The camera. (must be in the preview scene).
	/// 
	virtual void	MCCOMAPI SetCamera				(I3DShCamera* camera) = 0;

	// ****************************************************************************
	//								SetObjectToPreview
	// 
	/// Set the object to preview (for kObjectMode)
	/// 
	/// \param object      the object.
	/// \param xyzScaling  the non-uniform scaling of the object.
	/// 
	virtual void	MCCOMAPI SetObjectToPreview		(I3DShObject* object, const TVector3& xyzScaling) = 0;

	// ****************************************************************************
	//								SetObjectRotation
	// 
	/// Rotate the object in the preview scene.
	/// 
	/// \param matrix		the rotatin matrix
	/// 
	virtual void	MCCOMAPI SetObjectRotation		(const TMatrix33& matrix) = 0;

	// ****************************************************************************
	//								SetRenderingCallbacks
	// 
	/// Set the rendering call backs if they should be different than standard ones.
	/// 
	/// \param callback  the callback to use after finishing each tile.
	/// 
	virtual void	MCCOMAPI SetRenderingCallbacks	(I3DRenderingCallbacks* callback) = 0;

	// ****************************************************************************
	//								SetTiling
	// 
	/// Set the width and height of the tiles
	/// 
	/// \param width   the width of one tile in pixels.
	/// \param height  the height of one tile in pixels.
	/// 
	virtual void	MCCOMAPI SetTiling				(uint32 width,uint32 height) =  0;

	// ****************************************************************************
	//								SetUseDefaultBackgroundColor
	// 
	/// Specify if the preview is to use the default background color or not
	/// 
	/// \param useIt  If true the preview will use the background color.
	/// 
	virtual void	MCCOMAPI SetUseDefaultBackgroundColor(boolean useIt) = 0;

	// ****************************************************************************
	//								SetAutoFraming
	// 
	/// Autoframing will move camera for the object to fit in the view.
	/// 
	/// \param isAuto  if True set autoframing.
	/// 
	virtual void	MCCOMAPI SetAutoFraming			(boolean isAuto) = 0;

	// ****************************************************************************
	//								GetPreviewMode
	// 
	/// Get the preview mode (flat, sphere, object or scene)
	/// 
	/// \return the preview mode: kFlatMode, kSphereMode, kObjectMode or kSceneMode
	/// 
	virtual int16				MCCOMAPI GetPreviewMode			() = 0;

	// ****************************************************************************
	//								GetMasterShaderNoAddRef
	// 
	/// Get a link to the master shader of the object previewed
	/// 
	/// \return the mastershader.
	/// 
	virtual I3DShMasterShader*	MCCOMAPI GetMasterShaderNoAddRef() = 0;

	// ****************************************************************************
	//								GetCameraNoAddRef
	// 
	/// Get a link to the active camera of the preview scene
	/// 
	/// \return the camera.
	/// 
	virtual I3DShCamera*		MCCOMAPI GetCameraNoAddRef		() = 0;

	// ****************************************************************************
	//								GetSceneNoAddRef
	// 
	/// Get a link to the preview scene.
	/// 
	/// \return the preview scene. Return the template scene if not in kSceneMode
	/// 
	virtual I3DShScene*			MCCOMAPI GetSceneNoAddRef		() = 0;

	// ****************************************************************************
	//								GetObjectInstanceNoAddRef
	// 
	/// Get a link to the instance of the preview object
	/// 
	/// \return the instance of the object.
	/// 
	virtual I3DShInstance*		MCCOMAPI GetObjectInstanceNoAddRef() = 0;

	// Render methods
	// ****************************************************************************
	//								InitPreviewer
	// 
	/// Should be call after all the settings have been set and befor the render.
	/// 
	/// 
	virtual void	MCCOMAPI InitPreviewer	() = 0;

	// ****************************************************************************
	//								Reset
	// 
	/// reset the position of the object. Should not be called in kSceneMode
	/// 
	/// 
	virtual void	MCCOMAPI Reset	() = 0;

	// ****************************************************************************
	//								RenderPreview
	// 
	/// Renders a preview of the scene
	/// 
	/// \param outBucket         the resulting preview
	/// \param renderingQuality  defines the quality of the rendering (antialiasing, shadows...)
	/// \param rect              reserved
	/// \param inZone            the zone to render
	/// \param withAlphaChannel  render also the alpha channel            
	/// \param synchThreadID     id of the thread we are in, ( 0 will always work....)
	/// 
	virtual void	MCCOMAPI RenderPreview  (TMCPixelBucket& outBucket,const TRenderingQuality& renderingQuality,TMCRect* rect = NULL, TRenderArea* inZone = NULL , boolean withAlphaChannel = true, int32 synchThreadID = 0 ) = 0;

	// ****************************************************************************
	//								AbortRendering
	// 
	/// Abort the rendering of the preview
	/// 
	/// 
	virtual void	MCCOMAPI AbortRendering	() = 0;

	// ****************************************************************************
	//								CopyFromRasterlayerToBucket
	// 
	/// Copy a part of the already calculated preview.
	/// 
	/// \param outBucket  a bucket to store the result
	/// \param area       the area to get from the preview.
	/// 
	virtual	void	MCCOMAPI CopyFromRasterlayerToBucket(TMCPixelBucket& outBucket,const TMCRect& area) = 0;

	// ****************************************************************************
	//								SetObjectHotPoint
	// 
	/// Set the hot point the object in the preview scene.
	/// 
	/// \param hotPoint		the hot point vector
	/// 
	virtual void	MCCOMAPI SetObjectHotPoint		(const TVector3& hotPoint) = 0;
};

/// \}
#endif