- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# material.h

Go to the documentation of this file.

    00001
    00002 //**************************************************************************/
    00003 // Copyright (c) 2008 - 2010 Autodesk, Inc.
    00004 // All rights reserved.
    00005 //
    00006 // Use of this software is subject to the terms of the Autodesk license
    00007 // agreement provided at the time of installation or download, or which
    00008 // otherwise accompanies this software in either electronic or hard copy form.
    00009 //
    00010 //**************************************************************************/
    00011 // DESCRIPTION: Mudbox Plugin API header -- Material and Texture classes.
    00012 // CREATED: October 2008
    00013 //**************************************************************************/
    00014
    00015 namespace mudbox {
    00016 //------------------------------------------------------------------------------
    00073 class MBDLL_DECL Material : virtual public TreeNode
    00074 {
    00075     DECLARE_CLASS;
    00076
    00081     enum VertexDataUsage
    00082     {
    00086         eVDUPosition,
    00087         eVDUNormal,
    00088         eVDUTextureCoordinate,
    00089         eVDUVertexColor,
    00090         eVDUBoneIndices,
    00091         eVDUBoneWeights,
    00092
    00093         eVDUTangent,
    00094         eVDUBinormal,
    00095
    00096
    00100         eVDUDirectTextureCoordinate0,
    00101         eVDUDirectTextureCoordinate1,
    00102         eVDUDirectTextureCoordinate2,
    00103         eVDUDirectTextureCoordinate3,
    00104         eVDUDirectTextureCoordinate4,
    00105         eVDUDirectTextureCoordinate5,
    00106         eVDUDirectTextureCoordinate6,
    00107         eVDUDirectTextureCoordinate7,
    00108
    00109
    00110         eVDUNotUsed
    00111     };
    00112
    00113 protected:
    00119     Material( void );
    00120
    00121 public:
    00122     ~Material();
    00123
    00130     virtual bool Activate(
    00131         const Mesh *pMesh,
    00132         const AxisAlignedBoundingBox &cUVArea,
    00133
    00134         const Color &cColor = Color::white
    00135         );
    00136
    00138     virtual void Deactivate( void );
    00139
    00149     virtual float Transparency( void ) const;
    00150
    00153     virtual void SetTransparency(
    00154         float fTransparency
    00155         );
    00156
    00168     virtual bool TexturesVisible( void ) const;
    00169
    00171     virtual void SetTexturesVisible(
    00172         bool bVisible
    00173         );
    00174
    00181     virtual bool IsTCNeeded( void ) const;
    00182
    00189     virtual bool IsTNBNeeded( void ) const;
    00190
    00192     virtual unsigned int TextureCount( void ) const;
    00193
    00195     virtual class TexturePool *Texture(
    00196         unsigned int iTextureIndex
    00197         ) const;
    00198
    00212     virtual bool SetTextureTileLive(
    00213         const AxisAlignedBoundingBox &cUVArea,
    00214         bool bLive,
    00215         float fTCGrad = -1.0f,
    00216         bool bSync = false,
    00217         bool bLazyUpdate = false
    00218         );
    00219
    00221     virtual bool IsTextureTileLive(
    00222         const AxisAlignedBoundingBox &cUVArea
    00223         );
    00224
    00226     virtual unsigned int TextureTileCount() const;
    00227
    00229     virtual void SetTextureTileLODBias(
    00230         const AxisAlignedBoundingBox& cArea,
    00231         float fTCGrad
    00232         );
    00233
    00238     virtual qint64 TileVideoMemoryUsage(
    00239         const AxisAlignedBoundingBox& cArea,
    00240         float fTCGrad = -1.0f
    00241         ) const;
    00242
    00244     virtual AxisAlignedBoundingBox TextureTileArea(
    00245         unsigned int iTileIndex
    00246         ) const;
    00247
    00254     virtual void ActivateUVArea( const AxisAlignedBoundingBox &cArea );
    00255
    00260     virtual VertexDataUsage MapVertexData(
    00261         VertexDataUsage eUsage
    00262
    00263         ) const;
    00264
    00266     virtual Layer *ImportPaintLayer(
    00267         const QString &sFileName,
    00268
    00269         const QString &sChallenName,
    00270         Mesh *pMesh = 0
    00271
    00272         );
    00273 };
    00274
    00275
    00276 //-----------------------------------------------------------------------------
    00278 class MBDLL_DECL TextureMixer : public Node
    00279 {
    00280     DECLARE_CLASS;
    00281
    00282 protected:
    00288     TextureMixer( void );
    00289
    00290 public:
    00292     virtual unsigned int BlendModeCount( void ) const;
    00293
    00295     virtual QString BlendModeDisplayName(
    00296         int iBlendMode
    00297         ) const;
    00298
    00300     virtual QString BlendModeName(
    00301         int iBlendMode
    00302         ) const;
    00303
    00307     virtual void SetBlendMode(
    00308         int iBlendMode
    00309         ) ;
    00310
    00313     virtual void SetBlendModeParameters(
    00314         const Store<float>& pParameters
    00315         );
    00316
    00318     virtual void SetLayerCount(
    00319         unsigned int iLayerCount
    00320         );
    00321
    00323     virtual void SetLayerData(
    00324         unsigned int iLayerIndex,
    00325         int iTextureID,
    00326         float fTransparency,
    00327         int iMaskID = 0,
    00328         float fMaskTransparency = 1.0f
    00329         );
    00330
    00332     virtual void Mix(
    00333         class Texture *d,
    00334         unsigned int iWidth,
    00335         unsigned int iHeight,
    00336         enum Image::Format eFormat
    00337         );
    00338
    00339 };
    00340
    00341 //-----------------------------------------------------------------------------
    00346 class MBDLL_DECL TextureTileArray {
    00347     private:
    00348         // this describes a texture tile. It has a pointer to the texture and
    00349         // a small amount of frequently accessed metadata. This object should
    00350         // be kept as small as possible, as there will be a 2D, non-sparse
    00351         // array of these kept my the texture pool.
    00352         // presently 16 bytes on a 64 bit machine, 12 bytes on a 32 bit machine.
    00353         class TileDescriptor {
    00354             public:
    00355                 TileDescriptor() : m_TileStateIndex(-1) {}
    00356                 int           m_TileStateIndex;
    00357         };
    00358
    00359
    00360         float  m_UOrigin, m_VOrigin; // origin (may be negative) in UV space of this array.
    00361         int    m_USize, m_VSize;     // Size in U and V covered by this tile array
    00362
    00363         TileDescriptor *m_Tiles;     // pointer to the tile array - declared as 1D, but
    00364                                      // accessed as a 2D array by tileFromUV
    00365
    00366         // given UV coordinates, return the TileDescriptor
    00367         TileDescriptor *tileFromUV(float U, float V) const
    00368         {
    00369             U -= m_UOrigin; V -= m_VOrigin;     // bring to 0 origin
    00370             int u = (int)U, v = (int)V;         // same as floor now that they are positive
    00371             return &m_Tiles[(v * m_USize) + u]; // classic 2D array access math.
    00372         }
    00373
    00374         // resize the TileArray to include these UV coordinates.
    00375         void     resizeArrayToInclude(float U, float V);
    00376
    00377         // initialize the class.
    00378         void init()
    00379         {
    00380             m_UOrigin, m_VOrigin = 0;
    00381             m_USize, m_VSize = 0;
    00382             m_Tiles = NULL;
    00383         }
    00384
    00385     public :
    00386
    00387         TextureTileArray()  { init();    }
    00388         ~TextureTileArray() { dropAll(); }
    00389
    00392         float getMinU() const { return m_UOrigin; }
    00395         float getMinV() const { return m_VOrigin; }
    00398         float getMaxU() const { return m_UOrigin + (float)m_USize; }
    00401         float getMaxV() const { return m_VOrigin + (float)m_VSize; }
    00402
    00404         void getTotalUVBounds(float &minU, float &minV, float &maxU, float &maxV) const
    00405         {
    00406             minU = m_UOrigin;
    00407             minV = m_VOrigin;
    00408             maxU = minU + (float)m_USize;
    00409             maxV = minV + (float)m_VSize;
    00410         }
    00411
    00414         bool contains(float U, float V) const
    00415         {
    00416             return m_Tiles && U >= getMinU() && U < getMaxU() && V >= getMinV() && V < getMaxV();
    00417         }
    00418
    00419
    00420         int getTileStateIndex(float U, float V) const
    00421         {
    00422             if (!contains(U, V)) return -1; else
    00423             return tileFromUV(U, V)->m_TileStateIndex;
    00424         }
    00425
    00426         void setTileStateIndex(float U, float V, int indx)
    00427         {
    00428             if (!contains(U, V)) resizeArrayToInclude(U, V);
    00429             tileFromUV(U, V)->m_TileStateIndex = indx;
    00430         }
    00431
    00432
    00437         void dropAll();
    00438
    00439         void clearTileStateIndices();
    00440 };
    00441
    00442
    00443 //-----------------------------------------------------------------------------
    00459 class MBDLL_DECL TexturePool : virtual public Node
    00460 {
    00461     DECLARE_CLASS;
    00462
    00463 protected:
    00469     TexturePool( void );
    00470
    00471     TextureTileArray     m_TextureTileArray;
    00472
    00473 public:
    00474
    00476     struct MBDLL_DECL TileDescriptor
    00477     {
    00478         unsigned int m_iWidth;
    00479         unsigned int m_iHeight;
    00480         enum Image::Format m_eFormat;
    00481         unsigned int m_iChannelCount;
    00482         Color m_cFillColor;
    00483         QString m_sFileFormat;
    00484
    00485         TileDescriptor( unsigned int iW, unsigned int iH, enum Image::Format eFormat, unsigned int iChannelCount, const QString& sFileFormat, const Color& cFillColor );
    00486
    00487         TileDescriptor();
    00488
    00489         TileDescriptor( const TileDescriptor& pOther, unsigned int iChannelCount );
    00490
    00491         bool IsValid() const;
    00492
    00493         virtual void Serialize( Stream& s );
    00494     };
    00495
    00496     enum RenderMode
    00497     {
    00498         renderModeConstantColor,
    00499         renderModeTexture,
    00500         renderModeVertexColor
    00501     };
    00502
    00503     enum Location
    00504     {
    00505         locationUnknown,
    00506         locationGPU,
    00507         locationCPU,
    00508         locationDisk
    00509     };
    00510
    00511     enum Usage
    00512     {
    00513         usagePaintLayer,
    00514         usageLayerMask,
    00515         usageAdjustmentLayer,
    00516         usageUnknown
    00517     };
    00518
    00520     virtual const TileDescriptor& DefaultTileDescriptor( void ) const;
    00521
    00523     virtual void SetDefaultTileDescriptor( const TileDescriptor& pDesc );
    00524
    00534     virtual enum Usage Usage() const;
    00535
    00537     virtual void SetUsage( enum Usage eUsage );
    00538
    00540     virtual QString Name( void ) const;
    00541
    00543     virtual void SetName(
    00544         const QString &sName
    00545
    00546         );
    00547
    00549     virtual unsigned int RenderMode( void ) const;
    00550
    00552     virtual void SetRenderMode( unsigned int iMode );
    00553
    00555     virtual void SetLocation( unsigned int iLocation );
    00556
    00558     virtual unsigned int Location( void ) const;
    00559
    00560     virtual TexturePool &operator =( TexturePool &cT );
    00561
    00571     virtual int Width( void ) const;
    00572
    00574     virtual void SetWidth( int iWidth );
    00575
    00584     virtual void SetFileName(
    00585         const QString &sFileName
    00586         );
    00587
    00590     virtual const QString& FileName( void ) const;
    00591
    00595     virtual void Save(
    00596         const QString &sFileName = "",
    00597         const QString &sFormat = "",
    00598
    00599
    00600         Material *m = NULL,
    00601         bool bForced = false
    00602         );
    00603
    00606     virtual void Export(
    00607         const QString &sFileName,
    00608         const QString &sFormat = "",
    00609
    00610
    00611         Material *m = NULL
    00612         );
    00613
    00617     virtual void SetDirty(
    00618         bool bDirty
    00619         );
    00620
    00622     virtual bool IsDirty( void ) const;
    00623
    00625     virtual void AddToDirtyArea(
    00626         const Vector &cPoint
    00627     );
    00628
    00630     virtual void SetTilesDirty( void );
    00631
    00633     virtual void Reload( void );
    00634
    00636     virtual void SetContentChanged( void );
    00637
    00639     virtual bool IsContentChanged( void );
    00640
    00642     virtual unsigned int TileCount( void ) const;
    00643
    00645     virtual class Texture *Tile(
    00646         unsigned int iTileIndex
    00647         );
    00648
    00651     virtual class Texture *Tile(
    00652         const AxisAlignedBoundingBox &cTCArea,
    00653         bool bAlloc = true
    00654
    00655         );
    00656
    00660     virtual class Texture *Tile(float U, float V, bool bAlloc = true);
    00661
    00663     virtual AxisAlignedBoundingBox TileArea(
    00664         unsigned int iTileIndex
    00665         ) const;
    00666
    00667     TextureTileArray  *getTextureTileArray() { return &m_TextureTileArray; }
    00668
    00670     virtual TextureMixer *Mixer( void ) const;
    00671
    00673     virtual int BlendMode( void ) const;
    00674
    00676     virtual void SetBlendMode(
    00677         int iMode
    00678
    00679         );
    00680
    00681     virtual void SetMaterial(
    00682         Material* pMaterial
    00683         );
    00684
    00685     virtual Material *GetMaterial() const;
    00686
    00687     // Internal use only.
    00688     virtual TexturePool *Buffer( void ) const;
    00689
    00693     virtual qint64 TileVideoMemoryUsage(
    00694         const AxisAlignedBoundingBox& cArea,
    00695         float fTCGrad = -1
    00696     );
    00697 };
    00698
    00699 //-----------------------------------------------------------------------------
    00707 class MBDLL_DECL Texture : virtual public Node
    00708 {
    00709     Q_DECLARE_TR_FUNCTIONS(Texture);
    00710     DECLARE_CLASS;
    00711
    00712 protected:
    00718     Texture( void );
    00719
    00720 public:
    00722     virtual void Create(
    00723         unsigned int iWidth,
    00724         unsigned int iHeight,
    00725         unsigned int iChannelCount,
    00726         enum Image::Format eFormat,
    00727         const Color &cColor
    00728         );
    00729
    00731     virtual void Create(
    00732         unsigned int iWidth,
    00733         unsigned int iHeight,
    00734         unsigned int iChannelCount,
    00735         enum Image::Format eFormat
    00736         );
    00737
    00739     virtual bool CreateFromFile(
    00740         const QString &sFileName,
    00741         unsigned int iChannelCount = 0,
    00742         enum Image::Format eFormat = Image::eUnknown
    00743         );
    00744
    00746     virtual const Image *AsImage( void );
    00747
    00750     virtual void CopyTo(
    00751         Texture &cTexture
    00752         ) const;
    00753
    00755     virtual unsigned int Width( void ) const;
    00756
    00758     virtual unsigned int Height( void ) const;
    00759
    00761     virtual unsigned int BitDepth( void ) const;
    00762
    00764     static unsigned int BitDepth( enum Image::Format eFormat );
    00765
    00767     virtual enum Image::Format Format( void ) const;
    00768
    00770     virtual unsigned int ChannelCount( void ) const;
    00771
    00776     virtual bool Activate( void ) const;
    00777
    00780     virtual bool Deactivate( void ) const;
    00781
    00783     virtual unsigned int OpenGLName( void ) const;
    00784
    00786     virtual bool SetAsRenderTarget( void );
    00787
    00789     virtual bool RestoreRenderTarget( void );
    00790
    00791     virtual abool *getFilteringPref();
    00792
    00794     virtual void CopyFrom(
    00795         Image *pImage,
    00796         const ImgTile* pRegion = 0
    00797         );
    00798
    00800     virtual void ReplaceWith(
    00801         Image *pImage,
    00802         const ImgTile* pRegion = 0
    00803         );
    00804
    00807     virtual void CopyTo(
    00808         Image *pImage,
    00809         bool tiled = true,
    00810         const ImgTile *region = 0,
    00811         ImageDescriptor::MemoryChannelOrder eOrder = ImageDescriptor::orderRGBA
    00812
    00813         );
    00814
    00815
    00816
    00818     virtual void SetLocation(
    00819         unsigned int iLocation
    00820
    00821         );
    00822
    00827     virtual unsigned int Location( void ) const;
    00828
    00830     virtual int64 TotalMemoryUsage( void ) const;
    00831
    00833     virtual qint64 VideoMemoryUsage( float fTCGrad = -1.0f ) const;
    00834
    00836     virtual void SetLive(
    00837         bool bLive
    00838         );
    00839
    00841     virtual bool IsLive( void ) const;
    00842
    00845
    00846
    00854         virtual bool NewVersion();
    00855
    00862         virtual bool PrevVersion();
    00863
    00870         virtual bool NextVersion();
    00871
    00874         virtual int  NumVersions();
    00875
    00880         virtual bool MergeOldestVersions();
    00881
    00889         virtual bool PurgeNewerVersions();
    00890
    00893         virtual bool PurgeAllButCurrentVersion();
    00894
    00900         virtual bool BeginUndoableOperation();
    00901
    00904         virtual bool EndUndoableOperation();
    00905
    00907
    00909         virtual void SetFiltered(
    00910             bool bFiltered
    00911             );
    00912
    00915         virtual void SetConvert32To16bitFloat(
    00916             bool bConvert
    00917             );
    00918
    00925         virtual bool setProxyLevel(
    00926             unsigned char level,
    00927             bool bLazySet = false
    00928             );
    00929
    00931         virtual void SyncContent();
    00932
    00934         virtual unsigned char getProxyLevel() const;
    00935
    00939         virtual void Composite(
    00940             const Texture* pTex,
    00941             ImgDirtyRegion* pRegion = 0,
    00942             unsigned int iBlendMode = 0,
    00943             const Store<float>* aBlendParameters = 0
    00944             );
    00945
    00953         static unsigned char ProxyLevel(
    00954             float fTCGrad,
    00955             unsigned int iTextureSize
    00956             );
    00957
    00962         virtual void CopyGLTextureToImage(
    00963             Image *pImage,
    00964             bool tiled = true,
    00965             const ImgTile *region = 0,
    00966             ImageDescriptor::MemoryChannelOrder eOrder = ImageDescriptor::orderRGBA
    00967
    00968             ) const;
    00969 protected:
    00970     ImgDirtyRegion   m_DirtyRegion;
    00971
    00972
    00973 public:
    00974
    00976     virtual bool IsDirty( void ) const;
    00977
    00979     virtual void SetDirty( bool bDirty );
    00980
    00985
    00987
    00989         void ResetDirtyTile()
    00990         {
    00991             m_DirtyRegion.ClearDirtyRegion();
    00992         }
    00993
    01001         virtual void AddDirtyPixel(
    01002             int x,
    01003             int y
    01004             )
    01005         {
    01006             m_DirtyRegion.AddToDirtyRegion(ImgTile(x, y, 1, 1));
    01007         }
    01008
    01014         virtual void AddDirtyTile(
    01015             const ImgTile &t
    01016             )
    01017         {
    01018             m_DirtyRegion.AddToDirtyRegion(t);
    01019         }
    01020
    01021
    01023         ImgTile DirtyTile() const { return m_DirtyRegion.GetTotalBounds(); }
    01024
    01026         ImgDirtyRegion *DirtyRegion() { return &m_DirtyRegion; }
    01027
    01029 };
    01030
    01031
    01032 //-----------------------------------------------------------------------------
    01039 class MBDLL_DECL RenderTarget : public Node
    01040 {
    01041     DECLARE_CLASS;
    01042
    01043     enum Slot
    01044     {
    01045         eSlotColor0 = 0,
    01046         eSlotColor1,
    01047         eSlotColor2,
    01048         eSlotColor3,
    01049         eSlotDepth,
    01050         eSlotCount      // placeholder for last position - not a type of slot
    01051     };
    01052
    01053 public:
    01056     virtual void DrawTexture(
    01057         const class Texture *pTexture
    01058         );
    01059
    01062     virtual bool Attach(
    01063         mudbox::Texture *pTexture,
    01064         Slot eSlot = eSlotColor0
    01065         );
    01066
    01068     virtual void Detach(
    01069         Slot eSlot = eSlotColor0
    01070         );
    01071
    01073     virtual mudbox::Texture *Texture(
    01074         Slot eSlot = eSlotColor0
    01075         ) const;
    01076
    01078     virtual unsigned int Width( void ) const;
    01079
    01081     virtual unsigned int Height( void ) const;
    01082
    01084     virtual void SetSize(
    01085         unsigned int iWidth,
    01086         unsigned int iHeight
    01087         );
    01088
    01090     virtual void Activate( void );
    01091
    01093     virtual void Restore( void );
    01094
    01096     virtual void SetMultisampling( bool bMultisampling );
    01097 };
    01098
    01099
    01100
    01101
    01102
    01103 }; // end of namespace mudbox
    01104