imtl.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        imtl.h
00012 // DESCRIPTION: Renderer materials
00013 // AUTHOR:      Dan Silva 
00014 // HISTORY:      
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 
00019 
00020 #include "maxheap.h"
00021 #include "plugapi.h"
00022 #include "RenderElements.h"
00023 
00024 //#include "gport.h" 
00025 #include "custcont.h" 
00026 #include "shape.h"
00027 #include "buildver.h"
00028 #include "autoptr.h"
00029 #include "MtlBaseList.h"
00030 #include "quat.h"
00031 
00032 // forward declarations
00033 class TextureInfo;
00034 class MNMesh;
00035 class TimeChangeCallback;
00036 class Renderer;
00037 class ViewParams;
00038 class ShadeContext;
00039 class Bitmap;
00040 class RenderMapsContext; 
00041 class Object;
00042 class UVGen;
00043 class XYZGen;
00044 class Sampler;
00045 
00046 #define PROJ_PERSPECTIVE 0   // perspective projection
00047 #define PROJ_PARALLEL 1      // parallel projection
00048 
00049 #define AXIS_UV 0
00050 #define AXIS_VW 1
00051 #define AXIS_WU 2
00052 
00056 #define U_WRAP   (1<<0) //!< Indicates the texture map is tiled in the U direction.
00057 #define V_WRAP   (1<<1) //!< Indicates the texture map is tiled in the V direction.
00058 #define U_MIRROR (1<<2) //!< Indicates the texture map is mirrored in the U direction.
00059 #define V_MIRROR (1<<3) //!< Indicates the texture map is mirrored in the V direction.
00060 #define UV_NOISE (1<<4)
00061 #define UV_NOISE_ANI (1<<5)
00062 
00063 
00064 
00065 #define  X_AXIS 0
00066 #define  Y_AXIS 1
00067 #define  Z_AXIS 2
00068 
00069 static inline float Intens(const AColor& c) {   return (c.r+c.g+c.b)/3.0f; }
00070 static inline float Intens(const Color& c) { return (c.r+c.g+c.b)/3.0f; }
00071 
00072 // Meta-materials post this message to the MtlEditor when user
00073 // clicks on a sub-material button.
00074 #define WM_SUB_MTL_BUTTON  WM_USER + 0x04001
00075 
00076 // Materials or Texture maps post this message to the MtlEditor when user
00077 // clicks on a texture map button.
00078 #define WM_TEXMAP_BUTTON   WM_USER + 0x04002
00079 
00080 // Postage Stamp images ----------
00081 // GetImage fills an array RGB triples.
00082 // Width() and Height() return the dimensions of the image in pixels. 
00083 // The width in bytes of the array is given by the following macro, where w is pixel width. 
00084 
00085 #define PS_SMALL 0
00086 #define PS_LARGE 1
00087 #define PS_TINY  2
00088 
00089 #define PS_TINY_SIZE  24  // size of the tiny postage stamps
00090 #define PS_SMALL_SIZE 32  // size of the small postage stamps
00091 #define PS_LARGE_SIZE 88  // size of the large postage stamps
00092 #define PSDIM(isz) ((isz==0)?PS_SMALL_SIZE:(isz==1)?PS_LARGE_SIZE:PS_TINY_SIZE)
00093 
00094 #define ByteWidth(w) (((w*3+3)/4)*4)
00095 
00096 #pragma warning(push)
00097 #pragma warning(disable:4100)
00098 
00108 class PStamp: public AnimProperty {
00109      public:
00111      virtual int Width()=0;
00113      virtual int Height()=0;
00118      virtual void SetImage(UBYTE *img)=0;
00123      virtual void GetImage(UBYTE *img)=0;
00125      virtual void DeleteThis()=0;
00127      virtual IOResult Load(ILoad *iload)=0;
00129      virtual IOResult Save(ISave *isave)=0;
00130      };
00131 
00137 class TexHandle: public MaxHeapOperators {
00138      public:
00140             virtual ~TexHandle() {;}
00142             virtual DWORD_PTR GetHandle() = 0;
00144             virtual void DeleteThis() = 0;
00145      };    
00146 
00147 // Values for extraFlags:
00148 #define EX_MULT_ALPHA     1    // if alpha is NOT premultiplied in the Bitmap, set this 
00149 #define EX_RGB_FROM_ALPHA 2    // make map using alpha to define gray level 
00150 #define EX_OPAQUE_ALPHA   4    // make map using opaque alpha 
00151 #define EX_ALPHA_FROM_RGB 8    // make alpha from intensity 
00152 
00159 class TexHandleMaker: public MaxHeapOperators{
00160      public: 
00162             virtual ~TexHandleMaker() {;}
00163             // choice of two ways to create a texture handle.
00164             // From a 3DSMax Bitmap
00184             virtual TexHandle* CreateHandle(Bitmap *bm, int symflags=0, int extraFlags=0)=0;
00185 
00186             // From a 32 bit DIB
00207             virtual TexHandle* CreateHandle(BITMAPINFO *bminf, int symflags=0, int extraFlags=0)=0;
00208 
00209             // Create an 32 bit DIB with symmetry, extraflags already incorporated.
00210             // iff forceW is non-zero, it is used as the width of the final DIB 
00211             // iff forceH is non-zero, it is used as the height of the final DIB 
00237             virtual BITMAPINFO *BitmapToDIB(Bitmap *bm, int symflags, int extraFlags, BOOL forceW=0, BOOL forceH=0)=0;
00238 
00239             // From a 32 bit DIB that has symflags, extraflags already incorporated.
00246             virtual TexHandle* MakeHandle(BITMAPINFO*bminf)=0;  // this takes ownership of the BITMAPINFO*
00247 
00248             // This tells you the size desired of the bitmap. It ultimately
00249             // needs a bitmap that is a power of 2 in width and height.  If 
00250             // UseClosestPowerOf2 returns TRUE, then the bitmap need not be square.
00251             // If you already have a bitmap around, just pass it in to CreateHandle
00252             // and it will be converted.  If you are making a bitmap from scratch
00253             // (i.e.) a procedural texture, then you should make it Size() in 
00254             // width in height, and save us an extra step.  In either case
00255             // You own your bitmap, and are responsible for ultimately freeing it.
00256 
00259             virtual BOOL UseClosestPowerOf2()=0;
00270             virtual int Size()=0;
00271      };
00272 
00273 
00274 // Callback used with the new multi-texture interface by function SetGfxMtl. 
00280 class MtlMakerCallback: public TexHandleMaker {
00281      public:
00282      // This fills all the fields of texinf exept the texhandle and the texture ops.
00283      // note TexInfo is defined in mlt.h
00293      virtual void GetGfxTexInfoFromTexmap(TimeValue t, TextureInfo& texinf, Texmap *txm)=0;
00296      virtual BOOL NumberTexturesSupported()=0; // how many textures does the hardware+driver support
00297      };
00298 
00299 
00300 // passed to SetPickMode. This is a callback that gets called as
00301 // the user tries to pick objects in the scene.
00309 class PickObjectProc: public MaxHeapOperators {
00310      public:
00312             virtual ~PickObjectProc() {;}
00313             // Called when the user picks something.
00314             // return TRUE to end the pick mode.
00321             virtual BOOL Pick(INode *node)=0;
00322 
00323             // Return TRUE if this is an acceptable hit, FALSE otherwise.
00329             virtual BOOL Filter(INode *node)=0;
00330 
00331             // These are called as the mode is entered and exited
00336             virtual void EnterMode() {}
00341             virtual void ExitMode() {}
00342 
00343             // Provides two cursor, 1 when over a pickable object and 1 when not.
00350             virtual HCURSOR GetDefCursor() {return NULL;}
00357             virtual HCURSOR GetHitCursor() {return NULL;}
00358 
00359             // Return TRUE to allow the user to pick more than one thing.
00360             // In this case the Pick method may be called more than once.
00366             virtual BOOL AllowMultiSelect() {return FALSE;}
00367      };
00368 
00369 
00370 // Interface that is passed in to the Mtl or Texture Map when it is in the mtl
00371 // editor.
00377 class IMtlParams : public InterfaceServer {
00378      public:
00379      // call after mouse up's in mtls params
00380      // It causes the viewports to be redrawn.
00387      virtual void MtlChanged()=0;  
00388 
00389      // Adds rollup pages to the Material Params. Returns the window
00390      // handle of the dialog that makes up the page.
00428      virtual HWND AddRollupPage( HINSTANCE hInst, MCHAR *dlgTemplate, 
00429             DLGPROC dlgProc, MCHAR *title, LPARAM param=0,DWORD flags=0, int category = ROLLUP_CAT_STANDARD )=0;
00430 
00468      virtual HWND AddRollupPage( HINSTANCE hInst, DLGTEMPLATE *dlgTemplate, 
00469             DLGPROC dlgProc, MCHAR *title, LPARAM param=0,DWORD flags=0, int category = ROLLUP_CAT_STANDARD )=0;
00470 
00471 
00472      // Adds rollup pages to the Material Params. Returns the window
00473      // handle of the dialog that makes up the page.
00510      virtual HWND ReplaceRollupPage( HWND hOldRollup, HINSTANCE hInst, MCHAR *dlgTemplate, 
00511             DLGPROC dlgProc, MCHAR *title, LPARAM param=0,DWORD flags=0, int category = ROLLUP_CAT_STANDARD  )=0;
00512 
00550      virtual HWND ReplaceRollupPage( HWND hOldRollup, HINSTANCE hInst, DLGTEMPLATE *dlgTemplate, 
00551             DLGPROC dlgProc, MCHAR *title, LPARAM param=0,DWORD flags=0, int category = ROLLUP_CAT_STANDARD  )=0;
00552 
00553      // Removes a rollup page and destroys it.  When a dialog is destroyed
00554      // it need not delete all its rollup pages: the Mtl Editor will do
00555      // this for it, and it is more efficient.
00562      virtual void DeleteRollupPage( HWND hRollup )=0;
00563 
00564      // When the user mouses down in dead area, the plug-in should pass
00565      // mouse messages to this function which will pass them on to the rollup.
00584      virtual void RollupMouseMessage( HWND hDlg, UINT message, 
00585                         WPARAM wParam, LPARAM lParam )=0;
00586 
00592      virtual int IsRollupPanelOpen(HWND hwnd)=0;
00596      virtual int GetRollupScrollPos()=0;
00604      virtual void SetRollupScrollPos(int spos)=0;
00605 
00612      virtual void RegisterTimeChangeCallback(TimeChangeCallback *tc)=0;
00618      virtual void UnRegisterTimeChangeCallback(TimeChangeCallback *tc)=0;
00619 
00620      // Registers a dialog window so IsDlgMesage() gets called for it.
00621      // This is done automatically for Rollup Pages.
00627      virtual void RegisterDlgWnd( HWND hDlg )=0;
00632      virtual int UnRegisterDlgWnd( HWND hDlg )=0;
00633 
00634      // get the current time.
00638      virtual TimeValue GetTime()=0;   
00639 
00640      // Pick an object from the scene
00648      virtual void SetPickMode(PickObjectProc *proc)=0;
00650      virtual void EndPickMode()=0;
00651 
00652      // JBW 10/19/98: get interface to mtl editor rollup
00654      virtual IRollupWindow *GetMtlEditorRollup()=0;
00655 
00656      // Generic expansion function
00657      virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
00658      };
00659 
00660 class ParamDlg;
00661 class Texmap;
00662 
00668 class RenderData : public InterfaceServer {
00669      public:
00673         virtual void DeleteThis()=0;
00691             virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0;} 
00692      };
00693 
00713 class LightDesc : public RenderData {
00714      public:
00715             BOOL affectDiffuse;
00716             BOOL affectSpecular;
00717             BOOL  ambientOnly;
00718             DWORD  extra;
00721             LightDesc() { affectDiffuse = affectSpecular = TRUE; ambientOnly = FALSE; }
00722             // determine color and direction of illumination: return FALSE if light behind surface.
00723             // also computes dot product with normal dot_nl, and diffCoef which is to be used in
00724             // place of dot_n for diffuse light computations.
00768              virtual BOOL Illuminate(ShadeContext& sc, Point3& normal, Color& color, Point3 &dir, float &dot_nl, float &diffuseCoef){ return 0;}
00769             
00773             virtual Point3 LightPosition() { return Point3(0,0,0); } 
00774 
00775             CoreExport virtual void DeleteThis();
00776 
00777      };
00778 
00779 #define SHADELIM_FLAT 1
00780 #define SHADELIM_GOURAUD 2
00781 #define SHADELIM_PHONG 3
00782 
00783 // Transform Reference frames: 
00784 enum RefFrame { REF_CAMERA=0, REF_WORLD, REF_OBJECT };
00785 
00786 #define N_MAX_RENDER_ELEMENTS 32
00787 
00805 class ShadeOutput : public BaseInterfaceServer {
00806      public:
00807             ULONG flags;
00808             Color c;  // shaded color
00809             Color t;  // transparency
00810             float ior;  // index of refraction
00811             int gbufId;
00812 
00813             // render elements
00814             int nElements;
00815             AColor   elementVals[ N_MAX_RENDER_ELEMENTS ];
00816 
00849             CoreExport void MixIn(ShadeOutput& a, float f);  // (*this) =  (1-f)*(*this) + f*a;
00850             ShadeOutput():nElements(0), flags(0), gbufId(0){};
00851             ShadeOutput( int nEle ):flags(0), gbufId(0){ nElements = nEle; }
00860             void Reset( int nEle = -1 )
00861             { 
00862                  flags = 0;
00863                  gbufId = 0;
00864                  c.Black(); t.Black(); ior = 1.0f;
00865                  // clear nEle's worth of render elements
00866                  if (nEle >= 0)
00867                         nElements = nEle;
00868                  for( int i=0; i < nElements; ++i )
00869                         elementVals[i].r = elementVals[i].g =
00870                              elementVals[i].b = elementVals[i].a = 0.0f;
00871             }
00872             CoreExport ShadeOutput* Clone();       
00873 
00874             // Render Element interface
00875             // allocate new val, return index
00876             int NewElementVal(){
00877                  DbgAssert((nElements+1)<N_MAX_RENDER_ELEMENTS); 
00878                  return nElements++; 
00879             }
00880             int NElementVals(){ return nElements; }
00881             // override new val & set nElements directly, for clear mostly
00882             void SetNElements( int n ){
00883                  DbgAssert( n>=0 && n<N_MAX_RENDER_ELEMENTS); 
00884                  nElements = n;
00885             }
00886             // return rgba value of element n
00887             AColor ElementVal( int n ){ 
00888                  DbgAssert( n>=0 && n<N_MAX_RENDER_ELEMENTS); 
00889                  return elementVals[n]; 
00890             }
00891             // set rgba value of element n
00892             void SetElementVal( int n, AColor c ){ 
00893                  DbgAssert( n>=0 && n<N_MAX_RENDER_ELEMENTS); 
00894                  elementVals[n] = c; 
00895             }
00896             // sum rgba value intof element n
00897             void AccumElementVal( int n, AColor c ){ 
00898                  DbgAssert( n>=0 && n<N_MAX_RENDER_ELEMENTS); 
00899                  elementVals[n] += c; 
00900             }
00901             // sum all color components of a shade output
00902             void Sum( ShadeOutput* pSample ){
00903                  c += pSample->c; t += pSample->t;
00904                  for( int i = 0; i < nElements; ++i )
00905                         elementVals[i] += pSample->elementVals[i];
00906             }
00907             void Scale( float x ){
00908                  c *= x; t *= x;
00909                  for( int i = 0; i < nElements; ++i )
00910                         elementVals[i] *= x;
00911             }
00912             // sum all color components, w/o alpha of a shade output
00913             void SumClr( ShadeOutput* pSample ){
00914                  c += pSample->c; 
00915                  for( int i = 0; i < nElements; ++i ){
00916                         elementVals[i].r += pSample->elementVals[i].r;
00917                         elementVals[i].g += pSample->elementVals[i].g;
00918                         elementVals[i].b += pSample->elementVals[i].b;
00919                  }
00920             }
00921 
00922             ShadeOutput& operator += ( ShadeOutput& a ){
00923                  c += a.c;  
00924                  t += a.t; 
00925                  for( int i = 0; i < nElements; ++i )
00926                         elementVals[i] += a.elementVals[i];
00927                  return *this;
00928             }
00929             ShadeOutput& operator *= ( Color x ){
00930                  c *= x; // t *= x; 
00931                  AColor ac( x );
00932                  ac.a = Intens( x );
00933                  for( int i = 0; i < nElements; ++i )
00934                         elementVals[i] *= ac;
00935                  return *this;
00936             }
00937 
00938             ShadeOutput& operator = ( ShadeOutput& a ){
00939                  flags = a.flags;
00940                  c = a.c; t = a.t; 
00941                  ior = a.ior;
00942                  gbufId = a.gbufId;
00943                  nElements = a.nElements;
00944                  for( int i = 0; i < nElements; ++i )
00945                         elementVals[i] = a.elementVals[i];
00946                  return *this;
00947             }
00948 
00949 
00950      };
00951 
00952 
00953 class RenderInstance;
00954 
00961 struct ISect: public MaxHeapOperators {
00968      float t;   // ray parameter
00970      BOOL exit;
00972      BOOL backFace;
00974      RenderInstance *inst;
00976      int fnum;  // face number
00978      Point3 bc; // barycentric coords
00980      Point3 p;  // intersection point, object coords
00982      Point3 pc;  // intersection point, camera coords
00984      ULONG matreq;
00986      int mtlNum;
00988      ISect *next;
00989      };
00990 
01000 class ISectList: public MaxHeapOperators {
01001      public:
01002      ISect *first;
01004      ISectList() { first = NULL; }
01006      ~ISectList() { Init(); }
01008      BOOL IsEmpty() { return first?0:1; }
01014      CoreExport void Add(ISect *is); 
01020      CoreExport void Prune(float a); 
01023      CoreExport void Init();
01024      };
01025      
01029 CoreExport ISect *GetNewISect();
01039 CoreExport void DiscardISect(ISect *is);
01040 
01041 // Value given to blurFrame for non blurred objects  ( Object motion blur)
01042 #define NO_MOTBLUR (-1) 
01043 
01044 class FilterKernel;
01045 class IRenderElement;
01046 class ToneOperator;
01047 typedef  Tab<IRenderElement*> RenderElementTab;
01048 
01158 class RenderGlobalContext : public BaseInterfaceServer
01159 {
01160 protected:
01161      IRenderElementMgr *mpIRenderElementMgr; // current render element manager
01162 
01163 public:
01164      Renderer* renderer;
01165      int projType;  // PROJ_PERSPECTIVE or PROJ_PARALLEL
01166      int devWidth, devHeight;
01167      float xscale, yscale;
01168      float xc,yc;
01169      BOOL antialias;
01170      Matrix3 camToWorld, worldToCam;
01171      float nearRange, farRange;
01172      float devAspect;          // PIXEL aspect ratio of device pixel H/W
01173      float frameDur;
01174      Texmap *envMap;
01175      Color globalLightLevel;
01176      Atmospheric *atmos;
01177      ToneOperator* pToneOp;  // The tone operator, may be NULL
01178      TimeValue time;
01179      BOOL wireMode;    // wire frame render mode?
01180      float wire_thick; // global wire thickness
01181      BOOL force2Side;  // is force two-sided rendering enabled
01182      BOOL inMtlEdit;      // rendering in mtl editor?
01183      BOOL fieldRender; // are we rendering fields
01184      BOOL first_field; // is this the first field or the second?
01185      BOOL field_order; // which field is first: 0->even first,  1->odd first
01186 
01187      BOOL objMotBlur;  // is object motion blur enabled
01188      int nBlurFrames;  // number of object motion blur time slices
01189 
01190 #ifdef SIMPLIFY_AREA_LIGHTS
01191      bool simplifyAreaLights; //should area lights degrade to point lights
01192 #endif
01193 
01194 
01195      // Methods
01196      RenderGlobalContext() : pToneOp(NULL), mpIRenderElementMgr(NULL) { }
01197 
01198      // render element methods
01201      IRenderElementMgr *GetRenderElementMgr() { return mpIRenderElementMgr; }
01206      void SetRenderElementMgr(IRenderElementMgr *pIRenderElementMgr) { mpIRenderElementMgr = pIRenderElementMgr; }
01208      int NRenderElements()
01209      {
01210         return mpIRenderElementMgr ? mpIRenderElementMgr->NumRenderElements() : 0;
01211      } 
01216      IRenderElement* GetRenderElement(int n)
01217      {
01218         return mpIRenderElementMgr ? mpIRenderElementMgr->GetRenderElement(n) : NULL;
01219      }
01220      
01226      Point2 MapToScreen(Point3 p)
01227      {  
01228             if (projType==1)
01229             {
01230                  return Point2(  xc + xscale*p.x , yc + yscale*p.y);
01231             }
01232             else
01233             {
01234                  if (p.z==0.0f)
01235                         p.z = .000001f;
01236                  return Point2( xc + xscale*p.x/p.z,  yc + yscale*p.y/p.z);
01237             }
01238      }
01239 
01242      virtual FilterKernel* GetAAFilterKernel(){ return NULL; }
01245      virtual float GetAAFilterSize(){ return 0.0f; }
01246 
01247      // Access RenderInstances
01249      virtual int NumRenderInstances() { return 0; }
01255      virtual RenderInstance* GetRenderInstance( int i ) { return NULL; }
01256 
01257      // Evaluate the global environment map using ray as point of view,
01258      // optionally with atmospheric effect.
01271      virtual AColor EvalGlobalEnvironMap(ShadeContext &sc, Ray &r, BOOL applyAtmos)
01272      { 
01273             return AColor(0.0f,0.0f,0.0f,1.0f); 
01274      }
01275 
01297      virtual void IntersectRay(RenderInstance *inst, Ray& ray, ISect &isct, ISectList &xpList, BOOL findExit) {}
01330      virtual BOOL IntersectWorld(Ray &ray, int skipID, ISect &hit, ISectList &xplist, int blurFrame = NO_MOTBLUR) { return FALSE; }
01331 
01334      virtual ViewParams* GetViewParams() { return NULL; } 
01335 
01339      virtual FILE* DebugFile() { return NULL; }
01340 
01341      // Generic expansion function
01359      virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
01360 };
01361 
01362 
01363 // > 4/19/02 - 12:25am --MQM-- 
01364 // PLUG-IN DEVELOPER NOTE:
01365 //
01366 //    In this release we are using the xshadeID in the
01367 //    ShadeContext to store information during Light Tracer 
01368 //    and VIZ Radiosity renderings.  The developer should be
01369 //    sure to copy the xshadeID whenever creating new shade
01370 //    contexts based off of an existing ShadeContext instance.
01371 //
01372 //    The renderer performs two passes when a radiosity
01373 //    plugin is on.  The first pass is a very minimal pass,
01374 //    and the second is the normal pass.  Shader plugins
01375 //    can test for the pre-pass flag and possibly do less
01376 //    (or no) work.
01377 //
01378 //    During the regular pass, the Light Tracer will max out
01379 //    the rayLevel to halt raytraced reflections during regathering.  
01380 //    Shaders should also not do specular shading or other things 
01381 //    that will increase variance and/or slow regathering performance 
01382 //    down. 
01383 
01384 // we are inside of a regathering ray
01385 #define SHADECONTEXT_REGATHERING_FLAG        0x80000000  
01386 #define SHADECONTEXT_IS_REGATHERING( sc )    ( (sc).xshadeID & SHADECONTEXT_REGATHERING_FLAG )
01387 
01388 // we are in a pre-pass in the scanline renderer
01389 #define SHADECONTEXT_PREPASS_FLAG            0x40000000  
01390 #define SHADECONTEXT_IS_PREPASS( sc )        ( (sc).xshadeID & SHADECONTEXT_PREPASS_FLAG )
01391 
01392 // in recursive eval, so we don't try to 
01393 // regather something that we're already 
01394 // in the middle of...
01395 #define SHADECONTEXT_RECURSIVE_EVAL_FLAG     0x20000000  
01396 #define SHADECONTEXT_IS_RECURSIVE_EVAL( sc ) ( (sc).xshadeID & SHADECONTEXT_RECURSIVE_EVAL_FLAG )
01397 
01398 // matte material needs a way of getting the shadow values out
01399 // of light tracer.  (this is going away when we can change the sdk!!)
01400 #define SHADECONTEXT_GUESS_SHADOWS_FLAG         0x10000000
01401 #define SHADECONTEXT_GUESS_SHADOWS( sc )     ( (sc).xshadeID & SHADECONTEXT_GUESS_SHADOWS_FLAG )
01402 
01403 // scanline renderer thread #
01404 #define SHADECONTEXT_THREAD_MASK          0x0000F000  
01405 #define SHADECONTEXT_THREAD_SHIFT            12
01406 #define SHADECONTEXT_GET_THREAD( sc )        ( ( (sc).xshadeID & SHADECONTEXT_THREAD_MASK )  >> SHADECONTEXT_THREAD_SHIFT )
01407 #define SHADECONTEXT_SET_THREAD( sc, thread )   { (sc).xshadeID = ( (sc).xshadeID & (~SHADECONTEXT_THREAD_MASK) )  |  ( ( (thread) << SHADECONTEXT_THREAD_SHIFT ) & SHADECONTEXT_THREAD_MASK ); }
01408 
01409 // worker thread #
01410 #define SHADECONTEXT_WORKER_MASK          0x00000F00
01411 #define SHADECONTEXT_WORKER_SHIFT            8
01412 #define SHADECONTEXT_GET_WORKER( sc )        ( ( (sc).xshadeID & SHADECONTEXT_WORKER_MASK )  >> SHADECONTEXT_WORKER_SHIFT )
01413 #define SHADECONTEXT_SET_WORKER( sc, worker )   { (sc).xshadeID = ( (sc).xshadeID & (~SHADECONTEXT_WORKER_MASK) )  |  ( ( (worker) << SHADECONTEXT_WORKER_SHIFT ) & SHADECONTEXT_WORKER_MASK ); }
01414 
01415 // bounce # (1..255, 0 not used)
01416 #define SHADECONTEXT_BOUNCE_MASK          0x000000FF
01417 #define SHADECONTEXT_GET_BOUNCE( sc )        ( (sc).xshadeID & SHADECONTEXT_BOUNCE_MASK )
01418 #define SHADECONTEXT_SET_BOUNCE( sc, bounce )   { (sc).xshadeID = ( (sc).xshadeID & (~SHADECONTEXT_BOUNCE_MASK) )  |  ( (bounce) & SHADECONTEXT_BOUNCE_MASK ); }
01419 
01420 // general macro to init regathering info in the shade context.
01421 // this wipes out other flags in the xshadeID (prepass, etc)
01422 #define SHADECONTEXT_SET_REGATHERING_INFO( sc, thread, worker, bounce ) \
01423 { (sc).xshadeID = SHADECONTEXT_REGATHERING_FLAG  |  \
01424     ( ( (thread) << SHADECONTEXT_THREAD_SHIFT ) & SHADECONTEXT_THREAD_MASK )  |  \
01425     ( ( (worker) << SHADECONTEXT_WORKER_SHIFT ) & SHADECONTEXT_WORKER_MASK )  |  \
01426     ( (bounce) & SHADECONTEXT_BOUNCE_MASK ); }
01427 
01428 
01429 #define SCMODE_NORMAL  0
01430 #define SCMODE_SHADOW  1
01431 
01432 //
01433 // Shade Context: passed into Mtls and Texmaps
01434 //
01529 class ShadeContext : public InterfaceServer {
01530 public:
01531     ULONG mode;                   // normal, shadow ...
01532     BOOL doMaps;                  // apply texture maps?
01533     BOOL filterMaps;              // should texture be filtered                
01534     BOOL shadow;                  // apply shadows?
01535     BOOL backFace;                // are we on the back side of a 2-Sided face?
01536     int mtlNum;                   // sub-mtl number for multi-materials
01537     Color ambientLight;              // ambient light 
01538     int nLights;                  // number of lights;
01539     int rayLevel;
01540     int xshadeID;                    // different for every shade call in a render.
01541     LightDesc *atmosSkipLight;
01542     RenderGlobalContext *globContext;
01543     ShadeOutput out;                    // where a shading leaves its results
01544 
01545     // Reset output & render elements: 
01546     // param < 0 clears existing elements, leaving nElements unchanged
01547     // n >= 0 clears n elements & set nElements to n, default is 0
01553     void ResetOutput( int n = -1 ) { out.Reset(n); }   
01554 
01559     virtual Class_ID ClassID() { return Class_ID(0,0); }  // to distinguish different ShadeContexts.
01562     virtual BOOL InMtlEditor()=0; // is this rendering the mtl editor sample sphere?
01567     virtual int Antialias() {return 0;}
01573     virtual int ProjType() { return 0;} // returns: 0: perspective, 1: parallel
01579     virtual LightDesc* Light(int n)=0;  // get the nth light. 
01582     virtual TimeValue CurTime()=0;      // current time value
01588     virtual int NodeID() { return -1; }
01594     virtual INode *Node() { return NULL; }
01610     virtual Object *GetEvalObject() { return NULL; } // Returns the evaluated object for this node. 
01611     // Will be NULL if object is motion blurred  
01627     virtual Point3 BarycentricCoords() { return Point3(0,0,0);}  // coords relative to triangular face 
01634     virtual int FaceNumber()=0;         // 
01638     virtual Point3 Normal()=0;       // interpolated surface normal, in camera coords: affected by SetNormal()
01648     virtual void SetNormal(Point3 p) {} // used for perturbing normal
01653     virtual Point3 OrigNormal() { return Normal(); } // original surface normal: not affected by SetNormal();
01656     virtual Point3 GNormal()=0;      // geometric (face) normal
01663     virtual float  Curve() { return 0.0f; }          // estimate of dN/dsx, dN/dsy
01666     virtual Point3 V()=0;            // Unit view vector: from camera towards P 
01671     virtual void SetView(Point3 p)=0;   // Set the view vector
01676     virtual Point3 OrigView() { return V(); } // Original view vector: not affected by SetView();
01680     virtual  Point3 ReflectVector()=0;  // reflection vector
01687     virtual  Point3 RefractVector(float ior)=0;  // refraction vector
01695     virtual void SetIOR(float ior) {} // Set index of refraction
01699     virtual float GetIOR() { return 1.0f; } // Get index of refraction
01702     virtual Point3 CamPos()=0;       // camera position
01704     virtual Point3 P()=0;            // point to be shaded;
01708     virtual Point3 DP()=0;           // deriv of P, relative to pixel, for AA
01711     virtual void DP(Point3& dpdx, Point3& dpdy){};  // deriv of P, relative to pixel
01714     virtual Point3 PObj()=0;            // point in obj coords
01717     virtual Point3 DPObj()=0;           // deriv of PObj, rel to pixel, for AA
01720     virtual Box3 ObjectBox()=0;      // Object extents box in obj coords
01723     virtual Point3 PObjRelBox()=0;      // Point rel to obj box [-1 .. +1 ] 
01727     virtual Point3 DPObjRelBox()=0;     // deriv of Point rel to obj box [-1 .. +1 ] 
01735     virtual void ScreenUV(Point2& uv, Point2 &duv)=0; // screen relative uv (from lower left)
01738     virtual IPoint2 ScreenCoord()=0; // integer screen coordinate (from upper left)
01745     virtual Point2 SurfacePtScreen(){ return Point2(0.0,0.0); } // return the surface point in screen coords
01746 
01753     virtual Point3 UVW(int channel=0)=0;         // return UVW coords for point
01771     virtual Point3 DUVW(int channel=0)=0;        // return UVW derivs for point
01787     virtual void DPdUVW(Point3 dP[3],int channel=0)=0; // Bump vectors for UVW (camera space)
01788 
01789     // BumpBasisVectors: this is going to replace DPdUVW: Now compute bump vectors for 
01790     //  specific 2D cases only.
01791     //    axis = AXIS_UV, AXIS_VW, AXIS_WU    
01792     //    return:     0 => not implemented,  1=> implemented
01793     // If this function is implemented, it will be used instead of DPdUVW.
01811     virtual int BumpBasisVectors(Point3 dP[2], int axis, int channel=0) { return 0; } 
01812 
01813 
01814     virtual BOOL IsSuperSampleOn(){ return FALSE; }
01815     virtual BOOL IsTextureSuperSampleOn(){ return FALSE; }
01816     virtual int GetNSuperSample(){ return 0; }
01817     virtual float GetSampleSizeScale(){ return 1.0f; }
01818 
01819     // UVWNormal: returns a vector in UVW space normal to the face in UVW space. This can 
01820     // be CrossProd(U[1]-U[0],U[2]-U[1]), where U[i] is the texture coordinate
01821     // at the ith vertex of the current face.  Used for hiding textures on
01822     // back side of objects.
01834     virtual Point3 UVWNormal(int channel=0) { return Point3(0,0,1); }  
01835 
01836     // diameter of view ray at this point
01842     virtual float RayDiam() { return Length(DP()); } 
01843 
01844     // angle of ray cone hitting this point: gets increased/decreased by curvature 
01845     // on reflection
01858     virtual float RayConeAngle() { return 0.0f; } 
01859 
01870     CoreExport virtual AColor EvalEnvironMap(Texmap *map, Point3 view); //evaluate map with given viewDir
01880     virtual void GetBGColor(Color &bgcol, Color& transp, BOOL fogBG=TRUE)=0;   // returns Background color, bg transparency
01881 
01882     // Camera ranges set by user in camera's UI.
01885     virtual float CamNearRange() {return 0.0f;}
01888     virtual float CamFarRange() {return 0.0f;}
01889 
01890     // Transform to and from internal space
01902     virtual Point3 PointTo(const Point3& p, RefFrame ito)=0; 
01914     virtual Point3 PointFrom(const Point3& p, RefFrame ifrom)=0; 
01925     virtual Point3 VectorTo(const Point3& p, RefFrame ito)=0; 
01936     virtual Point3 VectorFrom(const Point3& p, RefFrame ifrom)=0; 
01947     CoreExport virtual Point3 VectorToNoScale(const Point3& p, RefFrame ito); 
01966     CoreExport virtual Point3 VectorFromNoScale(const Point3& p, RefFrame ifrom); 
01967 
01968     // After being evaluated, if a map or material has a non-zero GBufID, it should
01969     // call this routine to store it into the shade context.
01995     virtual void SetGBufferID(int gbid) { out.gbufId = gbid; }
01996 
01999     virtual FILE* DebugFile() { return NULL; }
02000 
02008     virtual AColor EvalGlobalEnvironMap(Point3 dir) { return AColor(0,0,0,0); }
02009 
02043     virtual BOOL GetCache(Texmap *map, AColor &c){ return FALSE; }
02055     virtual BOOL GetCache(Texmap *map, float &f) { return FALSE; }
02067     virtual BOOL GetCache(Texmap *map, Point3 &p){ return FALSE; }
02078     virtual void PutCache(Texmap *map, const AColor &c){}
02089     virtual void PutCache(Texmap *map, const float f) {}
02100     virtual void PutCache(Texmap *map, const Point3 &p){}
02108     virtual void TossCache(Texmap *map) {}
02109     // Generic expansion function
02126     virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
02127 
02128     // These are used to prevent self shadowing by volumetric lights
02150     LightDesc *GetAtmosSkipLight() { return atmosSkipLight; }
02166     void SetAtmosSkipLight(LightDesc *lt) { atmosSkipLight = lt; }
02167 
02168     // render element methods
02172     virtual int NRenderElements() { 
02173         return globContext ? globContext->NRenderElements():0;
02174     }
02181     virtual IRenderElement *GetRenderElement(int n) { 
02182         return globContext ? globContext->GetRenderElement(n) : NULL;
02183     }
02184 
02185     // diffuse illum utility, computes incoming diffuse illumination, for matte/shadow
02188     CoreExport virtual Color DiffuseIllum();
02189 
02190     // used to preshade in different ways
02191     // virtual IRenderMode GetIRenderMode(){ return IRM_NORMAL; }
02192     // IRenderMode GetIRenderMode(){ return iRenderMode; }
02193     // void SetIRenderMode( IRenderMode mode ){ iRenderMode = mode; }
02194 
02195     // NOTE: All of these methods are inline. The inline definitions not
02196     // declared here are declared in toneop.h
02197 
02198     // Does this tone operator really map physical values to RGB. This method
02199     // is provided so shaders can determine whether the shading calculations
02200     // are in physical or RGB space.
02204     bool IsPhysicalSpace() const;
02205 
02206     // Map an scaled energy value into RGB. The first version of the
02207     // method converts a color value and the second converts a monochrome
02208     // value. The converted color value is stored in <i>energy</i>.
02209     // The converted monochrome value is returned.
02215     template< class T > void ScaledToRGB( T& energy ) const
02216     {
02217         if ( globContext != NULL && globContext->pToneOp != NULL )
02218             globContext->pToneOp->ScaledToRGB( energy );
02219     }
02225     float ScaledToRGB( float energy ) const;
02226 
02227     // Map an energy value int out.c into RGB. The converted value is stored in
02228     // out.c.
02231     void ScaledToRGB( );
02232 
02233     // Scale physical values so they can be used in the renderer. The
02234     // first version of the method converts a color value and the second
02235     // converts a monochrome value. The converted color value is stored
02236     // in <i>energy</i>. The converted monochrome value is returned.
02242     template< class T > void ScalePhysical(T& energy) const
02243     {
02244         if ( globContext != NULL && globContext->pToneOp != NULL )
02245             globContext->pToneOp->ScalePhysical( energy );
02246     }
02252     float ScalePhysical(float energy) const;
02253 
02254     // Scale RGB values, just supplied to invert ScalePhysical. The first
02255     // version of the method converts a color value and the second
02256     // converts a monochrome value. The converted color value is stored
02257     // in <i>energy</i>. The converted monochrome value is returned.
02263     template< class T > void ScaleRGB(T& energy) const
02264     { 
02265         if ( globContext != NULL && globContext->pToneOp != NULL )
02266             globContext->pToneOp->ScaleRGB( energy ); 
02267     }
02273     float ScaleRGB(float energy) const;
02274 
02278     ShadeContext() {
02279         mode = SCMODE_NORMAL; nLights = 0; shadow = TRUE;  rayLevel = 0; 
02280         globContext = NULL; atmosSkipLight = NULL; 
02281     }
02282 };
02283 
02284             
02289 #define MTL_IN_SCENE             (1<<0) //!< The material is being used in the scene.
02290 #define MTL_BEING_EDITED      (1<<1)  //!< The material's parameters are being displayed in the Material Editor.
02291 #define MTL_SUB_BEING_EDITED  (1<<2)  //!< This material OR sub-material texmap is being displayed in the Material Editor. 
02292 #define MTL_TEX_DISPLAY_ENABLED (1<<3)  //!< Viewport display enabled for this material (see MTL_SUB_DISPLAY_ENABLED).
02293 #define MTL_MEDIT_BACKGROUND    (1<<8)  //!< Material has the background shown in Material Editor.
02294 #define MTL_MEDIT_BACKLIGHT      (1<<9)  //!< Material is backlight in the Material Editor.
02295 
02296 #define MTL_OBJTYPE_SHIFT     10 //!< 
02297 #define MTL_MEDIT_OBJTYPE     (1<<MTL_OBJTYPE_SHIFT) //!< Object type displayed in Material Editor
02298 #define MTL_MEDIT_OBJTYPE_MASK   ((1<<MTL_OBJTYPE_SHIFT)|(1<<(MTL_OBJTYPE_SHIFT+1))|(1<<(MTL_OBJTYPE_SHIFT+2)))
02299 
02300 #define MTL_TILING_SHIFT      13 //!< 
02301 #define MTL_MEDIT_TILING      (1<<MTL_TILING_SHIFT) // Object type displayed in Material Editor.
02302 #define MTL_MEDIT_TILING_MASK ((1<<MTL_TILING_SHIFT)|(1<<(MTL_TILING_SHIFT+1))|(1<<(MTL_TILING_SHIFT+2)))
02303 
02304 #ifndef NO_MTLEDITOR_VIDCOLORCHECK  // orb 01-08-2002
02305 #define MTL_MEDIT_VIDCHECK    (1<<16) //!< 
02306 #endif
02307 
02308 #define MTL_BROWSE_OPEN1      (1<<18) //!< For internal use.
02309 #define MTL_BROWSE_OPEN2      (1<<19) //!< For internal use.
02310 #define MTL_SUB_DISPLAY_ENABLED (1<<20)  //!< Indicates that texture display is enabled for map or material in this subtree
02311 
02312 #define MTL_CLONED            (1<<28)  //!< Indicates material or texture was created by being cloned from another material or texture. 
02313 #define MTL_HW_MAT_PRESENT    (1<<29)  //!< 
02314 #define MTL_HW_MAT_ENABLED    (1<<30)  //!< 
02315 
02316 #define MTL_WORK_FLAG         (1<<31)  //!< 
02317 
02318 #define MTL_DISPLAY_ENABLE_FLAGS (MTL_TEX_DISPLAY_ENABLED|MTL_SUB_DISPLAY_ENABLED)  //!<  Interactive texture display enabled for THIS mtl base
02319 
02320 #define MTL_HW_TEX_ENABLED    (1<<17)  //!<  Indicates that the texture should be part of the realtime shader
02321 
02322 
02326 #define MTLREQ_2SIDE          (1<<0)  //!< The material is 2-sided.
02327 #define MTLREQ_WIRE           (1<<1)  //!< The material is wire frame material.
02328 #define MTLREQ_WIRE_ABS       (1<<2)  //!< Wire frame material, absolute size
02329 #define MTLREQ_TRANSP         (1<<3)   //!< The material uses transparency.
02330 #define MTLREQ_UV          (1<<4)  //!< The material requires UVW coordinates.
02331 #define MTLREQ_FACEMAP        (1<<5)  //!< The material uses "face map" UV coordinates.
02332 #define MTLREQ_XYZ            (1<<6)  //!< The material requires object XYZ coordinates.
02333 #define MTLREQ_OXYZ        (1<<7)  //!< The material requires object ORIGINAL XYZ coordinates.
02334 #define MTLREQ_BUMPUV         (1<<8)  //!< The Material requires UV bump vectors.
02335 #define MTLREQ_BGCOL       (1<<9)  //!< The material requires background color (e.g. Matte mtl).
02336 #define MTLREQ_PHONG       (1<<10) //!< The material requires interpolated normal.
02337 #define MTLREQ_AUTOREFLECT       (1<<11) //!< The material needs to build auto-reflect map.
02338 #define MTLREQ_AUTOMIRROR     (1<<12) //!< The material needs to build auto-mirror map.
02339 
02342 #define MTLREQ_NOATMOS        (1<<13) //!< This suppresses the atmospheric shader. (used by Matte mtl)
02343 
02348 #define MTLREQ_ADDITIVE_TRANSP   (1<<14) //!< Specifies that transparent composites are done additively.
02349 #define MTLREQ_VIEW_DEP       (1<<15) //!< Maps or materials which depend on the view should set this bit in their Requirements() method. 
02350 #define MTLREQ_UV2            (1<<16)  //!< The material requires second uv channel values (vertex colors).
02351 #define MTLREQ_BUMPUV2        (1<<17)  //!< The material requires second uv channel bump vectors.
02352 #define MTLREQ_PREPRO         (1<<18)  //!< Pre-processing. MtlBase::BuildMaps is called on every frame.
02353 #define MTLREQ_DONTMERGE_FRAGMENTS  (1<<19) //!< No longer used.
02354 #define MTLREQ_DISPLACEMAP       (1<<20) //!< Material has a Displacement map channel
02355 
02358 #define MTLREQ_SUPERSAMPLE       (1<<21) //!< The material requires supersampling
02359 
02362 #define MTLREQ_WORLDCOORDS       (1<<22) //!< The material has world coordinates are used in material/map evaluation.
02363 
02364 #define MTLREQ_TRANSP_IN_VP   (1<<23) //!< The material is transparent in the viewport ( opacity < 100, or opacity map & ShowMapInVP set).
02365 #define MTLREQ_FACETED        (1<<24) //!< The material should be rendered faceted in the viewports.
02366 
02367 /* JH 5/21/03 Adjusting for R6
02368 #define MTLREQ_2SIDE_SHADOW   (1<<25) // USED IN RENDERER.
02369 #define MTLREQ_REND2          (1<<26) // USED IN RENDERER.
02370 #define MTLREQ_REND3          (1<<27) // USED IN RENDERER.
02371 #define MTLREQ_REND4          (1<<28) // USED IN RENDERER.
02372 #define MTLREQ_REND5          (1<<29) // USED IN RENDERER.
02373 #define MTLREQ_REND6          (1<<30) // USED IN RENDERER.
02374 #define MTLREQ_NOEXPOSURE     (1<<31) // don't do the tone-op (ie, for matte/shadow material, etc)
02375 */
02376 #define MTLREQ_NOEXPOSURE     (1<<25) //!< Do not do the tone-op (ie, for matte/shadow material, etc)
02377 #define MTLREQ_SS_GLOBAL      (1<<26) //!< Material requires supersampling but use global sampler
02378 
02379 #define MTLREQ_REND1          (1<<28) //!< USED IN RENDERER.
02380 #define MTLREQ_REND2          (1<<29) //!< USED IN RENDERER.
02381 #define MTLREQ_REND3          (1<<30) //!< USED IN RENDERER.
02382 #define MTLREQ_REND4          (1<<31) //!< USED IN RENDERER.
02383 
02384 
02388 #define MAPSLOT_TEXTURE      0   //!< A slot that holds a texture map.
02389 
02390 #define MAPSLOT_ENVIRON      1   //!< A slot which holds an environment map.
02391 #define MAPSLOT_DISPLACEMENT 2   //!< Displacement maps: a type of texture map.
02392 #define MAPSLOT_BACKGROUND   3   //!< Background maps: generate UVW on-the-fly using view vector, default to screen
02393 
02394 
02395 // Where to get texture vertices: returned by GetUVWSource();
02396 #define UVWSRC_EXPLICIT    0  // use explicit mesh texture vertices (whichever map channel)
02397 #define UVWSRC_OBJXYZ      1  // generate planar uvw mapping from object xyz on-the-fly
02398 #define UVWSRC_EXPLICIT2   2  // use explicit mesh map color vertices as a tex map
02399 #define UVWSRC_WORLDXYZ    3  // generate planar uvw mapping from world xyz on-the-fly
02400 #ifdef GEOREFSYS_UVW_MAPPING
02401 #define UVWSRC_GEOXYZ      4  // generate planar uvw mapping from geo referenced world xyz on-the-fly
02402 #endif
02403 #define UVWSRC_FACEMAP     5  // use face map
02404 #define UVWSRC_HWGEN    6  // use hardware generated texture coords
02405 
02416 class ISubMap : public MaxHeapOperators 
02417 {
02418 public:
02420     virtual ~ISubMap() {;}
02421     // Methods to access sub texture maps of material or texmap
02425     virtual int NumSubTexmaps() { return 0; }
02435     virtual Texmap* GetSubTexmap(int i) { return NULL; }
02451     virtual int MapSlotType(int i)=0;
02462     virtual void SetSubTexmap(int i, Texmap *m) { }
02463 
02464     // query ISubMap about the On/Off state of each sub map.
02473     virtual int SubTexmapOn(int i) { return 1; } 
02474 
02487     CoreExport virtual MSTR GetSubTexmapSlotName(int i);
02492     CoreExport MSTR GetSubTexmapTVName(int i);
02493 
02494     // called by the ParamMap2 AUTO_UI system if the material/map is letting
02495     // the system build an AutoMParamDlg for it.  SetDlgThing() is called on
02496     // a material/map coming into an existing set of ParamDlgs, once for each 
02497     // secondary ParamDlg and it should set the appropriate 'thing' into the
02498     // given dlg (for example, Texout* or UVGen*).  Return FALSE if dlg is unrecognized.
02499     // See Gradient::SetDlgThing() for an example.
02528     virtual BOOL SetDlgThing(ParamDlg* dlg) { return FALSE; }
02529 
02530     // use this for drag-and-drop of texmaps
02544     CoreExport void CopySubTexmap(HWND hwnd, int ifrom, int ito);
02545 
02549     virtual ReferenceTarget *GetRefTarget()=0;
02550 };
02551 
02552 // Base class from which materials and textures are subclassed.
02584 class MtlBase: public ReferenceTarget, public ISubMap {
02585      friend class Texmap;
02586      MSTR name;
02587      ULONG mtlFlags;
02588      int defaultSlotType;
02589      int activeCount;
02590      class MtlBaseImplData;
02591      const MaxSDK::Util::AutoPtr<MtlBaseImplData> mMtlBaseImplData;
02592     public:
02593             Quat meditRotate;
02594             ULONG gbufID;
02596             CoreExport MtlBase();
02597             CoreExport ~MtlBase();
02598             CoreExport Class_ID ClassID();
02601             MSTR& GetName() { return name; }
02604             CoreExport void SetName(MSTR s);
02612             CoreExport void SetMtlFlag(int mask, BOOL val=TRUE);
02617             CoreExport void ClearMtlFlag(int mask);
02622             CoreExport int TestMtlFlag(int mask); 
02623 
02624             // Used internally by materials editor.
02626             int GetMeditObjType() { return (mtlFlags&MTL_MEDIT_OBJTYPE_MASK)>>MTL_OBJTYPE_SHIFT; } 
02628             void SetMeditObjType(int t) { mtlFlags &= ~MTL_MEDIT_OBJTYPE_MASK; mtlFlags |= t<<MTL_OBJTYPE_SHIFT; }
02629 
02630 
02631 #ifndef NO_MTLEDITOR_SAMPLEUVTILING // orb 01-08-2002
02632 
02633             int GetMeditTiling() { return (mtlFlags&MTL_MEDIT_TILING_MASK)>>MTL_TILING_SHIFT; } 
02635             void SetMeditTiling(int t) { mtlFlags &= ~MTL_MEDIT_TILING_MASK; mtlFlags |= t<<MTL_TILING_SHIFT; }
02636 #endif // NO_MTLEDITOR_SAMPLEUVTILING 
02637 
02638             // recursively determine if there are any multi-materials or texmaps 
02639             // in tree
02645             CoreExport BOOL AnyMulti();
02646 
02649             BOOL TextureDisplayEnabled() { return TestMtlFlag(MTL_TEX_DISPLAY_ENABLED); }
02650 
02651             // Return the "className(instance Name)". 
02652             // The default implementation should be used in most cases.
02657              CoreExport virtual MSTR GetFullName();
02658 
02659             // Mtls and Texmaps must use this to copy the common portion of 
02660             // themselves when cloning
02664             CoreExport MtlBase& operator=(const MtlBase& m);
02665 
02676             virtual int BuildMaps(TimeValue t, RenderMapsContext &rmc) { return 1; }
02677 
02678             // This gives the cumulative requirements of the mtl and its
02679             // tree. The default just OR's together the local requirements
02680             // of the Mtl with the requirements of all its children.
02681             // For most mtls, all they need to implement is LocalRequirements,
02682             // if any.
02700             CoreExport virtual ULONG Requirements(int subMtlNum); 
02701 
02702             // Specifies various requirements for the material: Should NOT
02703             // include requirements of its sub-mtls and sub-maps.
02711             virtual ULONG LocalRequirements(int subMtlNum) { return 0; } 
02712 
02713             // This gives the UVW channel requirements of the mtl and its
02714             // tree. The default implementation just OR's together the local mapping requirements
02715             // of the Mtl with the requirements of all its children.
02716             // For most mtls, all they need to implement is LocalMappingsRequired, if any.
02717             // mapreq and bumpreq will be initialized to empty sets with MAX_MESHMAPS elements
02718             // set 1's in mapreq for uvw channels required
02719             // set 1's in bumpreq for bump mapping channels required
02732             CoreExport virtual void MappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq);
02733 
02734             // Specifies UVW channel requirements for the material: Should NOT
02735             // include UVW channel requirements of its sub-mtls and sub-maps.
02765             virtual void LocalMappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq) {  }
02766 
02767             // This returns true for materials or texmaps that select sub-
02768             // materials based on mesh faceMtlIndex. Used in 
02769             // interactive render.
02780             virtual  BOOL IsMultiMtl() { return FALSE; }
02781 
02782             // Methods to access sub texture maps of material or texmap
02783             virtual int MapSlotType(int i) { return defaultSlotType; }
02784 
02785             // This must be called on a sub-Mtl or sub-Map when it is removed,
02786             // in case it or any of its submaps are active in the viewport.
02790             CoreExport void DeactivateMapsInTree();
02791 
02792             // To make texture & material evaluation more efficient, this function is
02793             // called whenever time has changed.  It will be called at the
02794             // beginning of every frame during rendering.
02810             virtual  void Update(TimeValue t, Interval& valid)=0;
02811 
02828             virtual void Reset()=0;
02829 
02830             // call this to determine the validity interval of the mtl or texture
02835             virtual Interval Validity(TimeValue t)=0;
02836             
02837             // this gets called when the mtl or texture is to be displayed in the
02838             // mtl editor params area.
02901             virtual ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp)=0;
02902             
02903             // save the common mtlbase stuff.
02904             // these must be called in a chunk at the beginning of every mtl and
02905             // texmap.
02933             CoreExport IOResult Save(ISave *isave);
02963             CoreExport IOResult Load(ILoad *iload);
02964             
02965 #ifndef NO_MTLEDITOR_EFFECTSCHANNELS // orb 01-08-2002
02966             // GBuffer functions
02969             ULONG GetGBufID() { return gbufID; }
02972             void SetGBufID(ULONG id) { gbufID = id; }
02973 #endif // NO_MTLEDITOR_EFFECTSCHANNELS
02974             
02975             // Default File enumerator.
02979             CoreExport void EnumAuxFiles(AssetEnumCallback& nameEnum, DWORD flags);
02980 
02981             // Postage Stamp
02988             CoreExport virtual PStamp* GetPStamp(int sz); // sz = 0: small(32x32), 1: large(88x88), 2: tiny(24x24)      
03022             CoreExport virtual PStamp* CreatePStamp(int sz, BOOL Render = FALSE);         
03029             CoreExport virtual void DiscardPStamp(int sz);        
03030 
03031             // Schematic View Animatable Overrides...
03032             CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
03033             CoreExport bool SvHandleDoubleClick(IGraphObjectManager *gom, IGraphNode *gNode);
03034             CoreExport MSTR SvGetName(IGraphObjectManager *gom, IGraphNode *gNode, bool isBeingEdited);
03035             CoreExport bool SvCanSetName(IGraphObjectManager *gom, IGraphNode *gNode);
03036             CoreExport bool SvSetName(IGraphObjectManager *gom, IGraphNode *gNode, MSTR &name);
03037             CoreExport COLORREF SvHighlightColor(IGraphObjectManager *gom, IGraphNode *gNode);
03038             CoreExport bool SvIsSelected(IGraphObjectManager *gom, IGraphNode *gNode);
03039             CoreExport MultiSelectCallback* SvGetMultiSelectCallback(IGraphObjectManager *gom, IGraphNode *gNode);
03040             CoreExport bool SvCanSelect(IGraphObjectManager *gom, IGraphNode *gNode);
03041 
03042             // Methods for doing interactive texture display
03049             virtual BOOL SupportTexDisplay() { return FALSE; }   // supports map display in viewport
03058             virtual DWORD_PTR GetActiveTexHandle(TimeValue t, TexHandleMaker& thmaker) {return 0;}
03060             CoreExport void IncrActive();
03062             CoreExport void DecrActive(); 
03064             int Active() { return activeCount; }
03075             virtual void ActivateTexDisplay(BOOL onoff) {}
03076 
03078 
03082             CoreExport MtlBase* GetActiveMB();
03084 
03085             CoreExport void SetActiveMB(MtlBase* activeMB);
03086 
03087             // Multiple textures in viewports:
03092             virtual BOOL SupportsMultiMapsInViewport() { return FALSE; }
03122             virtual void SetupGfxMultiMaps(TimeValue t, Material *mtl, MtlMakerCallback &cb) {}
03123             virtual void* GetInterface(ULONG id){ if(id==I_SUBMAP) return (ISubMap*)this; else return ReferenceTarget::GetInterface(id); }
03124             virtual BaseInterface *GetInterface(Interface_ID id) { return ReferenceTarget::GetInterface(id); }
03125             virtual ReferenceTarget *GetRefTarget(){return this;}
03126 
03127             // Animatable Properties
03128             CoreExport virtual int SetProperty(ULONG id, void *data);
03129             CoreExport virtual void *GetProperty(ULONG id);
03130             CoreExport virtual void BaseClone(ReferenceTarget *from, ReferenceTarget *to, RemapDir &remap);
03131 
03139             virtual BOOL GetTransparencyHint(TimeValue t, Interval& valid) { return TRUE; }
03140      };
03141 
03142 
03143 // Every MtlBase sub-class defines a ParamDlg to manage its part of
03144 // the material editor.
03150 class ParamDlg : public InterfaceServer {
03151      public:
03154             virtual Class_ID ClassID()=0;
03160             virtual void SetThing(ReferenceTarget *m)=0;
03162             virtual ReferenceTarget* GetThing()=0;
03169             virtual void SetTime(TimeValue t)=0;
03174             virtual  void ReloadDialog()=0;
03180             virtual void DeleteThis()=0;
03203             virtual void ActivateDlg(BOOL onOff)=0;
03204             // These need to be implemented if using a TexDADMgr or a MtlDADMgr
03227             virtual int FindSubTexFromHWND(HWND hwnd){ return -1;} 
03237             virtual int FindSubMtlFromHWND(HWND hwnd){ return -1;} 
03238             // Generic expansion function
03239             virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
03240 
03241      };
03242 
03243 // Pre-defined categories of texture maps
03244 CoreExport MCHAR TEXMAP_CAT_2D[];  // 2D maps
03245 CoreExport MCHAR TEXMAP_CAT_3D[];  // 3D maps
03246 CoreExport MCHAR TEXMAP_CAT_COMP[]; // Composite
03247 CoreExport MCHAR TEXMAP_CAT_COLMOD[]; // Color modifier
03248 CoreExport MCHAR TEXMAP_CAT_ENV[];  // Environment
03249 
03254 class NameAccum: public MaxHeapOperators {
03255      public:
03257             virtual ~NameAccum() {;}
03263             virtual  void AddMapName(MCHAR *name)=0;
03264      };
03265 
03266 // this interface is a dummy interface returned by texmap::getinterface
03267 // if the map is a ray tracing type map.
03268 #define IID_RAYTRACE_MAP   0xff8d87a5
03269 
03270 class IRayTexmap : public InterfaceServer {
03271 public:
03272      bool isRayTraceMap() { return true; }
03273 };
03274 
03275 // virtual texture map interface
03298 class Texmap: public MtlBase {
03299      public:
03300             int cacheID;    // used by renderer for caching returned values
03301                         
03304             CoreExport Texmap();
03305 
03306             SClass_ID SuperClassID() { return TEXMAP_CLASS_ID; }
03307             virtual void GetClassName(MSTR& s) { s= MSTR(_M("Texture")); }  
03308 
03309             // Evaluate the color of map for the context.
03320             virtual  AColor EvalColor(ShadeContext& sc)=0;
03321      
03322             // Evaluate the map for a "mono" channel.
03323             // this just permits a bit of optimization 
03333             virtual  float  EvalMono(ShadeContext& sc) {
03334                  return Intens(EvalColor(sc));
03335                  }
03336             
03337             // For Bump mapping, need a perturbation to apply to a normal.
03338             // Leave it up to the Texmap to determine how to do this.
03345             virtual  Point3 EvalNormalPerturb(ShadeContext& sc)=0;
03346 
03347             // This query is made of maps plugged into the Reflection or 
03348             // Refraction slots:  Normally the view vector is replaced with
03349             // a reflected or refracted one before calling the map: if the 
03350             // plugged in map doesn't need this , it should return TRUE.
03357             virtual BOOL HandleOwnViewPerturb() { return FALSE; }
03358 
03359 
03360             // This gets the viewport display bitmap in DIB format, useful when combining several maps
03361             // for hardware-supported multiple texture display.  // DS 4/17/00
03362             // IF mono=TRUE, the map should do a mono evaluation and place the result in RGB.
03363             // forceW and forceH, if non-zero, override dimensions specified by thmaker.
03384             CoreExport virtual BITMAPINFO* GetVPDisplayDIB(TimeValue t, TexHandleMaker& thmaker, Interval &valid, BOOL mono=FALSE, int forceW=0, int forceH=0);  
03385 
03395             virtual  void GetUVTransform(Matrix3 &uvtrans) { uvtrans.IdentityMatrix(); }
03404             virtual int GetTextureTiling() { return  U_WRAP|V_WRAP; }
03415             virtual void InitSlotType(int sType) { defaultSlotType = sType; }          
03416             virtual int MapSlotType(int i) { return defaultSlotType; }
03440             virtual int GetUVWSource() { return UVWSRC_EXPLICIT; }
03446             virtual int GetMapChannel () { return 1; }   // only relevant if above returns UVWSRC_EXPLICIT
03447 
03452             virtual UVGen *GetTheUVGen() { return NULL; }  // maps with a UVGen should implement this
03457             virtual XYZGen *GetTheXYZGen() { return NULL; } // maps with a XYZGen should implement this
03458 
03459             // System function to set slot type for all subtexmaps in a tree.
03463             CoreExport void RecursInitSlotType(int sType);           
03474             virtual void SetOutputLevel(TimeValue t, float v) {}
03475 
03476             // called prior to render: missing map names should be added to NameAccum.
03477             // return 1: success,   0:failure. 
03557             virtual int LoadMapFiles(TimeValue t) { return 1; } 
03558 
03559             // render a 2-d bitmap version of map.
03588             CoreExport virtual void RenderBitmap(TimeValue t, Bitmap *bm, float scale3D=1.0f, BOOL filter = FALSE);
03589 
03590             CoreExport void RefAdded(RefMakerHandle rm);
03591 
03592             // Schematic View Animatable Overrides...
03593             CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
03594 
03595             // --- Texmap evaluation ---
03596 
03597             // Returns true only if all submaps and itself have a meaningful output.
03598             // Returns false if at least one sutexmap or itself does not have a 
03599             // meaningful output,
03613             CoreExport virtual bool IsOutputMeaningful( ShadeContext& sc );
03614 
03615             // The default implementation returns false
03624             virtual bool IsLocalOutputMeaningful( ShadeContext& sc ) { return false; }
03625 
03626             // Is the texture High Dynamic Range?
03631             virtual int IsHighDynamicRange( ) const { return false; }
03632      };
03633 
03634 
03646 class TexmapContainer: public ReferenceTarget {
03647      SClass_ID SuperClassID() { return TEXMAP_CONTAINER_CLASS_ID; }
03648      CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
03649      };
03650 
03651 // ID's for different DynamicProperties: passed into
03652 // GetDynamicProperty()
03653 
03654 #define DYN_BOUNCE 1
03655 #define DYN_STATIC_FRICTION 2
03656 #define DYN_SLIDING_FRICTION 3
03657 
03659 #define GNORMAL_CLASS_ID    Class_ID(0x243e22c6, 0x63f6a014)
03660 #define VDM_CLASS_ID        Class_ID(0x152c55c7, 0x26160e93)
03661 
03664 //-- UI and Param Block
03665 enum Normal_Block_IDs
03666 {
03667     gnormal_params
03668 };
03669 enum Normal_Param_IDs
03670 { 
03671     gn_mult_spin,
03672     gn_bmult_spin,
03673     gn_map_normal,
03674     gn_map_bump,
03675     gn_map1on,
03676     gn_map2on,
03677     gn_method,
03678     gn_flip_red,
03679     gn_flip_green,
03680     gn_swap_rg
03681 };
03682 
03683 enum VDM_Block_IDs
03684 {
03685     vdm_params
03686 };
03687 
03688 enum VDM_Param_IDs
03689 {
03690     vdm_mult_spin,              // Scaling value (float)
03691     vdm_map_vector_enabled,     // Whether the map is enabled or not (bool)
03692     vdm_map_vector,             // A sub-map defining the actual vector data as a Texmap 
03693     vdm_is_hdr,                 // Whether the sub-map is high-dynamic range and doesn't need re-scaling (i.e. value = pixel * 2.0 - 1.0). (bool)
03694     vdm_method                  // Space the vector map is defined in [0==World, 1==Object, 2==Tangent] (int)
03695 };
03696 
03697 
03698 // virtual material interface
03713 class Mtl: public MtlBase {
03714      RenderData *renderData;
03715      public:
03716 
03718             CoreExport Mtl();
03719             SClass_ID SuperClassID() { return MATERIAL_CLASS_ID; }
03720             virtual void GetClassName(MSTR& s) { s= MSTR(_M("Mtl")); }  
03721 
03725             CoreExport MtlBase* GetActiveTexmap();
03731             CoreExport void SetActiveTexmap(MtlBase *txm);
03732 
03733             CoreExport void RefDeleted();
03734             CoreExport void RefAdded(RefMakerHandle rm);  
03735 
03736             // Must call Update(t) before calling these functions!
03737             // Their purpose is for setting up the material for the
03738             // GraphicsWindow renderer.
03744             virtual Color GetAmbient(int mtlNum=0, BOOL backFace=FALSE)=0;
03750             virtual Color GetDiffuse(int mtlNum=0, BOOL backFace=FALSE)=0;     
03756             virtual Color GetSpecular(int mtlNum=0, BOOL backFace=FALSE)=0;
03762             virtual float GetShininess(int mtlNum=0, BOOL backFace=FALSE)=0;
03768             virtual  float GetShinStr(int mtlNum=0, BOOL backFace=FALSE)=0;      
03774             virtual float GetXParency(int mtlNum=0, BOOL backFace=FALSE)=0;
03775 
03776             // >>>>> Self-Illum
03784             virtual BOOL GetSelfIllumColorOn(int mtlNum=0, BOOL backFace=FALSE) { return TRUE; }
03792             virtual float GetSelfIllum(int mtlNum=0, BOOL backFace=FALSE) { return 0.0f; }
03800             virtual Color GetSelfIllumColor(int mtlNum=0, BOOL backFace=FALSE){ Color c( .0f,.0f,.0f); return c; }
03801 
03802             // sampler
03809             virtual Sampler * GetPixelSampler(int mtlNum=0, BOOL backFace=FALSE){ return NULL; }
03810 
03811             // used by the scanline renderer
03818             virtual float WireSize(int mtlNum=0, BOOL backFace=FALSE) { return 1.0f; }
03819 
03820             // why incomplete sets?? 
03821             // used onlt for default material creation....add no more
03825             virtual void SetAmbient(Color c, TimeValue t)=0;      
03829             virtual void SetDiffuse(Color c, TimeValue t)=0;      
03833             virtual void SetSpecular(Color c, TimeValue t)=0;
03837             virtual void SetShininess(float v, TimeValue t)=0;    
03842             virtual BOOL SupportsShaders() { return FALSE; } // moved from class StdMat
03843 
03844             // if supporting render elements
03845             virtual BOOL SupportsRenderElements() { return FALSE; } 
03846 
03847 /*************
03848 // begin - ke/mjm - 03.16.00 - merge reshading code
03849             // if supporting shaders, plug-in mtl should inherit from StdMat2
03850             enum ReshadeRequirements{ RR_None = 0, RR_NeedPreshade, RR_NeedReshade }; // mjm - 06.02.00
03851 
03852             virtual BOOL SupportsReShading(ShadeContext& sc) { return FALSE; }
03853             // GetReshadeValidity is called by the interactive reshader after being notified that the material has changed.
03854             // the return value indicates if the material is still valid, or needs to be preshaded or reshaded. the value
03855             // should pertain only to the latest change to the material
03856             // if a material doesn't support reshading, it doesn't need to override this function -- any change will cause
03857             // the nodes to which it's attached to be rerendered.
03858             virtual ReshadeRequirements GetReshadeRequirements() { return RR_NeedPreshade; } // mjm - 06.02.00
03859             virtual void PreShade(ShadeContext& sc, IReshadeFragment* pFrag ) { }
03860             virtual void PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex) { }
03861 // end - ke/mjm - 03.16.00 - merge reshading code
03862 ***********/
03863 
03864             // The main method: called by the renderer to compute color and transparency
03865             // output returned in sc.out
03870             virtual void Shade(ShadeContext& sc)=0;
03871 
03872             // Methods to access sub-materials of meta-materials 
03876             virtual int NumSubMtls() { return 0; }
03881             virtual Mtl* GetSubMtl(int i) { return NULL; }
03887             virtual void SetSubMtl(int i, Mtl *m) { }
03899             virtual int VPDisplaySubMtl() { return -1; }  // which sub-mtl to display in the viewport: -1 indicates not implemented.
03909             CoreExport virtual MSTR GetSubMtlSlotName(int i);
03913             CoreExport MSTR GetSubMtlTVName(int i);                 
03914             CoreExport void CopySubMtl(HWND hwnd, int ifrom, int ito);
03915 
03916             // Dynamics properties
03932             CoreExport virtual float GetDynamicsProperty(TimeValue t, int mtlNum, int propID);
03949             CoreExport virtual void SetDynamicsProperty(TimeValue t, int mtlNum, int propID, float value);
03950             
03951             // Displacement mapping
03957             virtual float EvalDisplacement(ShadeContext& sc) { return 0.0f; }
03963             virtual Interval DisplacementValidity(TimeValue t) { return FOREVER; }
03964 
03965             // Schematic View Animatable Overrides...
03966             CoreExport bool SvCanInitiateLink(IGraphObjectManager *gom, IGraphNode *gNode);
03967 
03968             // allows plugins to control the display of the Discard/Keep Old Material dialog when being
03969             // created in a MtlEditor slot.  Added by JBW for scripted material plugins.
03970             // return TRUE to prevent the Keep Old Material dialog from pooping.
03978             virtual BOOL DontKeepOldMtl() { return FALSE; }
03979 
03980             // allow renderer to attach auxiliary data to each material.
03986             virtual void SetRenderData( RenderData *rdata) { renderData = rdata; }
03991             virtual RenderData *GetRenderData() { return renderData; }
03992 
03993             // --- Material evaluation ---
03994 
03995             // Returns true if the evaluated color\value (output) is constant 
03996             // over all possible inputs. 
04005             virtual bool IsOutputConst( ShadeContext& sc, int stdID ) { return false; }
04006 
04007             // Evaluate the material on a single standard texmap channel (ID_AM, etc) 
04008             // at a UVW coordinated and over an area described in the ShadingContext
04028             virtual bool EvalColorStdChannel( ShadeContext& sc, int stdID, Color& outClr) { return false; }
04029             CoreExport virtual bool EvalMonoStdChannel( ShadeContext& sc, int stdID, float& outVal) ;
04030      };
04031 
04032 //  A texture map implements this class and passes it into  EvalUVMap,
04033 //  EvalUVMapMono, and EvalDeriv to evaluate itself with tiling & mirroring
04041 class MapSampler: public MaxHeapOperators {
04042      public:
04044             virtual ~MapSampler() {;}
04045             // required:
04060             virtual  AColor Sample(ShadeContext& sc, float u,float v)=0;
04080             virtual  AColor SampleFilter(ShadeContext& sc, float u,float v, float du, float dv)=0;
04081             // optional:
04082             virtual void SetTileNumbers(int iu, int iv) {} // called before SampleFunctions to tell what tile your in
04099             virtual  float SampleMono(ShadeContext& sc, float u,float v) { return Intens(Sample(sc,u,v)); }
04123             virtual  float SampleMonoFilter(ShadeContext& sc, float u,float v, float du, float dv){
04124                  return Intens(SampleFilter(sc,u,v,du,dv)); 
04125                  }
04126      };
04127 
04128 
04129 // This class generates UV coordinates based on the results of a UV 
04130 // Source and user specified transformation.
04131 // A reference to one of these is referenced by all 2D texture maps.
04143 class UVGen: public MtlBase {
04144      public:
04145             // Get texture coords and derivatives for antialiasing
04159             virtual void GetUV( ShadeContext& sc, Point2& UV, Point2& dUV)=0;
04160             
04161             // This is how a Texmap evaluates itself
04176             virtual AColor EvalUVMap(ShadeContext &sc, MapSampler* samp,  BOOL filter=TRUE)=0;
04220             virtual float EvalUVMapMono(ShadeContext &sc, MapSampler* samp, BOOL filter=TRUE)=0;
04235             virtual  Point2 EvalDeriv( ShadeContext& sc, MapSampler* samp, BOOL filter=TRUE)=0;
04236 
04237             // Get dPdu and dPdv for bump mapping
04254             virtual  void GetBumpDP( ShadeContext& sc, Point3& dPdu, Point3& dPdv)=0;
04255 
04258             virtual void GetUVTransform(Matrix3 &uvtrans)=0;
04259 
04262             virtual int GetTextureTiling()=0;
04263             virtual void SetTextureTiling(int t)=0;
04264 
04274             virtual int GetUVWSource()=0;
04275             virtual int GetMapChannel () { return 1; }   // only relevant if above returns UVWSRC_EXPLICIT
04291             virtual void SetUVWSource(int s)=0;
04298             virtual void SetMapChannel (int s) { }
04299 
04301             virtual int SymFlags()=0;
04303             virtual void SetSymFlags(int f)=0;
04304 
04305             virtual int GetSlotType()=0; 
04321             virtual void InitSlotType(int sType)=0; 
04322 
04328             virtual int GetAxis()=0;  // returns AXIS_UV, AXIS_VW, AXIS_WU
04336             virtual void SetAxis(int ax)=0;  //  AXIS_UV, AXIS_VW, AXIS_WU
04337 
04338             // The clip flag controls whether the U,V values passed to MapSampler by 
04339             //  EvalUVMap and EvalUVMapMono are clipped to the [0..1] interval or not. 
04340             // It defaults to ON (i.e., clipped).
04358             virtual void SetClipFlag(BOOL b)=0; 
04364             virtual BOOL GetClipFlag()=0;
04370             virtual BOOL IsStdUVGen() { return FALSE; } // class StdUVGen implements this to return TRUE
04371 
04372             SClass_ID SuperClassID() { return UVGEN_CLASS_ID; }
04373 
04378             virtual void SetRollupOpen(BOOL open)=0;
04381             virtual BOOL GetRollupOpen()=0;
04382             CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
04383             CoreExport MSTR SvGetName(IGraphObjectManager *gom, IGraphNode *gNode, bool isBeingEdited)
04384                  {
04385                  return Animatable::SvGetName(gom, gNode, isBeingEdited);
04386                  }
04387      };
04388 
04389 // This class generates Point3 coordinates based on the ShadeContext.
04390 // A reference to one of these is referenced by all 3D texture maps.
04399 class XYZGen: public MtlBase {
04400      public:
04401             // Get texture coords and derivatives for antialiasing
04421             virtual void GetXYZ( ShadeContext& sc, Point3& p, Point3& dp)=0;
04422             SClass_ID SuperClassID() { return XYZGEN_CLASS_ID; }
04427             virtual void SetRollupOpen(BOOL open)=0;
04430             virtual BOOL GetRollupOpen()=0;
04431             virtual BOOL IsStdXYZGen() { return FALSE; } // class StdXYZGen implements this to return TRUE
04468             virtual  void GetBumpDP( ShadeContext& sc, Point3* dP) {}; // returns 3 unit vectors for computing differentials
04469             CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
04470             CoreExport MSTR SvGetName(IGraphObjectManager *gom, IGraphNode *gNode, bool isBeingEdited)
04471         {
04472              return Animatable::SvGetName(gom, gNode, isBeingEdited);
04473           }
04474      };
04475 
04476 // This class is used by texture maps to put up the output filter 
04477 // rollup, and perform the output filtering.
04498 class TextureOutput: public MtlBase {
04499      public:
04505             virtual AColor Filter(AColor c) = 0;
04511             virtual float Filter(float f) = 0;
04517             virtual Point3 Filter(Point3 p) = 0;
04522             virtual float GetOutputLevel(TimeValue t) = 0;
04529             virtual void SetOutputLevel(TimeValue t, float v) = 0;
04534             virtual void SetInvert(BOOL onoff)=0;
04538             virtual BOOL GetInvert()=0;
04543             virtual void SetRollupOpen(BOOL open)=0;
04546             virtual BOOL GetRollupOpen()=0;
04547             SClass_ID SuperClassID() { return TEXOUTPUT_CLASS_ID; }
04548             CoreExport SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags);
04549             CoreExport MSTR SvGetName(IGraphObjectManager *gom, IGraphNode *gNode, bool isBeingEdited)
04550             {
04551                 return Animatable::SvGetName(gom, gNode, isBeingEdited);
04552             }
04553      };
04554 
04556 //
04557 // post mapping params for shaders & render elements
04558 class Shader;
04559 
04560 #ifndef USE_LIMITED_STDMTL
04561 #define STD2_NMAX_TEXMAPS  24
04562 #else
04563 #define STD2_NMAX_TEXMAPS  12
04564 #endif
04565 
04659 class IllumParams : public BaseInterfaceServer {
04660 public:
04661      // these are the inputs to the shader, mostly textured channels
04662 // ULONG mtlFlags;
04663      Shader* pShader;  // for render elements to call the shader & mtl again, may be null
04664      Mtl* pMtl;        // max mtl being shaded, null if bgnd
04665 // Point3 N, V;
04666      Color channels[ STD2_NMAX_TEXMAPS ];   //inputs, to be textured
04667 
04668      float finalOpac;     // textured opacity w/ stdfalloff (reg opac in channels)
04669      float reflectAmt;          // combined reflection.a * reflectAmt 
04670      float refractAmt;          // combined reflection.a * amt 
04671      ULONG hasComponents; // bits for active components(e.g.currently has active refl map)
04672      ULONG stdParams;
04673      int*  stdIDToChannel;   // combined shader & mtl. Note: may be NULL (for example, matte/shadow)
04674 
04675      // these are the component-wise outputs from the shading process
04676      Color ambIllumOut, diffIllumOut, transIllumOut, selfIllumOut; // the diffuse clrs
04677      Color specIllumOut, reflIllumOut;   // the specular colors
04678 
04679      // User Illumination outputs for render elements, name matched
04680      int   nUserIllumOut;    // one set of names for all illum params instances
04681      MCHAR** userIllumNames;  // we just keep ptr to shared name array, not destroyed
04682      Color* userIllumOut; // the user illum color array, new'd & deleted w/ the class
04683 
04684      float diffIllumIntens; // used only by reflection dimming, intensity of diffIllum prior to color multiply
04685      float finalAttenuation; // for combining components
04686 
04687      // these are the outputs of the combiner
04688      Color finalC;  // final clr: combiner composites into this value.
04689      Color finalT;  // shader transp clr out
04690 
04691 public:
04692      // Illum params are allocated by materials during shading process to
04693      // communicate with shaders & render elements
04694      // So materials need to know how many userIllum slots they will use
04695      // most materials know this, but std2 will have to get it from the shader
04696      CoreExport IllumParams( int nUserOut = 0, MCHAR** pUserNames = NULL );        
04697 
04698 // IllumParams(){ 
04699 //    nUserIllumOut = 0;
04700 //    userIllumOut = NULL;
04701 //    userIllumNames = NULL;
04702 // }
04703 
04704 
04705      CoreExport ~IllumParams();
04706 
04707      // returns number of user illum channels for this material
04708      int nUserIllumChannels(){ return nUserIllumOut; }
04709 
04710      // returns null if no name array specified
04711      MCHAR* GetUserIllumName( int n ) { 
04712             DbgAssert( n < nUserIllumOut );
04713             if( userIllumNames )
04714                  return userIllumNames[n];
04715             return NULL;
04716      }
04717 
04718      // render elements, mtls & shaders can use this to find the index associated with a name
04719      // returns -1 if it can't find the name
04720      CoreExport int FindUserIllumName( MCHAR* name );
04721 
04722      // knowing the index, these set/get the user illum output color
04723      void SetUserIllumOutput( int n, Color& out ){
04724             DbgAssert( n < nUserIllumOut );
04725             userIllumOut[n] = out;
04726      }
04727 
04728      CoreExport void SetUserIllumOutput( MCHAR* name, Color& out );
04729 
04730      Color GetUserIllumOutput( int n ){
04731             DbgAssert( n < nUserIllumOut );
04732             return userIllumOut[n];
04733      }
04734 
04735      CoreExport Color GetUserIllumOutput( MCHAR* name, int n );
04736 
04742      void ClearOutputs() { 
04743             finalC = finalT = ambIllumOut=diffIllumOut=transIllumOut=selfIllumOut=
04744             specIllumOut=reflIllumOut= Color( 0.0f, 0.0f, 0.0f ); 
04745             finalAttenuation = diffIllumIntens = 0.0f;
04746             for( int i=0; i < nUserIllumOut; ++i )
04747                  userIllumOut[i] = finalC;
04748      }
04749 
04750      void ClearInputs() { 
04751             /*mtlFlags = */ stdParams = hasComponents = 0;
04752             pShader = NULL; pMtl = NULL;
04753             stdIDToChannel = NULL;
04754             refractAmt = reflectAmt = 0.0f; 
04755             for( int i=0; i < STD2_NMAX_TEXMAPS; ++i )
04756                  channels[ i ] = Color( 0, 0, 0 );
04757      }
04758 };
04759 
04761 //
04762 // Reshading interfaces
04763 //
04764 class Color32;
04765 
04786 class IReshadeFragment : public InterfaceServer 
04787 {
04788 public:
04791      virtual int NChannels()=0;
04793      virtual int NFirstChannel()=0; 
04795      virtual int NTextures()=0;
04796 
04801      virtual Color32   Channel( int nChan )=0;
04809      virtual void SetChannel( int nChan, Color32 c )=0;
04815      virtual void AddChannel( Color32 c )=0;
04816 
04823      virtual void AddColorChannel( RGBA tex )=0;
04829      virtual void AddFloatChannel( float f )=0;
04835      virtual void AddIntChannel( int i )=0;
04841      virtual void AddUnitVecChannel( Point3 v )=0;
04847      virtual void AddPoint2Channel( Point2 p )=0;
04853      virtual void AddPoint3Channel( Point3 p )=0;
04854 
04862      virtual void SetColorChannel( int nChan, RGBA tex )=0;
04870      virtual void SetFloatChannel( int nChan, float f )=0;
04878      virtual void SetIntChannel( int nChan, int i )=0;
04886      virtual void SetUnitVecChannel( int nChan, Point3 v )=0;
04894      virtual void SetPoint2Channel( int nChan, Point2 p )=0;
04902      virtual void SetPoint3Channel( int nChan, Point3 p )=0;
04903 
04909      virtual RGBA GetColorChannel( int nChan )=0;
04914      virtual float GetFloatChannel( int nChan )=0;
04919      virtual int GetIntChannel( int nChan )=0;
04924      virtual Point3 GetUnitVecChannel( int nChan )=0;
04929      virtual Point2 GetPoint2Channel( int nChan )=0;
04934      virtual Point3 GetPoint3Channel( int nChan )=0;
04935 };
04936 
04937 // must be greater than I_USERINTERFACE in AnimatableInterfaceIDs.h
04938 #define IID_IReshading  0xabe00001
04939 
04940 // Materials support this interface to support preshading/reshading
04968 class IReshading: public MaxHeapOperators
04969 {
04970 public:
04971             // if supporting shaders, plug-in mtl should inherit from StdMat2
04972             enum ReshadeRequirements{ RR_None = 0, RR_NeedPreshade, RR_NeedReshade }; // mjm - 06.02.00
04974             virtual ~IReshading() {;}
04975             // this is implied by the GetInterface( IID_IReshading ) call on the mtl
04976 //    virtual BOOL SupportsReShading(ShadeContext& sc) { return FALSE; }
04977 
04978             // GetReshadeRequirements is called by the interactive reshader after being notified that the material has changed.
04979             // the return value indicates if the material is still valid, or needs to be preshaded or reshaded. the value
04980             // should pertain only to the latest change to the material
04981             // if a material doesn't support reshading, it doesn't need to override this function -- any change will cause
04982             // the nodes to which it's attached to be rerendered.
04999             virtual ReshadeRequirements GetReshadeRequirements() { return RR_NeedPreshade; } // mjm - 06.02.00
05015             virtual void PreShade(ShadeContext& sc, IReshadeFragment* pFrag ) { }
05037             virtual void PostShade(ShadeContext& sc, IReshadeFragment* pFrag, 
05038                                     int& nextTexIndex, IllumParams* ip = NULL ) { }
05039 
05040 };
05041 
05042 // must be greater than I_USERINTERFACE in AnimatableInterfaceIDs.h
05043 #define IID_IValidityToken 0xabe00002
05044 
05045 class IValidityToken: public MaxHeapOperators
05046 {
05047 public:
05048      virtual ~IValidityToken() {;}
05049      virtual BOOL NeedsUpdate( ULONG currentToken )= 0;
05050      virtual void SetToken( ULONG token )= 0;
05051      virtual ULONG GetToken() = 0;
05052      virtual void SetMessage( ULONG message )= 0;
05053      virtual ULONG GetMessage() = 0;
05054 };
05055 
05056 
05057 class IValidityTokenImp : public IValidityToken
05058 {
05059 protected:
05060      ULONG mLocalToken;
05061      ULONG mMessage;
05062 
05063 public:
05064      // if the object has been changed the local token will equal the
05065      // current token
05066      BOOL NeedsUpdate( ULONG currentToken ){
05067             return mLocalToken >= currentToken;
05068      }
05069      // mtls/maps set the token to next frame when changed
05070      // from core interface GetNextValidityToken()
05071      void SetToken( ULONG token ) {
05072             mLocalToken = token;
05073      }
05074      // not used, but here for debug & future use
05075      ULONG GetToken() {
05076             return mLocalToken;
05077      }
05078 
05079      // once the render know which mtls maps were changed, this can be used to 
05080      // send a secondary message e.g. map/colorVal or map/uv, etc.
05081      void SetMessage( ULONG message ) {
05082             mMessage = message;
05083      }
05084      ULONG GetMessage() {
05085             return mMessage;
05086      }
05087 };
05088 
05089 //------------------------------------
05090 
05091 typedef Mtl* MtlHandle;
05092 typedef Texmap* TexmapHandle;
05093 
05094 
05095 // Simple list of materials
05104 class MtlList: public Tab<MtlHandle> {
05105      public:
05114             CoreExport int AddMtl(Mtl *m, BOOL checkUnique=TRUE);
05121             CoreExport int FindMtl(Mtl *m);
05128             CoreExport int FindMtlByName(MSTR& name);
05133             void RemoveEntry(int n) { Delete(n,1); }
05135             void Empty() { Resize(0); }
05136      };
05137 
05138 #pragma warning(push)
05139 #pragma warning(disable:4239)
05140 
05141 // Materials library
05146 class MtlLib: public ReferenceTarget, public MtlList {
05147      public:
05148             CoreExport SClass_ID SuperClassID(); 
05149             CoreExport Class_ID ClassID();
05152             CoreExport void DeleteAll();
05153             CoreExport void GetClassName(MSTR& s);
05155             CoreExport ~MtlLib();
05156 
05157             int NumSubs() { 
05158                  return Count(); 
05159                  }  
05160             Animatable* SubAnim(int i) { 
05161                  return (*this)[i]; 
05162                  }
05163             CoreExport MSTR SubAnimName(int i);
05168             CoreExport virtual void Remove(Mtl *m);
05173             CoreExport virtual void Add(Mtl *m);
05174 
05175             // From ref
05176             RefResult AutoDelete() { return REF_SUCCEED; }
05177             CoreExport void DeleteThis();
05178             int NumRefs() { return Count();}
05179             RefTargetHandle GetReference(int i) { return (RefTargetHandle)(*this)[i];}
05180 protected:
05181             CoreExport virtual void SetReference(int i, RefTargetHandle rtarg);
05182 public:
05183             CoreExport RefTargetHandle Clone(RemapDir &remap);
05184             CoreExport RefResult NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget, 
05185                  PartID& partID, RefMessage message );
05186             // IO
05187             CoreExport IOResult Save(ISave *isave);
05188                 CoreExport IOResult Load(ILoad *iload);
05189 
05190      };
05191 
05192 
05206 class MtlBaseLib : public ReferenceTarget, public MtlBaseList
05207 {
05208 public:
05209     CoreExport MtlBaseLib();
05211     CoreExport virtual ~MtlBaseLib();
05212 
05213     // from Animitable
05214     CoreExport virtual SClass_ID SuperClassID();
05215     CoreExport virtual Class_ID ClassID();
05216     CoreExport virtual void GetClassName(MSTR& s);
05217     CoreExport virtual int NumSubs();
05218     CoreExport virtual Animatable* SubAnim(int i);
05219     CoreExport virtual MSTR SubAnimName(int i);
05220 
05221     // From ReferenceTarget
05222     CoreExport virtual RefResult AutoDelete();
05223     CoreExport virtual void DeleteThis();
05224     CoreExport virtual int NumRefs();
05225     CoreExport virtual RefTargetHandle GetReference(int i);
05226 protected:
05227     CoreExport virtual void SetReference(int i, RefTargetHandle rtarg);
05228 public:
05229 
05230     CoreExport virtual RefTargetHandle Clone(RemapDir &remap);
05231     CoreExport virtual RefResult NotifyRefChanged(
05232         Interval changeInt, 
05233         RefTargetHandle hTarget, 
05234         PartID& partID, 
05235         RefMessage message );
05236 
05237     // IO
05238     CoreExport virtual IOResult Save(ISave *isave);
05239     CoreExport virtual IOResult Load(ILoad *iload);
05240 
05243     CoreExport virtual void DeleteAll();
05248     CoreExport virtual void Remove(MtlBase *m);
05253     CoreExport virtual void Add(MtlBase *m);
05255     CoreExport virtual void RemoveDuplicates();
05256 
05257 protected:
05259     int GetMaterialCount() const;
05261 
05265     MtlBase* GetMaterial(int i) const;
05267 
05271     MtlBase* FindMaterial(const MCHAR* name) const;
05273 
05277     bool AddMaterial(MtlBase* pMaterial);
05279 
05281     void RemoveMaterial(MtlBase* pMaterial);
05282 
05283     void SetMaterial(int i, MtlBase* pMaterial);
05284     void SetMaterialCount(int count);
05285 
05286     void* mpReserved;
05287 };
05288 
05289 #pragma warning(pop)
05290 // Simple list of numbers
05295 class NumList: public Tab<int> {
05296      public:
05305             CoreExport int Add(int j, BOOL checkUnique=TRUE);
05310             CoreExport int Find(int j);
05311      };
05312 
05313 class MtlRemap: public MaxHeapOperators {
05314      public:
05315             virtual ~MtlRemap() {;}
05316             virtual Mtl* Map(Mtl *oldAddr)=0;
05317      };
05318 
05319 //--------------------------------------------------------------------------------
05320 // Use this class to implement Drag-and-Drop for materials sub-Texmaps.
05321 // If this class is used the ParamDlg method FindSubTexFromHWND() must be implemented.
05322 //--------------------------------------------------------------------------------
05330 class TexDADMgr: public DADMgr {
05331      ParamDlg *dlg;
05332      public:
05333             TexDADMgr(ParamDlg *d=NULL) { dlg = d;}
05334             void Init(ParamDlg *d) { dlg = d; }
05335             // called on the draggee to see what if anything can be dragged from this x,y
05336             SClass_ID GetDragType(HWND hwnd, POINT p) { return TEXMAP_CLASS_ID; }
05337             // called on potential dropee to see if can drop type at this x,y
05338             CoreExport BOOL OkToDrop(ReferenceTarget *dropThis, HWND hfrom, HWND hto, POINT p, SClass_ID type, BOOL isNew);
05339             int SlotOwner() { return OWNER_MTL_TEX;   }
05340             CoreExport ReferenceTarget *GetInstance(HWND hwnd, POINT p, SClass_ID type);
05341             CoreExport void Drop(ReferenceTarget *dropThis, HWND hwnd, POINT p, SClass_ID type, DADMgr* srcMgr = NULL, BOOL bSrcClone = FALSE);
05342             CoreExport BOOL  LetMeHandleLocalDAD(); 
05343             CoreExport void  LocalDragAndDrop(HWND h1, HWND h2, POINT p1, POINT p2);
05344             BOOL  AutoTooltip(){ return TRUE; }
05345      };
05346 
05347 
05348 //--------------------------------------------------------------------------------
05349 // Use this class to implement Drag-and-Drop for materials sub-materials.
05350 // If this class is used the ParamDlg method FindSubMtlFromHWND() must be implemented.
05351 //--------------------------------------------------------------------------------
05359 class MtlDADMgr: public DADMgr {
05360      ParamDlg *dlg;
05361      public:
05362             MtlDADMgr(ParamDlg *d=NULL) { dlg = d;}
05363             void Init(ParamDlg *d) { dlg = d; }
05364             // called on the draggee to see what if anything can be dragged from this x,y
05365             SClass_ID GetDragType(HWND hwnd, POINT p) { return MATERIAL_CLASS_ID; }
05366             // called on potential dropee to see if can drop type at this x,y
05367             CoreExport BOOL OkToDrop(ReferenceTarget *dropThis, HWND hfrom, HWND hto, POINT p, SClass_ID type, BOOL isNew);
05368             int SlotOwner() { return OWNER_MTL_TEX;   }
05369             CoreExport ReferenceTarget *GetInstance(HWND hwnd, POINT p, SClass_ID type);
05370             CoreExport void Drop(ReferenceTarget *dropThis, HWND hwnd, POINT p, SClass_ID type, DADMgr* srcMgr = NULL, BOOL bSrcClone = FALSE);
05371             CoreExport BOOL  LetMeHandleLocalDAD(); 
05372             CoreExport void  LocalDragAndDrop(HWND h1, HWND h2, POINT p1, POINT p2);
05373             BOOL  AutoTooltip(){ return TRUE; }
05374      };
05375 
05376 
05377 #pragma warning(push)
05378 #pragma warning(disable:4239)
05379 
05380 // this class used for Drag/and/dropping Bitmaps
05388 class DADBitmapCarrier: public ReferenceTarget {
05389      MSTR name;
05390      public:
05395      void SetName(const MSTR &nm) { name = nm; }
05397      MSTR& GetName() { return name; }    
05398 
05399      Class_ID ClassID() { return Class_ID(0,1); }
05400      SClass_ID SuperClassID() { return BITMAPDAD_CLASS_ID; }     
05401      void DeleteThis() { }
05402      RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, 
05403                         PartID& partID,  RefMessage message) { return REF_DONTCARE; }     
05404 
05405      RefTargetHandle Clone(RemapDir &remap) { assert(0); return NULL; }
05406 
05407      };
05408 #pragma warning(pop)
05409 
05410 // Get a pointer to the BitmapCarrier (their's only two of these: one for the
05411 // source, and one for the destination:  don't try to delete these; 
05417 CoreExport DADBitmapCarrier *GetDADBitmapCarrier();
05418 
05419 
05420 CoreExport void SetLoadingMtlLib(MtlLib *ml);
05421 CoreExport void SetLoadingMtlBaseLib(MtlBaseLib *ml);
05422 
05423 CoreExport ClassDesc* GetMtlLibCD();
05424 CoreExport ClassDesc* GetMtlBaseLibCD();
05425 
05426 CoreExport UVGen* GetNewDefaultUVGen();
05427 CoreExport XYZGen* GetNewDefaultXYZGen();
05428 CoreExport TextureOutput* GetNewDefaultTextureOutput();
05429 inline int IsMtl(Animatable *m) { return m->SuperClassID()==MATERIAL_CLASS_ID; }
05430 inline int IsTex(Animatable *m) { return m->SuperClassID()==TEXMAP_CLASS_ID; }
05431 inline int IsMtlBase(Animatable *m) { return IsMtl(m)||IsTex(m); }
05432 
05433 // Combines the two materials into a multi-material.
05434 // Either of the two input materials can themselves be multis.
05435 // c1 and c2 will be set to the mat count for mat1 and mat2.
05436 CoreExport Mtl* CombineMaterials(Mtl *mat1, Mtl *mat2, int &mat2Offset);
05437 
05438 // Expand multi material size to the largest face ID
05439 CoreExport Mtl* FitMaterialToMeshIDs(Mesh &mesh,Mtl *mat);
05440 CoreExport Mtl* FitMaterialToShapeIDs(BezierShape &shape, Mtl *mat);
05441 CoreExport Mtl* FitMaterialToPatchIDs(PatchMesh &patch, Mtl *mat);
05442 CoreExport Mtl* FitMaterialToPolyMeshIDs (MNMesh & mesh, Mtl *mat);
05443 
05444 // Adjust face IDs so that no face ID is greater then them multi size
05445 CoreExport void FitMeshIDsToMaterial(Mesh &mesh, Mtl *mat);
05446 CoreExport void FitShapeIDsToMaterial(BezierShape &shape, Mtl *mat);
05447 CoreExport void FitPatchIDsToMaterial(PatchMesh &patch, Mtl *mat);
05448 CoreExport void FitPolyMeshIDsToMaterial (MNMesh & mesh, Mtl *mat);
05449 
05450 // Remove unused mats in a multi and shift face IDs.
05451 CoreExport Mtl *CondenseMatAssignments(Mesh &mesh, Mtl *mat);
05452 CoreExport Mtl *CondenseMatAssignments(BezierShape &shape, Mtl *mat);
05453 CoreExport Mtl *CondenseMatAssignments(PatchMesh &patch, Mtl *mat);
05454 CoreExport Mtl *CondenseMatAssignments (MNMesh &mesh, Mtl *mat);
05455 
05456 
05457 // Attach materials dialog support -- TH 3/9/99
05458 
05459 // Attach Mat values
05460 #define ATTACHMAT_IDTOMAT 0
05461 #define ATTACHMAT_MATTOID 1
05462 #define ATTACHMAT_NEITHER 2
05463 
05495 class AttachMatDlgUser: public MaxHeapOperators {
05496      public:
05498             virtual ~AttachMatDlgUser() {;}
05507             virtual int GetAttachMat()=0;
05509             virtual BOOL GetCondenseMat()=0;
05520             virtual void SetAttachMat(int value)=0;
05525             virtual void SetCondenseMat(BOOL sw)=0;
05526      };
05527 
05528 #pragma warning(pop) // C4100
05529 
05542 CoreExport BOOL DoAttachMatOptionDialog(IObjParam *ip, AttachMatDlgUser *user);
05543 
05544 #define IID_INewSubMapNotification Interface_ID(0x3fe013b2, 0x31815874)
05545 
05546 // Optional interface which can be implemented by classes derived from MtlBase.
05547 // If this interface is returned from GetInterface, then this method is called
05548 // when a new sub-texmap is added to the material.  It lets the material set
05549 // material-specific defaults on the texture map.  This is only called when
05550 // adding newly created textures to the material.
05551 class INewSubTexmapNotification: public BaseInterface
05552 {
05553 public:
05554         virtual void NewSubTexmapAdded(int i, Texmap *m) = 0;
05555      Interface_ID   GetID() { return IID_INewSubMapNotification; }
05556 };
05557 
05558 #define DEFAULT_TEXTURE_MAP_SIZE_INCHES 48.0f
05559 #define DEFAULT_TEXTURE_MAP_SIZE_METERS 1.0f
05560 
05561