renderelements.h

Go to the documentation of this file.
00001 
00002 //
00003 //
00004 //  Render Element Plug-Ins
00005 //
00006 //  Created 4/15/2000   Kells Elmquist
00007 //
00008 
00009 #pragma once
00010 
00011 // includes
00012 #include "maxheap.h"
00013 #include "sfx.h"
00014 
00015 // forward declarations
00016 class IllumParams;
00017 namespace MaxSDK
00018 {
00019     namespace AssetManagement
00020     {
00021         class AssetUser;
00022     }
00023 }
00024 
00025 
00026 #define BEAUTY_RENDER_ELEMENT_CLASS_ID          0x00000001
00027 
00028 #define SHADOWS_RENDER_ELEMENT_CLASS_ID         0x00000008
00029 #define Z_RENDER_ELEMENT_CLASS_ID               0x0000000c
00030 #define ALPHA_RENDER_ELEMENT_CLASS_ID           0x0000000d
00031 #define LIGHTING_RENDER_ELEMENT_CLASS_ID        0x00000011
00032 #define MATERIALID_RENDER_ELEMENT_CLASS_ID      0x00000014
00033 #define OBJECTID_RENDER_ELEMENT_CLASS_ID        0x00000015
00034 #define ILLUMINANCE_RENDER_ELEMENT_CLASS_ID     0x00000017
00035 
00036 
00037 // Returned by a RenderElement when it is asked to put up its rollup page.
00038 typedef SFXParamDlg IRenderElementParamDlg;
00039 
00040 
00042 //
00043 //      RenderElement base interface
00044 //
00045 //      class SpecialFX declared in maxsdk/include/render.h
00046 //
00058 #pragma warning(push)
00059 #pragma warning(disable:4100)
00060 class IRenderElement : public SpecialFX
00061 {
00062 public:
00063     // set/get element's enabled state
00068     virtual void SetEnabled(BOOL enabled)=0;
00071     virtual BOOL IsEnabled() const = 0;
00072 
00073     // set/get element's filter enabled state
00080     virtual void SetFilterEnabled(BOOL filterEnabled)=0;
00086     virtual BOOL IsFilterEnabled() const =0;
00087 
00088     // is this element to be blended for multipass effects?
00098     virtual BOOL BlendOnMultipass() const =0;
00099 
00102     virtual BOOL AtmosphereApplied() const =0;
00103 
00106     virtual BOOL ShadowsApplied() const =0;
00107 
00108     // set/get element's name (as it will appear in render dialog)
00114     virtual void SetElementName( const MCHAR* newName )=0; 
00115 
00116     // deprecated method - implement SetElementName(const MCHAR *newName) 
00117     virtual void SetElementName( MCHAR* newName ) { SetElementName(const_cast<const MCHAR*>(newName)); }
00118 
00121     virtual const MCHAR* ElementName() const =0;
00122 
00133     virtual void SetPBBitmap(PBBitmap* &pPBBitmap) const =0;
00139     virtual void GetPBBitmap(PBBitmap* &pPBBitmap) const =0;
00140 
00141     // this is the element specific optional UI, which is a rollup in the render dialog
00152     virtual IRenderElementParamDlg *CreateParamDialog(IRendParams *ip) { return NULL; }
00153 
00154     // Implement this if you are using the ParamMap2 AUTO_UI system and the 
00155     // IRenderElement has secondary dialogs that don't have the IRenderElement as their 'thing'.
00156     // Called once for each secondary dialog, for you to install the correct thing.
00157     // Return TRUE if you process the dialog, false otherwise.
00170     virtual BOOL SetDlgThing(IRenderElementParamDlg* dlg) { return FALSE; }
00171 
00172     // ---------------------
00173     // from class RefMaker
00174     // ---------------------
00175     // it is critical for merging that this code is called at the start of a plug-in's save and load methods.
00176     // SpecialFX's base implementation saves/loads SpecialFX::name, which is used to populate the 'Merge Render Elements'
00177     // dialog box. if a plugin re-implements this function, it should first call IRenderElement::Save(iSave)
00178     // or IRenderElement::Load(iLoad)
00194     IOResult Save(ISave *iSave)
00195     {
00196         name = ElementName();
00197         return SpecialFX::Save(iSave);
00198     }
00211     IOResult Load(ILoad *iLoad)
00212     {
00213         return SpecialFX::Load(iLoad);
00214     }
00215 
00240     virtual RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message) { return REF_SUCCEED; }
00241 
00242     // ---------------------
00243     // from class Animatable
00244     // ---------------------
00248     SClass_ID SuperClassID() { return RENDER_ELEMENT_CLASS_ID; }
00249 
00250     // renderer will call this method to see if IRenderElement is compatible with it
00251     using SpecialFX::GetInterface;
00265     virtual void* GetInterface(ULONG id) =0;
00266 
00270     virtual void ReleaseInterface(ULONG id, void *i) =0;
00271 };
00272 
00273 //==============================================================================
00274 // class IRenderElementRequirements
00275 //
00276 // This interface is used to query special requirement flags from render elements.
00277 //==============================================================================
00279 #define IRENDERELEMENTREQUIREMENTS_INTERFACE_ID Interface_ID(0x1804343c, 0x614c2fdf)
00280 class IRenderElementRequirements : public BaseInterface {
00281 public:
00282 
00284     enum Requirement {
00285         kRequirement_MotionData = 0 
00286     };
00287 
00291     virtual bool HasRequirement(Requirement requirement) = 0;
00292 
00293     // -- from BaseInterface
00295     virtual Interface_ID GetID();
00296 };
00297 
00298 inline Interface_ID IRenderElementRequirements::GetID() {
00299 
00300     return IRENDERELEMENTREQUIREMENTS_INTERFACE_ID;
00301 }
00302 
00304 
00309 inline IRenderElementRequirements* Get_RenderElementRequirements(IRenderElement* element) {
00310 
00311     return (element != NULL) ? static_cast<IRenderElementRequirements*>(element->GetInterface(IRENDERELEMENTREQUIREMENTS_INTERFACE_ID)) : NULL;
00312 }
00313 
00315 //
00316 //      RenderElement base class for max's default scanline renderer.
00317 //      RenderElement plugins that utilize ShadeContext and IllumParams
00318 //      should sub-class from here
00319 //
00320 
00341 class MaxRenderElement : public IRenderElement
00342 {
00343     friend class FilterComp;
00344 protected:
00345     int mShadeOutputIndex;
00346 
00347 public:
00348     // this interface's ID
00349     enum { IID = 0xeffeeffe };
00350 
00351     // set/get this element's index into the ShadeOutput's array of element channels
00361     void SetShadeOutputIndex(int shadeOutputIndex) { mShadeOutputIndex = shadeOutputIndex; }
00368     int ShadeOutputIndex() const { return mShadeOutputIndex; }
00369 
00370     // will be called on each element before call to PostIllum()
00381     virtual void Update(TimeValue timeValue) { }
00382 
00383     // compute the element and store in the ShadeContext's ShadeOutput.
00410     virtual void PostIllum(ShadeContext& sc, IllumParams& ip) =0;
00411 
00412     // called after atmospheres are computed, to allow elements to handle atmospheres
00435     virtual void PostAtmosphere(ShadeContext& sc, float z, float prevZ) =0;
00436 
00437     // ---------------------
00438     // from class Animatable
00439     // ---------------------
00440     // renderer will call this method to see if IRenderElement is compatible with it
00441     using IRenderElement::GetInterface;
00453     virtual void* GetInterface(ULONG id){ return (id == IID) ? this : SpecialFX::GetInterface(id);}
00457     virtual void ReleaseInterface(ULONG id, void *i) { }
00458 };
00459 
00460 #pragma warning(pop)
00461 
00462 //
00463 //      RenderElement base class for texture baking elements using
00464 //      max's default scanline renderer.
00465 //
00480 class MaxBakeElement : public MaxRenderElement
00481 {
00482 
00483 public:
00484     // this interface's ID
00485     enum { IID = 0xeffeefff };
00486 
00487     // these are the common attributes for texture bake elements
00488     // set/get element's output size, shd always be square
00497     virtual void SetOutputSz( int xSz, int ySz ) = 0;
00506     virtual void GetOutputSz( int& xSz, int& ySz ) const = 0;
00507 
00515     virtual void SetFileName( const MCHAR* newName) = 0;
00516 
00517     // deprecated method - implement SetFileName(const MCHAR *newName) 
00518     virtual void SetFileName( MCHAR* newName) { SetFileName(const_cast<const MCHAR*>(newName)); }
00519 
00522     virtual const MCHAR* GetFileName() const = 0;
00532     virtual void SetFileType( const MCHAR* newType) = 0;
00533 
00534     // deprecated method - implement SetFileType(const MCHAR *newType) 
00535     virtual void SetFileType( MCHAR* newType) { SetFileType(const_cast<const MCHAR*>(newType)); }
00536 
00540     virtual const MCHAR* GetFileType() const = 0;
00541 
00543     virtual void SetFileNameUnique(BOOL on) = 0; 
00545     virtual BOOL IsFileNameUnique() const = 0;
00546 
00547     // set/get the renderingbitmap, max of sizes
00548     // no memory management of the bitmap!
00557     virtual void SetRenderBitmap( Bitmap* pBitmap ) = 0;
00560     virtual Bitmap* GetRenderBitmap() const = 0;
00561 
00562     // set/get whether the output texture is shaded, or represents raw
00563     // texture colors
00572     virtual void SetLightApplied(BOOL on) = 0; 
00575     virtual BOOL IsLightApplied() const = 0;
00576 
00577     // set/get element's shadow applied state
00586     virtual void SetShadowApplied(BOOL on) = 0;
00590     virtual BOOL IsShadowApplied() const = 0;
00591 
00592 
00593     // set/get element's atmosphere applied state
00601     virtual void SetAtmosphereApplied(BOOL on) = 0;
00605     virtual BOOL IsAtmosphereApplied() const = 0;
00606 
00607         // these IRenderElement methods hooked to new functions
00608     virtual BOOL AtmosphereApplied() const {
00609             return IsAtmosphereApplied();
00610         }
00611     virtual BOOL ShadowsApplied() const {
00612             return IsShadowApplied();
00613         }
00614 
00615     // these allow us to build dynamic ui for the elements in maxscript
00616     // currently only checkboxes supported
00617     // these use & return 0-based indices
00620     virtual int GetNParams() const = 0;
00629     virtual const MCHAR* GetParamName( int nParam ) = 0;
00642     virtual const int FindParamByName( MCHAR* name ) = 0;
00651     virtual int  GetParamType( int nParam ) = 0;
00659     virtual int  GetParamValue( int nParam ) = 0;
00666     virtual void SetParamValue( int nParam, int newVal ) = 0;
00667 
00668     // ---------------------
00669     // from class Animatable
00670     // ---------------------
00671     SClass_ID SuperClassID() { return BAKE_ELEMENT_CLASS_ID; }
00672     
00673     // renderer will call this method to see if IRenderElement is compatible with it
00674     using MaxRenderElement::GetInterface;
00675     virtual void* GetInterface(ULONG id){ return (id == IID) ? this : MaxRenderElement::GetInterface(id);}
00676     
00677     virtual void ReleaseInterface(ULONG id, void *i) { UNUSED_PARAM(id); UNUSED_PARAM(i); }
00678 };
00679 
00681 //
00683 
00686 class MaxBakeElement8 : public MaxBakeElement
00687 {
00688 public:
00690     enum { IID = 0x1f2203c5 };
00691 
00693 
00695     virtual int GetParamType( int nParam ) = 0;
00696 
00698 
00700     virtual FPValue GetParamFPValue( int nParam ) = 0;
00701 
00703 
00705     virtual void SetParamFPValue( int nParam, FPValue newVal ) = 0;
00706 
00707 
00709 
00711     virtual FPValue GetParamFPValueMin( int nParam ) = 0;
00712 
00714 
00716     virtual FPValue GetParamFPValueMax( int nParam ) = 0;
00717 
00718     // ---------------------
00719     // from class Animatable
00720     // ---------------------
00721     using MaxBakeElement::GetInterface;
00723     virtual void* GetInterface(ULONG id){ return (id == IID) ? this : MaxBakeElement::GetInterface(id);}
00724     
00725 };
00726 
00728 //
00730 
00731 class MaxBakeElement10 : public MaxBakeElement8
00732 {
00733 public:
00735     enum { IID = 0x3b6566df };
00736 
00738 
00739     virtual AColor GetBackgroundColor( ) = 0;
00740 
00742 
00743     virtual void SetBackgroundColor( AColor color ) = 0;
00744 
00745     // ---------------------
00746     // from class Animatable
00747     // ---------------------
00748     using MaxBakeElement::GetInterface;
00750     virtual void* GetInterface(ULONG id){ return (id == IID) ? this : MaxBakeElement8::GetInterface(id);}
00751 
00752 };
00753 
00755 //
00756 //      IRenderElement compatibility interface
00757 //
00758 //      The system will ask a Renderer for this interface by calling
00759 //      Renderer::GetInterface(IRenderElementCompatible::ICompatibleID).
00760 //      If the Renderer returns a pointer to this interface, it is implied that the Renderer
00761 //      supports render elements. The system will then call IRenderElementCompatible::IsCompatible()
00762 //      to determine if an IRenderElement instance is compatible with it.
00763 //
00764 //      To determine compatibility, the Renderer can call IRenderElement::GetInterface()
00765 //      (inherited from class Animatable), passing in an interface ID that a compatible IRenderElement
00766 //      would understand. If the Renderer receives a valid interface pointer, it can return TRUE to
00767 //      IRenderElementCompatible::IsCompatible().
00768 //
00769 //      for an example, see class IScanRenderElement below
00770 //
00784 class IRenderElementCompatible: public MaxHeapOperators
00785 {
00786 public:
00787     // this interface's ID
00788     enum { IID = 0xcafeface };
00789 
00796     virtual BOOL IsCompatible(IRenderElement *pIRenderElement) = 0;
00797 };
00798 
00799 
00801 //
00802 //      RenderElementMgr base interface
00803 //
00804 #define IREND_ELEM_MGR_INTERFACE Interface_ID(0x95791767, 0x17651746)
00805 
00806 
00813 class IRenderElementMgr : public FPMixinInterface
00814 {
00815 public:
00816 
00817     // called by system to add an element merged from another file
00824     virtual BOOL AppendMergedRenderElement(IRenderElement *pRenderElement) = 0;
00832     virtual BOOL AppendMergedRenderElement(ReferenceTarget *pRenderElement) = 0; // ensures ReferenceTarget is a render element
00833 
00834     // adds/removes an instance of IRenderElement to the manager's list
00841     virtual BOOL AddRenderElement(IRenderElement *pRenderElement) = 0;
00848     virtual BOOL AddRenderElement(ReferenceTarget *pRenderElement) = 0; // ensures ReferenceTarget is a render element
00849     virtual BOOL RemoveRenderElement(IRenderElement *pRenderElement) = 0;
00856     virtual BOOL RemoveRenderElement(ReferenceTarget *pRenderElement) = 0; // ensures ReferenceTarget is a render element
00859     virtual void RemoveAllRenderElements() = 0;
00860 
00861     // returns number of render elements in manager's list
00864     virtual int NumRenderElements() = 0;
00865 
00866     // returns pointer to a specific render element in manager's list -- NULL if invalid index
00874     virtual IRenderElement *GetRenderElement(int index) = 0;
00875 
00876     // sets/gets whether element list should be active during a render
00882     virtual void SetElementsActive(BOOL elementsActive) = 0;
00885     virtual BOOL GetElementsActive() const = 0;
00886 
00887     // sets/gets whether elements should be displayed in their own viewer
00893     virtual void SetDisplayElements(BOOL displayElements) = 0;
00897     virtual BOOL GetDisplayElements() const = 0;
00898 
00899     // sets/gets whether element list should be exported to Combustion file format
00905     virtual void SetCombustionOutputEnabled(BOOL combustionOutEnabled) = 0;
00909     virtual BOOL GetCombustionOutputEnabled() const = 0;
00910 
00916     virtual void SetCombustionOutput(const MaxSDK::AssetManagement::AssetUser& combustionOutputPath) = 0;
00919     virtual const MaxSDK::AssetManagement::AssetUser& GetCombustionOutput() const = 0;
00920 
00921 
00922 #ifndef NO_RENDER_ELEMENTS
00923     // function publishing
00924     enum
00925     {
00926         fps_AddRenderElement, fps_RemoveRenderElement, fps_RemoveAllRenderElements,
00927         fps_NumRenderElements, fps_GetRenderElement,
00928         fps_SetElementsActive, fps_GetElementsActive,
00929         fps_SetDisplayElements, fps_GetDisplayElements,
00930         fps_SetCombustionOutputEnabled, fps_GetCombustionOutputEnabled,
00931         fps_SetCombustionOutputPath, fps_GetCombustionOutputPath,
00932         fps_SetRenderElementFilename, fps_GetRenderElementFilename,
00933     };
00934 #endif // NO_RENDER_ELEMENTS
00935 
00936 };
00937