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 - 2010 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 #include <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #include <fbxfilesdk/kfbxplugins/kfbxgeometry.h>
00044 
00045 #include <fbxfilesdk/kfbxmath/kfbxvector4.h>
00046 #include <fbxfilesdk/kfbxmath/kfbxvector2.h>
00047 
00048 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00049 
00050 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00051 
00052 class KFbxMesh;
00053 class KFbxSdkManager;
00054 
00065 class KFBX_DLL KFbxMesh : public KFbxGeometry
00066 {
00067     KFBXOBJECT_DECLARE(KFbxMesh,KFbxGeometry);
00068 
00069 public:
00073     virtual EAttributeType GetAttributeType() const;
00074 
00079 
00095     void BeginPolygon(int pMaterial = -1, int pTexture = -1, int pGroup = -1, bool pLegacy=true);
00096 
00107     void BeginPolygonExt(int pMaterial, int* pTextures);
00108 
00116     void AddPolygon(int pIndex, int pTextureUVIndex = -1);
00117 
00119     void EndPolygon();
00120 
00124     inline int GetPolygonCount() const { return mPolygons.GetCount(); }
00125 
00131     inline int GetPolygonSize(int pPolygonIndex) const
00132     {
00133         return (pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount()) ? mPolygons[pPolygonIndex].mSize : -1;
00134     }
00135 
00144     int GetPolygonGroup(int pPolygonIndex) const;
00145 
00153     inline void SetPolygonGroup(int pPolygonIndex, int pGroup) const
00154     {
00155         if (pPolygonIndex >= 0 && pPolygonIndex<mPolygons.GetCount())
00156             mPolygons[pPolygonIndex].mGroup = pGroup;
00157     }
00158 
00167     inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
00168     {
00169         return (pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon >= 0 && pPositionInPolygon < mPolygons[pPolygonIndex].mSize) ?
00170             mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
00171     }
00172 
00180     bool GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, KFbxVector4& pNormal) const;
00181 
00186     bool GetPolygonVertexNormals(KArrayTemplate<KFbxVector4>& pNormals) const;
00187 
00196     bool GetPolygonVertexUV(int pPolyIndex, int pVertexIndex, const char* pUVSetName, KFbxVector2& pUV) const;
00197 
00203     bool GetPolygonVertexUVs(const char* pUVSetName, KArrayTemplate<KFbxVector2>& pUVs) const;
00204 
00212     int* GetPolygonVertices() const;
00213 
00221     int GetPolygonVertexCount() const;
00222 
00242     int GetPolygonVertexIndex( int pPolygonIndex ) const;
00243 
00250     int RemovePolygon(int pPolygonIndex);
00251 
00258     int RemoveDuplicatedEdges(KArrayTemplate<int>& pEdgeIndexList);
00259 
00261 
00271 
00278     void InitTextureUV(int pCount, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00279 
00287     void AddTextureUV(KFbxVector2 pUV, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00288 
00292     int GetTextureUVCount(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00293 
00297     int GetUVLayerCount() const;
00298 
00309     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetAllChannelUV(int pLayer);
00310 
00312 
00322 
00336     void InitMaterialIndices(KFbxLayerElement::EMappingMode pMappingMode);
00337 
00350     void InitTextureIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTextureType);
00351 
00367     void InitTextureUVIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00368 
00379     int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00380 
00381 
00391     void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, KFbxLayerElement::ELayerElementType pTypeIdentifier/*=KFbxLayerElement::eDIFFUSE_TEXTURES*/);
00392 
00394 
00399 
00403     void Reset();
00404 
00410     void ComputeVertexNormals(bool pCW =  false);
00411 
00416     bool CheckIfVertexNormalsCCW();
00417 
00420     typedef enum
00421     {
00422         eBY_NORMAL  
00424     } ESplitObject;
00425 
00427     class KDuplicateVertex
00428     {
00429     public:
00431         KDuplicateVertex() :
00432           lVertexPolyIndex(0),
00433           lNewVertexIndex(0),
00434           lNormal(0,0,0)
00435           {
00436           };
00437 
00438         int lVertexPolyIndex ; 
00439         int lNewVertexIndex;   
00440         KFbxVector4 lNormal;    
00441         KFbxVector2 lUV;        
00442 
00443         int lEdgeIndex;         
00444     };
00445 
00447     class KVertexNormalInfo
00448     {
00449     public:
00451         KVertexNormalInfo():
00452           mTotalNormal(0,0,0),
00453           mNumNormal(0)
00454           {
00455           };
00456 
00457           KFbxVector4 mTotalNormal; 
00458           int mNumNormal;          
00459     };
00460 
00464     bool CheckSamePointTwice() const;
00465 
00471     int RemoveBadPolygons();
00472 
00474 
00479 
00485     bool SplitPoints(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00486 
00492     bool BuildMergeList(KArrayTemplate<int> &pMergeList,ESplitObject pObject , bool pExport = false);
00493 
00497     void MergePointsForPolygonVerteNormals(KArrayTemplate<int> &pMergeList);
00498 
00500 
00501 
00506 
00510     void BuildMeshEdgeArray();
00511 
00515     int GetMeshEdgeCount() const;
00516 
00526     int GetMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool& pReversed, int pExistedEdgeCount = -1 );
00527 
00533     int GetMeshEdgeIndexForPolygon( int pPolygon, int pPositionInPolygon );
00534 
00541     void GetMeshEdgeVertices( int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex ) const;
00542 
00547     void BeginGetMeshEdgeVertices();
00548 
00553     void EndGetMeshEdgeVertices();
00554 
00558     void SetMeshEdgeCount( int pEdgeCount );
00559 
00564     inline void SetMeshEdge( int pEdgeIndex, int pValue )
00565     {
00566         if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue;
00567     }
00568 
00578     int AddMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00579 
00592     int SetMeshEdgeIndex( int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates, int pExistedEdgeCount=-1 );
00593 
00597     void BeginAddMeshEdgeIndex();
00598 
00601     void EndAddMeshEdgeIndex();
00602 
00603 
00610     int AddMeshEdgeIndexForPolygon( int pPolygonIndex, int pPositionInPolygon );
00611 
00622     bool SetMeshEdgeIndex( int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon );
00623 
00624 
00626     struct KFbxComponentMap
00627     {
00628         KArrayTemplate<int> mData; 
00629         KArrayTemplate<int> mOffsets; 
00630 
00631         int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
00632         int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
00633         int GetComponentCount() { return mOffsets.GetCount() - 1; }
00634     };
00635 
00637     void ComputeComponentMaps( KFbxComponentMap& pEdgeToPolyMap, KFbxComponentMap& pPolyToEdgeMap );
00638 
00642     bool IsTriangleMesh() const;
00643 
00645 
00649     inline void ReservePolygonCount( int pCount ) { mPolygons.Reserve( pCount ); }
00650 
00655     inline void ReservePolygonVertexCount( int pCount ) { mPolygonVertices.Reserve( pCount ); }
00656 
00657     bool GetTextureUV(KFbxLayerElementArrayTemplate<KFbxVector2>** pLockableArray, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
00658     bool GetMaterialIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray) const;
00659     bool GetTextureIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray, KFbxLayerElement::ELayerElementType pTextureType) const;
00660 
00661 
00666 
00671     double GetEdgeCreaseInfo(int pEdgeIndex);
00672 
00677     bool GetEdgeCreaseInfoArray(KFbxLayerElementArrayTemplate<double>** pCreaseArray);
00678 
00683     double GetVertexCreaseInfo(int pVertexIndex);
00684 
00689     bool GetVertexCreaseInfoArray(KFbxLayerElementArrayTemplate<double>** pCreaseArray);
00690 
00696     bool SetEdgeCreaseInfo(int pEdgeIndex, double pWeight);
00697 
00702     bool SetEdgeCreaseInfoArray(KArrayTemplate<double>* pWeightArray);
00703 
00709     bool SetVertexCreaseInfo(int pVertexIndex, double pWeight);
00710 
00715     bool SetVertexCreaseInfoArray(KArrayTemplate<double>* pWeightArray);
00716 
00718 
00723 
00728     enum EMeshSmoothness
00729     {
00730         eHULL,          
00731         eROUGH,         
00732         eMEDIUM,        
00733         eFINE           
00734     };
00735 
00739     enum EBoundaryRule
00740     {
00741         eLEGACY,            
00742         eCREASE_ALL,        
00743         eCREASE_EDGES       
00744     };
00745 
00750     KFbxMesh::EMeshSmoothness GetMeshSmoothness() const;
00751 
00756     void SetMeshSmoothness(KFbxMesh::EMeshSmoothness pSmoothness);
00757 
00761     int GetMeshPreviewDivisionLevels() const;
00762 
00766     void SetMeshPreviewDivisionLevels(int pPreviewDivisionLevels);
00767 
00772     int GetMeshRenderDivisionLevels() const;
00773 
00777     void SetMeshRenderDivisionLevels(int pRenderDivisionLevels);
00778 
00782     bool GetDisplaySubdivisions() const;
00783 
00787     void SetDisplaySubdivisions(bool pDisplySubdivisions);
00788 
00792     EBoundaryRule GetBoundaryRule() const;
00793 
00798     void SetBoundaryRule(EBoundaryRule pBoundaryRule);
00799 
00803     bool GetPreserveBorders() const;
00804 
00809     void SetPreserveBorders(bool pPreserveBorders);
00810 
00814     bool GetPreserveHardEdges() const;
00815 
00820     void SetPreserveHardEdges(bool pPreserveHardEdges);
00821 
00825     bool GetPropagateEdgeHardness() const;
00826 
00831     void SetPropagateEdgeHardness(bool pPropagateEdgeHardness);
00832 
00834 
00839 
00844     bool GetPolyHoleInfo(int pFaceIndex);
00845 
00850     bool GetPolyHoleInfoArray(KFbxLayerElementArrayTemplate<bool>** pHoleArray);
00851 
00852 
00858     bool SetPolyHoleInfo(int pFaceIndex, bool pIsHole);
00859 
00864     bool SetPolyHoleInfoArray(KArrayTemplate<bool>* pHoleArray);
00865 
00867 
00872 private:
00873 
00874     bool GenerateTangentsData(KFbxLayerElementUV* pUVSet, int pLayerIndex);
00875 
00876     bool ComputeTangents(KFbxVector4* pPolyVetices, KFbxVector2* pUvs, int pPolySize, KArrayTemplate<KFbxVector4> &pTan1, KArrayTemplate<KFbxVector4> &pTan2);
00877 
00878 public:
00879 
00887     bool GenerateTangentsData(KString pUVSetName = "");
00888 
00895     bool GenerateTangentsData(int pUVSetLayerIndex);
00896 
00897     
00903     bool GenerateTangentsDataForAllUVSets();
00904 
00906 
00908 //
00909 //  WARNING!
00910 //
00911 //  Anything beyond these lines may not be documented accurately and is
00912 //  subject to change without notice.
00913 //
00915 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00916 
00917     virtual KFbxObject& Copy(const KFbxObject& pObject);
00918 
00919 protected:
00920     void InitTextureIndices(KFbxLayerElementTexture* pLayerElementTexture, KFbxLayerElement::EMappingMode pMappingMode);
00921     void RemoveTextureIndex(KFbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
00922     void RemoveUVIndex(KFbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
00923 
00924     K_DEPRECATED bool IsBadPoly(int pPolygonIndex) const;
00925     
00932     bool GetBadPolyIndices(KArrayTemplate<int>& pArrayBadPolyIndices, bool pCheckOne) const;
00933 
00934     KFbxMesh(KFbxSdkManager& pManager, char const* pName);
00935 
00936     virtual void Destruct(bool pRecursive, bool pDependents);
00937 
00938     struct KFbxSplitEdgeData
00939     {
00940         int mOriginalEdge;
00941         bool mIsNew;
00942     };
00943 
00944     //smooth mesh preview
00945     EMeshSmoothness mSmoothness;
00946     int mPreviewDivisionLevels;
00947     int mRenderDivisionLevels;
00948 
00949     bool mDisplaySubdivisions;
00950     EBoundaryRule mBoundaryRule;
00951     bool mPreserveBorders;
00952     bool mPreserveHardEdges;
00953     bool mPropagateEdgeHardness;
00954 
00955 public:
00956     //Please use GetPolygonVertexIndex and GetPolygonVertices to access these arrays.
00957     //DO NOT MODIFY them directly, otherwise unexpected behavior will occur.
00958     //These members are public only for application data copy performance reasons.
00959     struct KFbxPolygon{ int mIndex; int mSize; int mGroup; };
00960     KArrayTemplate<KFbxPolygon> mPolygons;
00961     KArrayTemplate<int> mPolygonVertices;
00962 
00963 protected:
00964     struct KFbxPolyIndex
00965     {
00966         int mPolygonIndex;
00967         int mSubPolygonIndex;
00968     };
00969 
00970     struct KFbxV2PVMap
00971     {
00972         KFbxPolyIndex* mV2PV;
00973         int* mV2PVOffset;
00974         int* mV2PVCount;
00975         int* mPVEdge;
00976         bool mValid;
00977     };
00978 
00979     KFbxV2PVMap mV2PVMap;
00980 
00981     struct KFbxEdgeLookup
00982     {
00983         KArrayTemplate<int> mPVFlags;
00984         bool mValid;
00985     };
00986 
00987     KFbxEdgeLookup mPVEndFlags;
00988 
00989 public:
00990     KArrayTemplate< int > mEdgeArray;
00991 
00992 protected:
00993     // Finds the polygon index for the given edge
00994     int FindPolygonIndex( int pEdgeIndex );
00995     static int PolygonIndexCompare( const void *p1, const void *p2 );
00996 
00997     void PolySetTexture(KFbxLayer* pLayer, int pTextureIndex,
00998                         KFbxLayerElement::ELayerElementType pTextureType);
00999     template<class T> bool GetPolygonVertexLayerElementValue(const KFbxLayerElementTemplate<T>* pLayerElement,
01000             int pPolyIndex, int pVertexIndex, T& pValue) const;
01001 
01002     friend class KFbxGeometryConverter;
01003     friend class KFbxWriter3DS;
01004 
01005 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01006 
01007 };
01008 
01009 
01010 typedef KFbxMesh* HKFbxMesh;
01011 
01012 #include <fbxfilesdk/fbxfilesdk_nsend.h>
01013 
01014 #endif // FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
01015