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     void GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, KFbxVector4 &pNormal) const;
00181 
00189     int* GetPolygonVertices() const;
00190 
00198     int GetPolygonVertexCount() const;
00199 
00219     int GetPolygonVertexIndex( int pPolygonIndex ) const;
00220 
00227     int RemovePolygon(int pPolygonIndex);
00228 
00230 
00240 
00247     void InitTextureUV(int pCount, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00248 
00256     void AddTextureUV(KFbxVector2 pUV, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00257 
00261     int GetTextureUVCount(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00262 
00266     int GetUVLayerCount() const;
00267 
00278     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetAllChannelUV(int pLayer);
00279 
00281 
00291 
00305     void InitMaterialIndices(KFbxLayerElement::EMappingMode pMappingMode);
00306 
00319     void InitTextureIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTextureType);
00320 
00336     void InitTextureUVIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00337 
00348     int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00349 
00350 
00360     void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, KFbxLayerElement::ELayerElementType pTypeIdentifier/*=KFbxLayerElement::eDIFFUSE_TEXTURES*/);
00361 
00363 
00368 
00372     void Reset();
00373 
00379     void ComputeVertexNormals(bool pCW =  false);
00380 
00385     bool CheckIfVertexNormalsCCW();
00386 
00389     typedef enum
00390     {
00391         eBY_NORMAL  
00393     } ESplitObject;
00394 
00396     class KDuplicateVertex
00397     {
00398     public:
00400         KDuplicateVertex() :
00401           lVertexPolyIndex(0),
00402           lNewVertexIndex(0),
00403           lNormal(0,0,0)
00404           {
00405           };
00406 
00407         int lVertexPolyIndex ; 
00408         int lNewVertexIndex;   
00409         KFbxVector4 lNormal;    
00410         KFbxVector2 lUV;        
00411 
00412         int lEdgeIndex;         
00413     };
00414 
00416     class KVertexNormalInfo
00417     {
00418     public:
00420         KVertexNormalInfo():
00421           mTotalNormal(0,0,0),
00422           mNumNormal(0)
00423           {
00424           };
00425 
00426           KFbxVector4 mTotalNormal; 
00427           int mNumNormal;          
00428     };
00429 
00433     bool CheckSamePointTwice();
00434 
00440     int RemoveBadPolygons();
00441 
00443 
00448 
00454     bool SplitPoints(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00455 
00461     bool BuildMergeList(KArrayTemplate<int> &pMergeList,ESplitObject pObject , bool pExport = false);
00462 
00466     void MergePointsForPolygonVerteNormals(KArrayTemplate<int> &pMergeList);
00467 
00469 
00470 
00475 
00479     void BuildMeshEdgeArray();
00480 
00484     int GetMeshEdgeCount() const;
00485 
00494     int GetMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool& pReversed );
00495 
00501     int GetMeshEdgeIndexForPolygon( int pPolygon, int pPositionInPolygon );
00502 
00509     void GetMeshEdgeVertices( int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex ) const;
00510 
00515     void BeginGetMeshEdgeVertices();
00516 
00521     void EndGetMeshEdgeVertices();
00522 
00526     void SetMeshEdgeCount( int pEdgeCount );
00527 
00532     inline void SetMeshEdge( int pEdgeIndex, int pValue )
00533     {
00534         if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue;
00535     }
00536 
00546     int AddMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00547 
00558     int SetMeshEdgeIndex( int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00559 
00563     void BeginAddMeshEdgeIndex();
00564 
00567     void EndAddMeshEdgeIndex();
00568 
00569 
00576     int AddMeshEdgeIndexForPolygon( int pPolygonIndex, int pPositionInPolygon );
00577 
00588     bool SetMeshEdgeIndex( int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon );
00589 
00590 
00592     struct KFbxComponentMap
00593     {
00594         KArrayTemplate<int> mData; 
00595         KArrayTemplate<int> mOffsets; 
00596 
00597         int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
00598         int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
00599         int GetComponentCount() { return mOffsets.GetCount() - 1; }
00600     };
00601 
00603     void ComputeComponentMaps( KFbxComponentMap& pEdgeToPolyMap, KFbxComponentMap& pPolyToEdgeMap );
00604 
00608     bool IsTriangleMesh() const;
00609 
00611 
00615     inline void ReservePolygonCount( int pCount ) { mPolygons.Reserve( pCount ); }
00616 
00621     inline void ReservePolygonVertexCount( int pCount ) { mPolygonVertices.Reserve( pCount ); }
00622 
00623     // Clone
00624     virtual KFbxObject* Clone(KFbxObject* pContainer, KFbxObject::ECloneType pCloneType) const;
00625 
00626     bool GetTextureUV(KFbxLayerElementArrayTemplate<KFbxVector2>** pLockableArray, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
00627     bool GetMaterialIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray) const;
00628     bool GetTextureIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray, KFbxLayerElement::ELayerElementType pTextureType) const;
00629 
00630 
00635 
00640     double GetEdgeCreaseInfo(int pEdgeIndex);
00641 
00646     bool GetEdgeCreaseInfoArray(KFbxLayerElementArrayTemplate<double>** pCreaseArray);
00647 
00652     double GetVertexCreaseInfo(int pVertexIndex);
00653 
00658     bool GetVertexCreaseInfoArray(KFbxLayerElementArrayTemplate<double>** pCreaseArray);
00659 
00665     bool SetEdgeCreaseInfo(int pEdgeIndex, double pWeight);
00666 
00671     bool SetEdgeCreaseInfoArray(KArrayTemplate<double>* pWeightArray);
00672 
00678     bool SetVertexCreaseInfo(int pVertexIndex, double pWeight);
00679 
00684     bool SetVertexCreaseInfoArray(KArrayTemplate<double>* pWeightArray);
00685 
00687 
00692 
00697     enum EMeshSmoothness
00698     {
00699         eHULL,          
00700         eROUGH,         
00701         eMEDIUM,        
00702         eFINE           
00703     };
00704 
00708     enum EBoundaryRule
00709     {
00710         eLEGACY,            
00711         eCREASE_ALL,        
00712         eCREASE_EDGES       
00713     };
00714 
00719     KFbxMesh::EMeshSmoothness GetMeshSmoothness() const;
00720 
00725     void SetMeshSmoothness(KFbxMesh::EMeshSmoothness pSmoothness);
00726 
00730     int GetMeshPreviewDivisionLevels() const;
00731 
00735     void SetMeshPreviewDivisionLevels(int pPreviewDivisionLevels);
00736 
00741     int GetMeshRenderDivisionLevels() const;
00742 
00746     void SetMeshRenderDivisionLevels(int pRenderDivisionLevels);
00747 
00751     bool GetDisplaySubdivisions() const;
00752 
00756     void SetDisplaySubdivisions(bool pDisplySubdivisions);
00757 
00761     EBoundaryRule GetBoundaryRule() const;
00762 
00767     void SetBoundaryRule(EBoundaryRule pBoundaryRule);
00768 
00772     bool GetPreserveBorders() const;
00773 
00778     void SetPreserveBorders(bool pPreserveBorders);
00779 
00783     bool GetPreserveHardEdges() const;
00784 
00789     void SetPreserveHardEdges(bool pPreserveHardEdges);
00790 
00794     bool GetPropagateEdgeHardness() const;
00795 
00800     void SetPropagateEdgeHardness(bool pPropagateEdgeHardness);
00801 
00803 
00808 
00813     bool GetPolyHoleInfo(int pFaceIndex);
00814 
00819     bool GetPolyHoleInfoArray(KFbxLayerElementArrayTemplate<bool>** pHoleArray);
00820 
00821 
00827     bool SetPolyHoleInfo(int pFaceIndex, bool pIsHole);
00828 
00833     bool SetPolyHoleInfoArray(KArrayTemplate<bool>* pHoleArray);
00834 
00836 
00838 //
00839 //  WARNING!
00840 //
00841 //  Anything beyond these lines may not be documented accurately and is
00842 //  subject to change without notice.
00843 //
00845 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00846 
00847     virtual KFbxObject& Copy(const KFbxObject& pObject);
00848 
00849 protected:
00850     void InitTextureIndices(KFbxLayerElementTexture* pLayerElementTexture, KFbxLayerElement::EMappingMode pMappingMode);
00851     void RemoveTextureIndex(KFbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
00852     void RemoveUVIndex(KFbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
00853 
00854     bool IsBadPoly(int pPolygonIndex) const;
00855 
00856     KFbxMesh(KFbxSdkManager& pManager, char const* pName);
00857 
00858     virtual void Destruct(bool pRecursive, bool pDependents);
00859 
00860     virtual KString     GetTypeName() const;
00861 
00862     struct KFbxSplitEdgeData
00863     {
00864         int mOriginalEdge;
00865         bool mIsNew;
00866     };
00867 
00868     //smooth mesh preview
00869     EMeshSmoothness mSmoothness;
00870     int mPreviewDivisionLevels;
00871     int mRenderDivisionLevels;
00872 
00873     bool mDisplaySubdivisions;
00874     EBoundaryRule mBoundaryRule;
00875     bool mPreserveBorders;
00876     bool mPreserveHardEdges;
00877     bool mPropagateEdgeHardness;
00878 
00879 public:
00880     //Please use GetPolygonVertexIndex and GetPolygonVertices to access these arrays.
00881     //DO NOT MODIFY them directly, otherwise unexpected behavior will occur.
00882     //These members are public only for application data copy performance reasons.
00883     struct KFbxPolygon{ int mIndex; int mSize; int mGroup; };
00884     KArrayTemplate<KFbxPolygon> mPolygons;
00885     KArrayTemplate<int> mPolygonVertices;
00886 
00887 protected:
00888     struct KFbxPolyIndex
00889     {
00890         int mPolygonIndex;
00891         int mSubPolygonIndex;
00892     };
00893 
00894     struct KFbxV2PVMap
00895     {
00896         KFbxPolyIndex* mV2PV;
00897         int* mV2PVOffset;
00898         int* mV2PVCount;
00899         bool mValid;
00900     };
00901 
00902     KFbxV2PVMap mV2PVMap;
00903 
00904     struct KFbxEdgeLookup
00905     {
00906         KArrayTemplate<int> mPVFlags;
00907         bool mValid;
00908     };
00909 
00910     KFbxEdgeLookup mPVEndFlags;
00911 
00912 public:
00913     KArrayTemplate< int > mEdgeArray;
00914 
00915 protected:
00916     // Finds the polygon index for the given edge
00917     int FindPolygonIndex( int pEdgeIndex );
00918     static int PolygonIndexCompare( const void *p1, const void *p2 );
00919 
00920     void PolySetTexture(KFbxLayer* pLayer, int pTextureIndex,
00921                         KFbxLayerElement::ELayerElementType pTextureType);
00922 
00923     friend class KFbxGeometryConverter;
00924     friend class KFbxWriter3DS;
00925 
00926 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00927 
00928 };
00929 
00930 
00931 typedef KFbxMesh* HKFbxMesh;
00932 
00933 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00934 
00935 #endif // FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00936