kfbxmesh.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00005 #define FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2009 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 
00042 #include <fbxfilesdk/components/kbaselib/kaydaradef_h.h>
00043 #include <fbxfilesdk/components/kbaselib/kaydara.h>
00044 
00045 #include <fbxfilesdk/kfbxplugins/kfbxgeometry.h>
00046 
00047 #include <fbxfilesdk/kfbxmath/kfbxvector4.h>
00048 #include <fbxfilesdk/kfbxmath/kfbxvector2.h>
00049 
00050 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00051 
00052 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00053 
00054 class KFbxMesh;
00055 class KFbxSdkManager;
00056 
00070 class KFBX_DLL KFbxMesh : public KFbxGeometry
00071 {
00072     KFBXOBJECT_DECLARE(KFbxMesh,KFbxGeometry);
00073 
00074 public:
00078     virtual EAttributeType GetAttributeType() const;
00079 
00084 
00094     void BeginPolygon(int pMaterial = -1, int pTexture = -1, int pGroup = -1, bool pLegacy=true);
00095 
00102     void BeginPolygonExt(int pMaterial, int* pTextures);
00103 
00109     void AddPolygon(int pIndex, int pTextureUVIndex = -1);
00110 
00112     void EndPolygon();
00113 
00117     inline int GetPolygonCount() const { return mPolygons.GetCount(); }
00118 
00124     inline int GetPolygonIndex(int pPolygonIndex) const
00125     {
00126         return pPolygonIndex < mPolygons.GetCount() ? mPolygons[pPolygonIndex].mIndex : -1;
00127     }
00128 
00134     inline int GetPolygonSize(int pPolygonIndex) const
00135     {
00136         return pPolygonIndex < mPolygons.GetCount() ? mPolygons[pPolygonIndex].mSize : -1;
00137     }
00138 
00144     int GetPolygonGroup(int pPolygonIndex) const;
00145 
00152     inline void SetPolygonGroup(int pPolygonIndex, int pGroup) const
00153     {
00154         if (pPolygonIndex<mPolygons.GetCount())
00155             mPolygons[pPolygonIndex].mGroup = pGroup;
00156     }
00157 
00165     inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
00166     {
00167         return pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon < mPolygons[pPolygonIndex].mSize ?
00168             mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
00169     }
00170 
00178     void GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, KFbxVector4 &pNormal) const;
00179 
00187     int* GetPolygonVertices() const;
00188 
00192     int GetPolygonVertexCount() const;
00193 
00199     int GetPolygonVertexIndex( int pPolygonIndex ) const;
00200 
00206     int RemovePolygon(int pPolygonIndex);
00207 
00209 
00220 
00227     void InitTextureUV(int pCount, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00228 
00236     void AddTextureUV(KFbxVector2 pUV, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00237 
00241     int GetTextureUVCount(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00242 
00245     int GetUVLayerCount();
00246 
00250     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetAllChannelUV(int pLayer);
00251 
00253 
00264 
00278     void InitMaterialIndices(KFbxLayerElement::EMappingMode pMappingMode);
00279 
00291     void InitTextureIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTextureType);
00292 
00308     void InitTextureUVIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00309 
00320     int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00321 
00322 
00332     void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, KFbxLayerElement::ELayerElementType pTypeIdentifier/*=KFbxLayerElement::eDIFFUSE_TEXTURES*/);
00333 
00335 
00340 
00344     void Reset();
00345 
00351     void ComputeVertexNormals(bool pCW =  false);
00352 
00357     bool CheckIfVertexNormalsCCW();
00358 
00361     typedef enum
00362     {
00363         eBY_NORMAL  
00365     } ESplitObject;
00366 
00368     class KDuplicateVertex
00369     {
00370     public:
00372         KDuplicateVertex() :
00373           lVertexPolyIndex(0),
00374           lNewVertexIndex(0),
00375           lNormal(0,0,0)
00376           {
00377           };
00378 
00379         int lVertexPolyIndex ; 
00380         int lNewVertexIndex;   
00381         KFbxVector4 lNormal;    
00382         KFbxVector2 lUV;        
00383 
00384         int lEdgeIndex;         
00385     };
00386 
00388     class KVertexNormalInfo
00389     {
00390     public:
00392         KVertexNormalInfo():
00393           mTotalNormal(0,0,0),
00394           mNumNormal(0)
00395           {
00396           };
00397 
00398           KFbxVector4 mTotalNormal; 
00399           int mNumNormal;          
00400     };
00401 
00405     bool CheckSamePointTwice();
00406 
00412     int RemoveBadPolygons();
00413 
00415 
00420 
00425     void SplitPoints(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00426 
00432     bool BuildMergeList(KArrayTemplate<int> &pMergeList,ESplitObject pObject , bool pExport = false);
00433 
00437     void MergePointsForPolygonVerteNormals(KArrayTemplate<int> &pMergeList);
00438 
00440 
00441 
00446 
00450     void BuildMeshEdgeArray();
00451 
00455     int GetMeshEdgeCount() const;
00456 
00465     int GetMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool& pReversed );
00466 
00472     int GetMeshEdgeIndexForPolygon( int pPolygon, int pPositionInPolygon );
00473 
00480     void GetMeshEdgeVertices( int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex );
00481 
00486     void BeginGetMeshEdgeVertices();
00487 
00492     void EndGetMeshEdgeVertices();
00493 
00497     void SetMeshEdgeCount( int pEdgeCount );
00498 
00503     inline void SetMeshEdge( int pEdgeIndex, int pValue )
00504     {
00505         if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue;
00506     }
00507 
00517     int AddMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00518 
00529     int SetMeshEdgeIndex( int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00530 
00534     void BeginAddMeshEdgeIndex();
00535 
00538     void EndAddMeshEdgeIndex();
00539 
00540 
00547     int AddMeshEdgeIndexForPolygon( int pPolygonIndex, int pPositionInPolygon );
00548 
00559     bool SetMeshEdgeIndex( int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon );
00560 
00561 
00563     struct KFbxComponentMap
00564     {
00565         KArrayTemplate<int> mData; 
00566         KArrayTemplate<int> mOffsets; 
00567 
00568         int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
00569         int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
00570         int GetComponentCount() { return mOffsets.GetCount() - 1; }
00571     };
00572 
00577     void ComputeComponentMaps( KFbxComponentMap& pEdgeToPolyMap, KFbxComponentMap& pPolyToEdgeMap );
00578 
00582     bool IsTriangleMesh() const;
00583 
00585 
00587 //
00588 //  WARNING!
00589 //
00590 //  Anything beyond these lines may not be documented accurately and is
00591 //  subject to change without notice.
00592 //
00594 
00595 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00596 
00597 public:
00598 
00602     inline void ReservePolygonCount( int pCount ) { mPolygons.Reserve( pCount ); }
00603 
00608     inline void ReservePolygonVertexCount( int pCount ) { mPolygonVertices.Reserve( pCount ); }
00609 
00610     // Clone
00611     virtual KFbxObject* Clone(KFbxObject* pContainer, KFbxObject::ECloneType pCloneType) const;
00612 
00613     bool GetTextureUV(KFbxLayerElementArrayTemplate<KFbxVector2>** pLockableArray, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
00614     bool GetMaterialIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray) const;
00615     bool GetTextureIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray, KFbxLayerElement::ELayerElementType pTextureType) const;
00616 
00617 
00622 
00627     double GetEdgeCreaseInfo(int pEdgeIndex);
00628 
00633     double GetVertexCreaseInfo(int pVertexIndex);
00634 
00640     bool SetEdgeCreaseInfo(int pEdgeIndex, double pWeight);
00641 
00647     bool SetVertexCreaseInfo(int pVertexIndex, double pWeight);
00648 
00650 
00655 
00662     enum MeshSmoothness
00663     {
00664         HULL,
00665         ROUGH,
00666         MEDIUM,
00667         FINE,
00668     };
00669 
00670 
00675     KFbxMesh::MeshSmoothness GetMeshSmoothness() const;
00676 
00685     void SetMeshSmoothness(KFbxMesh::MeshSmoothness pSmoothness);
00686 
00690     int GetMeshPreviewDivisionLevels() const;
00691 
00695     void SetMeshPreviewDivisionLevels(int pPreviewDivisionLevels);
00696 
00701     int GetMeshRenderDivisionLevels() const;
00702 
00706     void SetMeshRenderDivisionLevels(int pRenderDivisionLevels);
00707 
00711     bool GetDisplaySubdivisions() const;
00712 
00716     void SetDisplaySubdivisions(bool pDisplySubdivisions);
00717 
00719 
00720 protected:
00721 
00722     void InitTextureIndices(KFbxLayerElementTexture* pLayerElementTexture, KFbxLayerElement::EMappingMode pMappingMode);
00723     void RemoveTextureIndex(KFbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
00724     void RemoveUVIndex(KFbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
00725 
00726     bool IsBadPoly(int pPolygonIndex);
00727 
00728     KFbxMesh(KFbxSdkManager& pManager, char const* pName);
00729 
00730     virtual void Destruct(bool pRecursive, bool pDependents);
00731 
00733     KFbxMesh& operator= (KFbxMesh const& pMesh);
00734 
00735     virtual KString     GetTypeName() const;
00736     virtual KStringList GetTypeFlags() const;
00737 
00738     struct KFbxPolygon
00739     {
00740         int mIndex;
00741         int mSize;
00742         int mGroup;
00743     };
00744 
00745     struct KFbxSplitEdgeData
00746     {
00747         int mOriginalEdge;
00748         bool mIsNew;
00749     };
00750 
00751     //smooth mesh preview
00752     MeshSmoothness mSmoothness;
00753     int mPreviewDivisionLevels;
00754     int mRenderDivisionLevels;
00755 
00756     bool mDisplaySubdivisions;
00757 
00758     KArrayTemplate<KFbxPolygon> mPolygons;
00759 public:
00760     KArrayTemplate<int> mPolygonVertices;
00761 
00762 protected:
00763     struct KFbxPolyIndex
00764     {
00765         int mPolygonIndex;
00766         int mSubPolygonIndex;
00767     };
00768 
00769     struct KFbxV2PVMap
00770     {
00771         KFbxPolyIndex* mV2PV;
00772         int* mV2PVOffset;
00773         int* mV2PVCount;
00774         bool mValid;
00775     };
00776 
00777     KFbxV2PVMap mV2PVMap;
00778 
00779     struct KFbxEdgeLookup
00780     {
00781         KArrayTemplate<int> mPVFlags;
00782         bool mValid;
00783     };
00784 
00785     KFbxEdgeLookup mPVEndFlags;
00786 
00787 public:
00788     KArrayTemplate< int > mEdgeArray;
00789 
00790 protected:
00791     // Finds the polygon index for the given edge
00792     int FindPolygonIndex( int pEdgeIndex );
00793     static int PolygonIndexCompare( const void *p1, const void *p2 );
00794 
00795     void PolySetTexture(KFbxLayer* pLayer, int pTextureIndex,
00796                         KFbxLayerElement::ELayerElementType pTextureType);
00797 
00798     friend class KFbxGeometryConverter;
00799     friend class KFbxWriter3DS;
00800 
00801 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00802 
00803 };
00804 
00805 
00806 typedef KFbxMesh* HKFbxMesh;
00807 
00808 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00809 
00810 #endif // FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00811