mesh.h

Go to the documentation of this file.
00001 
00002 //**************************************************************************/
00003 // Copyright (c) 2008 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:
00012 // CREATED: October 2008
00013 //**************************************************************************/
00014 
00015 namespace mudbox {
00016 
00017 #ifndef MB_NORMALPRECISION
00018 #define MB_NORMALPRECISION 16
00019 #endif
00020 
00021 #ifndef MB_NORMALMAX
00022 #if MB_NORMALPRECISION == 16
00023 //typedef short int tnormal;
00024 //typedef qint64 tnormalv;
00025 #define MB_NORMALMAX 32767
00026 #else
00027 #if MB_NORMALPRECISION == 8
00028 //typedef char tnormal;
00029 //typedef int tnormalv;
00030 #define MB_NORMALMAX 127
00031 #else
00032 #error MB_NORMALPRECISION must be either 8 or 16
00033 #endif
00034 #endif
00035 #endif
00036 
00037 
00039 
00044 struct MBDLL_DECL Vertex
00045 {
00046     inline Vertex( void ) { m_iStrokeID = 0; m_iStates = 0; };
00047 
00048     // data
00049     Vector m_vPos;
00050     mutable unsigned int m_iStrokeID;
00051     //union
00052     //{ 
00053     //  tnormal m_vNormal[4];
00054     //  tnormalv m_iNormal;
00055     //};
00056     unsigned short m_iStates;
00057 
00064     inline float Freeze( void ) const 
00065         { return ((float)(unsigned char)(m_iStates&0x7f))/0x7f; };
00066     
00073     inline void SetFreeze( float fFreeze ) 
00074         { m_iStates = (m_iStates&0xff80)+(unsigned int)(0x7f*fFreeze); };
00075     
00078     inline float Mask( void ) const 
00079         { return ((float)(unsigned char)(m_iStates>>8))/0xff; };
00080     
00083     inline void SetMask( float fMask ) 
00084         { m_iStates = (m_iStates&0xff)+(((unsigned int)(0xff*fMask))<<8); };
00085     
00087     inline bool IsSelected( void ) const { return (m_iStates&0x80) != 0; };
00088     
00090     inline void SetSelected( bool bSelected ) 
00091         { m_iStates = (m_iStates&0xff7f)+bSelected*0x80; };
00092 };
00093 
00098 struct GenericFace
00099 {
00101     unsigned int GetSides( void ) { return m_aIndices.ItemCount(); };
00103     unsigned int Adjacency( unsigned int i) { return m_aAdjacents[i]; };
00105     unsigned int TCI( unsigned int i ) { return m_aTCIs[i]; };
00107     void Serialize( Stream &s )
00108     {
00109         m_aIndices.Serialize( s );
00110         m_aAdjacents.Serialize( s );
00111         m_aTCIs.Serialize( s );
00112     };
00114     const GenericFace & operator=(const GenericFace &rhs)
00115     {
00116         rhs.m_aIndices.Copy(m_aIndices);
00117         rhs.m_aAdjacents.Copy(m_aAdjacents);
00118         rhs.m_aTCIs.Copy(m_aTCIs);
00119         return *this;
00120     }
00121 
00122     Store<unsigned int> m_aIndices;
00123     Store<unsigned int> m_aAdjacents;
00124     Store<unsigned int> m_aTCIs;
00125 };
00126 
00128 
00135 struct MBDLL_DECL TC
00136 {
00137     TC( void ) {m_fU = m_fV = 0.0f;};
00138     TC( float fU, float fV ) { m_fU = fU; m_fV = fV; };
00139     inline bool operator ==( const TC &a ) const { return m_fU == a.m_fU && m_fV == a.m_fV; };
00140     inline bool operator !=( const TC &a ) const { return !operator==( a ); };
00141     inline TC operator +( const TC &a ) const { return TC( m_fU + a.m_fU, m_fV + a.m_fV ); };
00142     inline TC operator -( const TC &a ) const { return TC( m_fU - a.m_fU, m_fV - a.m_fV ); };
00143     inline TC operator *( float f ) const { return TC( m_fU * f, m_fV * f ); };
00144     inline TC operator /( float f ) const { return TC( m_fU / f, m_fV / f ); };
00145     inline TC &operator +=( const TC &a ) { m_fU += a.m_fU, m_fV += a.m_fV; return *this; };
00146     inline TC &operator -=( const TC &a ) { m_fU -= a.m_fU, m_fV -= a.m_fV; return *this; };
00147     inline TC &operator *=( float f ) { m_fU *= f, m_fV *= f; return *this; };
00148     inline TC &operator /=( float f ) { m_fU /= f, m_fV /= f; return *this; };
00149     inline operator bool( void ) const throw() { return m_fU || m_fV; };
00150     inline operator Vector( void ) const throw() { return Vector( m_fU, m_fV, 0 ); };
00151     inline operator const float *( void ) const { return &u; };
00152     void Normalize( void );
00153     float Length( void );
00154     union
00155     {
00156         float m_fU;
00157         float u;
00158     };
00159     union
00160     {
00161         float m_fV;
00162         float v;
00163     };
00164 };
00165 
00179 class MBDLL_DECL FaceEnumerator
00180 {
00181 public:
00183     virtual void Operator(
00184         class Mesh *pMesh,          
00185         unsigned int iFaceIndex     
00186         );
00187     
00190     virtual bool Tester(
00191         class Mesh *pMesh,          
00192         unsigned int iFaceIndex     
00193         );
00194 };
00195 
00196 
00198 
00210 
00211 class MBDLL_DECL VertexEnumerator
00212 {
00213 public:
00214     virtual void Operator(
00215         class Mesh *pMesh,          
00216         unsigned int iVertexIndex,  
00217         unsigned int iFaceIndex     
00218 
00219         );
00220         
00221     virtual bool Tester(
00222         class Mesh *pMesh,          
00223         unsigned int iVertexIndex,  
00224         unsigned int iFaceIndex     
00225 
00226         );
00227 };
00228 
00229 
00240 class MBDLL_DECL AdjacentVertexEnumerator
00241 {
00242 public:
00243     virtual void ProcessAdjacentVertex(
00244         unsigned int iVertexIndex,  
00245         unsigned int iFaceIndex     
00246 
00247         );
00248         
00249     bool m_bEdge;  
00250 
00251 };
00252 
00253 
00260 class MBDLL_DECL Mesh : public Topology
00261 {
00262     DECLARE_CLASS;
00263 
00264 protected:
00272     Mesh(
00273         FaceType eFaceType = typeQuadric    
00274 
00275         );
00276 
00277 public:
00279     virtual class Geometry *Geometry( void ) const;
00280 
00283     virtual class MeshRenderer *Renderer(
00284         float fLODLevel = 1.0f  
00285         );
00286 
00288     virtual void CopyTo( Node *pNode ) const;
00289 
00291     virtual class Material *Material( void ) const;
00292 
00295     virtual class Material *MaterialOverride( void ) const;
00296 
00298     inline unsigned int VertexCount( void ) const { return m_iVertexCount; };
00299     
00301     void SetVertexCount(
00302         unsigned int iVertexCount   
00303         );
00304     
00306     inline unsigned int TCCount( void ) const { return m_pTCs.ItemCount(); };
00307 
00309     virtual void SetTCCount( 
00310         unsigned int iTCCount 
00311         );
00312     
00314     inline bool HasTC( void ) const { return (FaceComponents() & fcTCIndex) != 0 && TCCount() > 0; };
00315 
00317     virtual unsigned int UVlessPaintingStatus( void ) const;
00318 
00320     virtual void SetUVlessPaintingStatus(
00321         unsigned int iStatus    
00322 
00323         );
00324 
00329     inline const Vertex *VertexArray( void ) const { return &m_pVertices[0]; };
00330 
00332     inline const Vertex &VertexData(
00333         unsigned int iVertexIndex   
00334         ) const { return m_pVertices[iVertexIndex]; };
00335     
00337     inline Vertex &VertexData(
00338         unsigned int iVertexIndex   
00339         ) { return m_pVertices[iVertexIndex]; };
00340         
00342     inline const Vector &VertexPosition(
00343         unsigned int iVertexIndex   
00344         ) const { return m_pVertices[iVertexIndex].m_vPos; };
00345     
00347     inline Vector &VertexPosition(
00348         unsigned int iVertexIndex   
00349         ) { return m_pVertices[iVertexIndex].m_vPos; };
00350     
00354     virtual const Vector &VertexOriginalPosition(
00355         unsigned int iVertexIndex   
00356         ) const { return m_pVertices[iVertexIndex].m_vPos; };
00357     
00359     inline const TC &VertexTC(
00360         unsigned int iVertexTCIndex 
00361         ) const { return m_pTCs[iVertexTCIndex]; };
00362     
00364     inline Vector VertexNormal(
00365         unsigned int iVertexIndex   
00366         ) const { return Vector( m_pVertexNormals[iVertexIndex].m_vNormal ); };
00367         
00369     inline unsigned int VertexStrokeID( unsigned int iVertexIndex ) const 
00370         { return m_pVertices[iVertexIndex].m_iStrokeID; };
00371     
00382     inline float VertexMask(
00383         unsigned int iVertexIndex   
00384         ) const { return m_pVertices[iVertexIndex].Mask(); };
00385     
00393     inline float VertexFreeze(
00394         unsigned int iVertexIndex   
00395         ) const { return m_pVertices[iVertexIndex].Freeze(); };
00396     
00399     virtual unsigned int FrozenVertexCount( void ) const;
00400 
00403     inline const tnormal *VertexNormalArray(
00404         unsigned int iVertexIndex   
00405         ) const { return m_pVertexNormals[iVertexIndex].m_vNormal; };
00406     
00409     inline tnormalv VertexNormalValue(
00410         unsigned int iVertexIndex   
00411         ) const { return m_pVertexNormals[iVertexIndex].m_iNormal; };
00412     
00413     inline const Normal *VertexNormalArray( void ) const { return &m_pVertexNormals[0]; };
00414 
00415     inline unsigned int VertexNormalCount( void ) const { return m_pVertexNormals.ItemCount(); }
00416 
00418     virtual AxisAlignedBoundingBox BoundingBox( bool bRecalculate = false ) const;
00419 
00421     virtual AxisAlignedBoundingBox TCBoundingBox( void ) const;
00422 
00424     inline void SetVertexPosition(
00425         unsigned int iVertexIndex,  
00426         const Vector &vPosition     
00427         ) { m_pVertices[iVertexIndex].m_vPos = vPosition; };
00428         
00430     inline void AddVertexPosition(
00431         unsigned int iVertexIndex,  
00432         const Vector &vPosition     
00433         )
00434     { m_pVertices[iVertexIndex].m_vPos += vPosition; };
00435     
00437     inline void SetVertexNormal( unsigned int iVertexIndex, int *pNormal)
00438     {
00439         m_pVertexNormals[iVertexIndex].m_vNormal[0] = tnormal(pNormal[3]);
00440         m_pVertexNormals[iVertexIndex].m_vNormal[1] = tnormal(pNormal[2]);
00441         m_pVertexNormals[iVertexIndex].m_vNormal[2] = tnormal(pNormal[1]);
00442     };
00443     
00445     inline void SetVertexNormal(
00446         unsigned int iVertexIndex,  
00447         const Vector &vNormal       
00448         )
00449         {
00450             m_pVertexNormals[iVertexIndex].m_vNormal[0] = tnormal(vNormal.x * MB_NORMALMAX);
00451             m_pVertexNormals[iVertexIndex].m_vNormal[1] = tnormal(vNormal.y * MB_NORMALMAX);
00452             m_pVertexNormals[iVertexIndex].m_vNormal[2] = tnormal(vNormal.z * MB_NORMALMAX);
00453         };
00454         
00455     // Adds vNormal to the current normal of the vertex with the given index.
00456     //void AddVertexNormal(
00457     //  unsigned int iVertexIndex,  ///< [in] index of the vertex
00458     //  const Vector &vNormal       ///< [in] x,y,z offset to be added to the normal
00459     //  );
00460     
00462     inline void SetVertexTC(
00463         unsigned int iTCIndex,  
00464         const TC &tc            
00465         ) { m_pTCs[iTCIndex] = tc; }
00466 
00468     virtual void SetVertexFreeze(
00469         unsigned int iVertexIndex,  
00470         unsigned int iFaceIndex,    
00471         float fFreeze               
00472 
00473         );
00474 
00476     virtual void SetFreezeValues(
00477         Store<float> &aNewFreeze    
00478         );
00479 
00481     void SetVertexMask( unsigned int iVertexIndex, unsigned int iFaceIndex, float fFMask );
00482     
00484     inline void SetVertexStrokeID( unsigned int iVertexIndex, unsigned int iStrokeID ) const 
00485         { m_pVertices[iVertexIndex].m_iStrokeID = iStrokeID; };
00486 
00493     virtual void MarkVertex(
00494         unsigned int iVertexIndex   
00495         );
00496         
00503     virtual bool IsVertexMarked(
00504         unsigned int iVertexIndex   
00505         );
00506     
00514     virtual void ClearVertexMarks( void );
00515 
00525     virtual unsigned int VertexExternalIndex( 
00526         unsigned int iVertexIndex 
00527         ) const; 
00528 
00531     virtual void SetVertexExternalIndex( 
00532         unsigned int iVertexIndex, 
00533         unsigned int iExternalVertexIndex 
00534         );
00535     
00538     inline const Vector &TriangleVertexPosition(
00539         unsigned int iTriangleIndex,    
00540         unsigned int iCornerIndex       
00541         ) const { return VertexPosition( TriangleIndex( iTriangleIndex, iCornerIndex ) ); };
00542 
00544     inline const Vector &QuadVertexPosition(
00545         unsigned int iQuadIndex,    
00546         unsigned int iCornerIndex   
00547         ) const { return VertexPosition( QuadIndex( iQuadIndex, iCornerIndex ) ); };
00548         
00551     const TC &TriangleVertexTC(
00552         unsigned int iTriangleIndex,    
00553         unsigned int iCornerIndex       
00554         ) const { return VertexTC( TriangleTCI( iTriangleIndex, iCornerIndex ) ); };
00555         
00557     const TC &QuadVertexTC(
00558         unsigned int iQuadIndex,    
00559         unsigned int iCornerIndex   
00560         ) const { return VertexTC( QuadTCI( iQuadIndex, iCornerIndex ) ); };
00561 
00563     inline Vector TriangleVertexNormal(
00564         unsigned int iTriangleIndex,    
00565         unsigned int iCornerIndex       
00566         ) const { return VertexNormal( TriangleIndex( iTriangleIndex, iCornerIndex ) ); };
00567 
00569     inline Vector QuadVertexNormal(
00570         unsigned int iQuadIndex,    
00571         unsigned int iCornerIndex   
00572         ) const { return VertexNormal( QuadIndex( iQuadIndex, iCornerIndex ) ); };
00573 
00575     inline Vector TriangleVertexCreaseNormal(
00576         unsigned int iTriangleIndex,    
00577         unsigned int iCornerIndex       
00578         ) const { return VertexNormal( TriangleCreaseNormalIndex( iTriangleIndex, iCornerIndex ) ); };
00579 
00581     inline Vector QuadVertexCreaseNormal(
00582         unsigned int iQuadIndex,    
00583         unsigned int iCornerIndex   
00584         ) const { return VertexNormal( QuadCreaseNormalIndex( iQuadIndex, iCornerIndex ) ); };
00585 
00587     inline float TriangleVertexFreeze(
00588         unsigned int iTriangleIndex,    
00589         unsigned int iCornerIndex       
00590         ) const { return VertexFreeze( TriangleIndex( iTriangleIndex, iCornerIndex ) ); };
00591 
00594     inline float QuadVertexFreeze(
00595         unsigned int iQuadIndex,    
00596         unsigned int iCornerIndex   
00597         ) const { return VertexFreeze( QuadIndex( iQuadIndex, iCornerIndex ) ); };
00598 
00600     inline const tnormal *TriangleVertexNormalArray(
00601         unsigned int iTriangleIndex,    
00602         unsigned int iCornerIndex       
00603         ) const { return VertexNormalArray( TriangleIndex( iTriangleIndex, iCornerIndex ) ); };
00604 
00606     inline const tnormal *QuadVertexNormalArray(
00607         unsigned int iQuadIndex,    
00608         unsigned int iCornerIndex   
00609         ) const { return VertexNormalArray( QuadIndex( iQuadIndex, iCornerIndex ) ); };
00610 
00612     inline tnormalv TriangleVertexNormalValue(
00613         unsigned int iTriangleIndex,    
00614         unsigned int iCornerIndex       
00615         ) const { return VertexNormalValue( TriangleIndex( iTriangleIndex, iCornerIndex ) ); };
00616 
00618     inline tnormalv QuadVertexNormalValue(
00619         unsigned int iQuadIndex,    
00620         unsigned int iCornerIndex   
00621         ) const { return VertexNormalValue( QuadIndex( iQuadIndex, iCornerIndex ) ); };
00622 
00634     virtual void EnumerateFaces(
00635         unsigned int iFaceIndex,        
00636         FaceEnumerator *pEnumerator,    
00637         bool bSymmetry = false          
00638 
00639         );
00640 
00646     virtual void EnumerateNearestFaces(
00647         unsigned int iFaceIndex,        
00648         FaceEnumerator *pOperation      
00649         );
00650 
00655     virtual void EnumerateVertices(
00656         unsigned int iFaceIndex,        
00657         VertexEnumerator *pEnumerator   
00658         );
00659 
00665     unsigned int EnumerateAdjacentVertices(
00666         AdjacentVertexEnumerator *pEnumerator,  
00667         unsigned int iVertexIndex,              
00668         unsigned int iFaceIndex                 
00669         );
00670 
00672     virtual int MeshVersion( void ) const;
00673 
00675     virtual void SmoothTextureCoordinates( float fStrength);
00676 
00678     virtual void RecalculateNormals(
00679         bool bKeep = false  
00680         );
00681 
00683     virtual void RecalculateAdjacency( 
00684         bool bForce = true  
00685         );
00686 
00688     virtual unsigned int CollectionID( void ) const;
00689 
00691     virtual void IncreaseCollectionID( void );
00692 
00694     virtual bool IsSelected( void );
00695 
00697     virtual void SetSelected( bool bOn = true );
00698 
00701     virtual class LayerMeshData *AddLayer( Layer * pLayer = NULL );
00702 
00705     virtual void RemoveLayer( 
00706         LayerMeshData* pLayer 
00707         );
00708 
00710     virtual class LayerMeshData *ActiveLayer( void ) const;
00711 
00715     aptr<LayerMeshData> ActiveSculptLayer;
00716 
00718     virtual bool IsActiveLevel( void ) const;
00719 
00726     virtual bool Lock( 
00727         class MeshUnlocker *pUnlocker = NULL 
00728 
00729         );
00730 
00736     virtual bool Unlock( void );
00737 
00739     virtual bool IsLocked( void );
00740 
00744     class MeshChange *StartChange( void );
00745 
00747     virtual bool IsNSided( void ) const;
00749     virtual GenericFace &Face( unsigned int iIndex );
00751     virtual unsigned int GenericFaceCount( void );
00752 
00755     virtual bool HasExpandedTCs( void ) const;
00757     virtual void CreateExpandedTCs( void );
00759     virtual TC &ExpandedTC( unsigned int index );
00761     virtual bool SupportsTangentMirror() const;
00763     virtual unsigned int TangentMirroredFaceIndex( unsigned int iFaceIndex ) const;
00765     virtual unsigned int TangentMirroredVertexIndex( unsigned int iFaceIndex,
00766         unsigned int iCornerIndex, 
00767         unsigned int &iOppositeFaceIndex, 
00768         unsigned int &iOppositeCornerIndex) const;
00769 
00770     Store<TC> m_pTCs;
00771 
00773     aevent Modified;
00774 
00777     virtual bool InitializeTopologicalSymmetry( unsigned int iFaceIndex0, unsigned int iFaceIndex1 );
00780     virtual bool IsTopologicalSymmetryInitialized( unsigned int &iFaceIndex0, unsigned int &iFaceIndex1 ) const;
00782     virtual void RecalculateTopologicalSymmetry( void );
00783     
00784     virtual unsigned int PrimaryCount(bool bNeedToUseTC);
00788     virtual unsigned int QuadPrimaryIndex(bool bNeedToUseTC, unsigned int iFaceIndex, unsigned int iCornerIndex);
00792     virtual unsigned int TrianglePrimaryIndex(bool bNeedToUseTC, unsigned int iFaceIndex, unsigned int iCornerIndex);
00793     
00794     virtual void Transform( const Matrix &mMatrix );
00795 
00796     virtual void CheckValidity( DiagnosticLevel iLevel = dgnLevel2 ) const;
00797 
00798 protected:
00799     Store<Vertex> m_pVertices;
00800     unsigned int m_iVertexCount;
00801     Store<Normal> m_pVertexNormals;
00802 };
00803 
00805 class MBDLL_DECL MeshFreezer : public Node
00806 {
00807     DECLARE_CLASS;
00808 public:
00809     virtual void Freeze( Mesh *pMesh, Store<float> aFreezeData, bool bMerge = false );
00810 };
00811 
00813 class MBDLL_DECL MeshSelector : public Node
00814 {
00815     DECLARE_CLASS;
00816 public:
00817     virtual void Select( Mesh *pMesh, bool bState, const Store<unsigned int> &aSelectionData, bool bMerge = false );
00818 };
00819 
00846 class MBDLL_DECL TangentGenerator : public TreeNode
00847 {
00848     DECLARE_CLASS;
00849 public:
00851     virtual Vector ConvertToTangent(
00852         unsigned int iVertexIndex,  
00853         const Vector &vVector       
00854         ) const;
00855     
00857     virtual Vector ConvertToObject(
00858         unsigned int iVertexIndex,  
00859         const Vector &vVector       
00860         ) const;
00861         
00863     virtual Base LocalBase(
00864         unsigned int iFaceIndex,    
00865         unsigned int iCornerIndex   
00866         );
00867     
00869     virtual void SetNormalization(
00870         bool bNormalize     
00871         );
00872 };
00873 
00874 
00876 
00881 struct MBDLL_DECL SurfacePoint
00882 {
00883     class Mesh *m_pMesh;            
00884     unsigned int m_iFaceIndex;  
00885     float m_fRelativeRange;     
00886     Vector m_vLocalPosition;    
00887     Vector m_vLocalNormal;      
00888     bool m_bSide;               
00889     TangentGenerator *m_pTG;    
00890 
00892     SurfacePoint( void );
00893     
00895     SurfacePoint(
00896         class Mesh *pMesh,          
00897         unsigned int iVertexIndex,  
00898         unsigned int iFaceIndex     
00899         );
00900         
00902     class Mesh *Mesh( void ) const;
00903     
00905     unsigned int FaceIndex( void ) const;
00906         
00908     Vector LocalPosition( void ) const;
00909     
00911     Vector WorldPosition( void ) const;
00912     
00914     Vector LocalNormal( void ) const;
00915     
00917     Vector WorldNormal( void ) const;
00918 
00920     TC TextureCoordinate( void ) const;
00921     
00923     Base TangentBase( void ) const;
00924 
00926     Vector FaceCoordinates( void ) const;
00927 
00934     bool Fill(
00935         class Mesh *pMesh,  
00936         unsigned int iFaceIndex,    
00937         const Vector &vStart,       
00938         const Vector &vEnd,         
00939         bool bTwoSide = false,      
00940         bool bOriginalPosition = false
00941         );
00942 
00947     void Fill(
00948         class Mesh *pMesh,          
00949         unsigned int iFaceIndex,    
00950         float fFaceU,                       
00951         float fFaceV                        
00952         );
00953 
00958     void Fill(
00959         class Mesh *pMesh,          
00960         unsigned int iFaceIndex,        
00961         const Vector &vLocalPosition,   
00962         bool bRecalculatePosition   
00963         );
00964     
00970     void SetTangentGenerator( 
00971                              TangentGenerator *pGenerator   
00972                              );
00973 
00976     void Align( void ); 
00977 
00978     mutable Vector m_vFaceCoordinates;
00979 };
00980 
00996 class MBDLL_DECL Picker : public TreeNode
00997 {
00998     DECLARE_CLASS;
00999 
01000 public:
01001     virtual void SetMesh(
01002         Mesh *m_pMesh       
01003         );
01004     
01005     virtual bool Pick(
01006         const Vector &vLocalStart,  
01007         const Vector &vLocalEnd,    
01008         bool bBothSides,            
01009         SurfacePoint &cResult,      
01010         float fTarget = 0.5f        
01011         );
01012 };
01013 
01028 class MBDLL_DECL ScreenSpacePicker : public Node
01029 {
01030     DECLARE_CLASS;
01031 
01032 public:
01034     virtual void SetFramebufferSize(
01035         unsigned int iWidth,    
01036         unsigned int iHeight    
01037         );
01038     
01040     virtual bool Pick(
01041         const class Camera *pCamera,    
01042         float fXPosition,               
01043         float fYPosition,               
01044         SurfacePoint &sResult           
01045         );
01046 };
01047 
01073 class MBDLL_DECL MeshGrid : public TreeNode
01074 {
01075     DECLARE_CLASS;
01076 
01077 public:
01079     virtual unsigned int MeshGridCount( void ) const;
01080     
01083     virtual unsigned int MeshGridLevel( 
01084         unsigned int iMeshGridIndex 
01085         ) const;
01086     
01089     virtual unsigned int MeshGridFaceIndex( 
01090         unsigned int iMeshGridIndex, 
01091         unsigned int iX,            
01092         unsigned int iY         
01093         ) const;
01094     
01096     virtual unsigned int MeshGridVertexIndex( 
01097         unsigned int iMeshGridIndex, 
01098         unsigned int iX,            
01099         unsigned int iY         
01100         ) const;
01101     
01103     virtual unsigned int MeshGridTCIndex( 
01104         unsigned int iMeshGridIndex, 
01105         unsigned int iX,            
01106         unsigned int iY         
01107         ) const;
01108     
01110     virtual unsigned int MeshGridIndexByFaceIndex( 
01111         unsigned int iFaceIndex     
01112         ) const;
01113 };
01114 
01133 class MBDLL_DECL SurfaceSmoother : public TreeNode
01134 {
01135     DECLARE_CLASS;
01136 
01137 public:
01139     virtual Vector SmoothPosition( 
01140         unsigned int iFaceIndex, 
01141         double fUCoordinate, 
01142         double fVCoordinate, 
01143         bool bConsiderCrease = true, 
01144         bool bConsiderHarden = true  
01145         ) const;
01146     
01148     virtual Vector SmoothNormal( 
01149         unsigned int iFaceIndex, 
01150         double fUCoordinate, 
01151         double fVCoordinate, 
01152         bool bConsiderCrease = true, 
01153         bool bConsiderHarden = true  
01154         ) const;
01155     
01157     virtual Vector SmoothTextureCoordinate( 
01158         unsigned int iFaceIndex, 
01159         double fUCoordinate, 
01160         double fVCoordinate 
01161         ) const;
01162 
01164     virtual Base SmoothTangent( 
01165         unsigned int iFaceIndex, 
01166         double fUCoordinate, 
01167         double fVCoordinate 
01168         ) const;
01169 };
01170 
01177 class MBDLL_DECL MeshChange : public Node
01178 {
01179     MeshChange( Mesh *m_pMesh );
01180 
01181 public:
01183     struct VertexChange
01184     {
01186         Vector m_vPosition;
01188         unsigned int m_iID;
01190         union
01191         {
01192             tnormalv m_iNormal;
01193             tnormal m_vNormal[4];
01194         };
01196         float m_fData;
01198         unsigned int m_iVertexIndex;
01200         unsigned int m_iFaceIndex;
01202         unsigned int m_iLayerVertexIndex;
01203     };
01204     
01206     inline float Data(
01207         unsigned int iVertexIndex 
01208         ) const
01209     {
01210         Vertex &v = m_pMesh->VertexData( iVertexIndex );
01211         if ( v.m_iStrokeID < m_iVertexCount && m_pArray[v.m_iStrokeID].m_iVertexIndex == iVertexIndex )
01212             return m_pArray[v.m_iStrokeID].m_fData;
01213         else
01214             return 0.0f;
01215     };
01216 
01218     inline const Vector &OriginalPosition( 
01219         unsigned int iVertexIndex 
01220         ) const
01221     {
01222         Vertex &v = m_pMesh->VertexData( iVertexIndex );
01223         if ( v.m_iStrokeID < m_iVertexCount && m_pArray[v.m_iStrokeID].m_iVertexIndex == iVertexIndex )
01224             return m_pArray[v.m_iStrokeID].m_vPosition;
01225         else
01226             return v.m_vPos;
01227     };
01228     
01230     inline Vector OriginalNormal( 
01231         unsigned int iVertexIndex 
01232         ) const
01233     {
01234         Vertex &v = m_pMesh->VertexData( iVertexIndex );
01235         if ( v.m_iStrokeID < m_iVertexCount && m_pArray[v.m_iStrokeID].m_iVertexIndex == iVertexIndex )
01236             return m_pArray[v.m_iStrokeID].m_vNormal;
01237         else
01238             //return v.m_vNormal;
01239             return m_pMesh->VertexNormal(iVertexIndex);
01240     };
01241     
01242 
01243     // this function is not being inlined as it is too big, si it is split into a small inlined part,
01244     // and the larger not inlined part...
01245     private:
01246     VertexChange &Add_uncached(     // see arg list of Add just below....
01247         unsigned int  iVertexIndex, 
01248         unsigned int  iFaceIndex,
01249         Vertex       &v, 
01250         bool          bPrecalculateLayerIndex = false );
01251 
01252     public:
01255     inline VertexChange &Add( 
01256         unsigned int iVertexIndex, 
01257         unsigned int iFaceIndex,   
01258         bool bPrecalculateLayerIndex = false 
01259 
01260         )
01261     {
01262         Vertex &v = m_pMesh->VertexData( iVertexIndex );
01263         if ( v.m_iStrokeID < m_iVertexCount && 
01264              m_pArray[v.m_iStrokeID].m_iVertexIndex == iVertexIndex )
01265             return m_pArray[v.m_iStrokeID]; // 80% of the time it hits this...
01266         else 
01267             return Add_uncached(iVertexIndex, iFaceIndex, v, bPrecalculateLayerIndex);
01268     };
01269 
01271     void Finish( 
01272         bool bUndo = true,  
01273 
01274         bool bMerge = false 
01275         );
01276 
01277 private:
01278     Mesh *m_pMesh;
01279 
01280     Store<VertexChange> &m_pArray;
01281     unsigned int &m_iVertexCount;
01282 
01283     friend class Mesh;
01284 };
01285 
01291 class MBDLL_DECL MeshUnlocker
01292 {
01293 public:
01298     virtual bool Unlock( 
01299         Mesh *pMesh 
01300         );
01301 };
01302 
01303 }; // end of namespace mudbox
01304 
01305