IProjectionRenderHandler.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE:           ProjectionRenderHandler.h
00004 
00005     DESCRIPTION:    Render time functionality for projection mapping
00006 
00007     CREATED BY:     Michaelson Britt
00008 
00009     HISTORY:        05-01-2004
00010 
00011  *> Copyright (c) 2004, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 
00015 #pragma once
00016 
00017 #include "maxheap.h"
00018 #include "istdplug.h"
00019 #include "iparamb2.h"
00020 #include "iparamm2.h"
00021 
00022 //-----------------------------------------------------------------------------
00023 // Types
00024 
00025 class IMeshWrapper;
00026 class IProjectionRenderMgr;
00027 
00028 
00029 struct GenTri: public MaxHeapOperators {
00030     int v0, v1, v2;
00031 };
00032 
00033 struct GenTriPoints: public MaxHeapOperators {
00034     Point3 v0, v1, v2;
00035 };
00036 
00037 struct TangentBasis: public MaxHeapOperators {
00038     Point3 uBasis, vBasis;
00039 };
00040 
00041 
00042 //===========================================================================
00043 //
00044 // Class IProjectionRenderHandler
00045 //
00046 //===========================================================================
00047 
00048 class IProjectionRenderHandler: public MaxHeapOperators {
00049     public:
00050         struct ProjectionResult: public MaxHeapOperators {
00051             RenderInstance* inst;
00052             IMeshWrapper*   mesh; //CAMERA SPACE mesh wrapper for the inst
00053             float           dist;
00054             int             faceIndex;
00055             Point3          faceBary;
00056             BOOL            isBackfacing;
00057             int             err; //used when Project() returns FALSE
00058         };
00059 
00060         enum { ERR_NONE=0,
00061             ERR_RAYMISS,    //ray did not hit a reference model
00062             ERR_NONSELFACE, //the working model face is not in the active selection, skipped
00063         };
00064 
00065 
00066         virtual ~IProjectionRenderHandler() {}
00067         virtual void        DeleteThis() = 0;
00068 
00069         virtual int         RenderBegin(TimeValue t, ULONG flags=0) = 0;
00070         virtual int         RenderEnd(TimeValue t) = 0;
00071 
00072         // NOTE: Init() may require several seconds to calculate sorting structures for the reference models
00073         virtual BOOL        Init( RenderInstance* workingModelInst, RenderGlobalContext* rgc ) = 0;
00074         virtual BOOL        Valid() = 0; //true if initialized, false otherwise
00075         // Reference & working model info
00076         virtual void                GetReferenceModels( Tab<RenderInstance*>& refModels ) = 0;
00077         virtual IMeshWrapper*       GetWorkingModelMesh() = 0;
00078         virtual RenderInstance*     GetWorkingModelInst() = 0;
00079         virtual void                GetWorkingModelMask( BitArray& mask ) = 0;
00080 
00081         // Do the projection from working model to reference model
00082         virtual BOOL        Project( int faceIndex, Point3& faceBary, Point3& faceNorm, ProjectionResult& result ) = 0;
00083 };
00084 
00085 
00086 // Manager class to create render handler instances
00087 
00088 #define IPROJECTIONRENDERMGR_INTERFACE_ID Interface_ID(0x45390e61, 0x42de3b37)
00089 inline IProjectionRenderMgr* GetIProjectionRenderMgr()
00090 {return (IProjectionRenderMgr*)GetCOREInterface(IPROJECTIONRENDERMGR_INTERFACE_ID);}
00091 
00092 class IProjectionRenderMgr : public FPStaticInterface {
00093     public:
00094         virtual IProjectionRenderHandler* CreateProjectionRenderHandler() = 0;
00095 };
00096 
00097 
00098 //===========================================================================
00099 //
00100 // Class IMeshWrapper
00101 // An object defined as a set of triangles
00102 //
00103 //===========================================================================
00104 
00105 
00106 //FIXME: hopefully this can become a subclass of ObjectWrapper
00107 class IMeshWrapper: public MaxHeapOperators {
00108     public:
00109         virtual ~IMeshWrapper() {;}
00110         virtual void        DeleteThis() = 0;
00111 
00112         virtual int         NumTriangles() = 0;
00113         // For a given triangle, find the face number, and the index of the triangle within the face
00114         virtual void        Translate( int rawTriIndex, int& faceIndex, int& faceTriIndex ) = 0;
00115 
00116         // Transform affects the geometry & geom normals, but not the mapping data
00117         virtual Matrix3     GetTM() = 0;
00118         virtual void        SetTM( Matrix3 tm ) = 0;
00119 
00120         // Geom triangles & verts
00121         virtual GenTri      GetTri( int triIndex ) = 0;
00122         virtual void        GetTriPoints( int triIndex, GenTriPoints& triPoints ) = 0;
00123         virtual Point3      GetVert( int vertIndex ) = 0;
00124         virtual int         NumVerts() = 0;
00125 
00126         // Map triangles & verts
00127         virtual BOOL        GetChannelSupport( int mapChannel ) = 0;
00128         virtual GenTri      GetMapTri( int triIndex, int mapChannel ) = 0;
00129         virtual void        GetMapTriPoints( int triIndex, int mapChannel, GenTriPoints& triPoints ) = 0;
00130         virtual Point3      GetMapVert( int vertIndex, int mapChannel ) = 0;
00131         virtual int         NumMapVerts( int mapChannel ) = 0;
00132     
00133         // Normals
00134         virtual Point3      GetNormal( int triIndex ) = 0;
00135         virtual TangentBasis GetTangentBasis( int triIndex, int mapChannel ) = 0;
00136         virtual Point3      GetVertexNormal( int vertIndex, DWORD smGroup ) = 0;
00137         virtual TangentBasis GetVertexTangentBasis( int vertIndex, DWORD smGroup, int mapChannel ) = 0;
00138         virtual Point3      GetMapNormal( int triIndex, int mapChannel ) = 0; //UVW space
00139 
00140         // Face properties
00141         virtual MtlID       GetMtlID( int triIndex ) = 0;
00142         virtual DWORD       GetSmoothingGroup( int triIndex ) = 0;
00143 
00144         // Helpers
00145         virtual void        GetPoint( int triIndex, const Point3& triBary, Point3& point ) = 0;
00146         virtual void        GetMapPoint( int triIndex, const Point3& triBary, int mapChannel, Point3& uvw ) = 0;
00147         virtual void        GetNormal( int triIndex, const Point3& triBary, Point3& point ) = 0;
00148         virtual void        GetTangentBasis( int triIndex, const Point3& triBary, int mapChannel, TangentBasis& tangentBasis ) = 0;
00149 };
00150 
00151