FBX SDK Reference Guide: kfbxmesh.h Source File
Go to the documentation of this file.
00001 
00004 #ifndef _FBXSDK_MESH_H_
00005 #define _FBXSDK_MESH_H_
00006 
00007 /**************************************************************************************
00008 
00009  Copyright  2001 - 2008 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 <kaydaradef.h>
00043 #ifndef KFBX_DLL
00044     #define KFBX_DLL K_DLLIMPORT
00045 #endif
00046 
00047 #include <kaydara.h>
00048 
00049 #include <kfbxplugins/kfbxgeometry.h>
00050 
00051 #include <kfbxmath/kfbxvector4.h>
00052 #include <kfbxmath/kfbxvector2.h>
00053 
00054 #include <klib/karrayul.h>
00055 
00056 #include <fbxfilesdk_nsbegin.h>
00057 
00058 class KFbxMesh;
00059 class KFbxSdkManager;
00060 
00074 class KFBX_DLL KFbxMesh : public KFbxGeometry
00075 {
00076     KFBXOBJECT_DECLARE(KFbxMesh,KFbxGeometry);
00077 
00078 public:
00082     virtual EAttributeType GetAttributeType() const;
00083 
00088 
00098     void BeginPolygon(int pMaterial = -1, int pTexture = -1, int pGroup = -1, bool pLegacy=true);
00099 
00106     void BeginPolygonExt(int pMaterial, int* pTextures);
00107 
00113     void AddPolygon(int pIndex, int pTextureUVIndex = -1);
00114 
00116     void EndPolygon();
00117 
00121     inline int GetPolygonCount() const { return mPolygons.GetCount(); }
00122 
00128     inline int GetPolygonSize(int pPolygonIndex) const
00129     {
00130         return pPolygonIndex < mPolygons.GetCount() ? mPolygons[pPolygonIndex].mSize : -1;
00131     }
00132 
00138     int GetPolygonGroup(int pPolygonIndex) const;
00139 
00147     inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
00148     {
00149         return pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon < mPolygons[pPolygonIndex].mSize ?
00150             mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
00151     }
00152 
00160     void GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, KFbxVector4 &pNormal) const;
00161 
00168     int* GetPolygonVertices() const;
00169 
00172     int GetPolygonVertexCount() const;
00173 
00179     int GetPolygonVertexIndex( int pPolygonIndex ) const;
00180 
00186     int RemovePolygon(int pPolygonIndex);
00187 
00189 
00200 
00207     void InitTextureUV(int pCount, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00208 
00216     void AddTextureUV(KFbxVector2 pUV, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00217 
00221     int GetTextureUVCount(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00222 
00225     int GetUVLayerCount();
00226 
00230     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetAllChannelUV(int pLayer);
00231 
00233 
00244 
00258     void InitMaterialIndices(KFbxLayerElement::EMappingMode pMappingMode);
00259 
00271     void InitTextureIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTextureType);
00272 
00288     void InitTextureUVIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00289 
00300     int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00301 
00302 
00312     void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, KFbxLayerElement::ELayerElementType pTypeIdentifier/*=KFbxLayerElement::eDIFFUSE_TEXTURES*/);
00313 
00315 
00320 
00324     void Reset();
00325 
00331     void ComputeVertexNormals(bool pCW =  false);
00332 
00337     bool CheckIfVertexNormalsCCW();
00338 
00341     typedef enum
00342     {
00343         eBY_NORMAL  
00345     } ESplitObject;
00346 
00348     class KDuplicateVertex
00349     {
00350     public:
00351         KDuplicateVertex() :
00352           lVertexPolyIndex(0),
00353           lNewVertexIndex(0),
00354           lNormal(0,0,0)
00355           {
00356           };
00357 
00358         int lVertexPolyIndex ; 
00359         int lNewVertexIndex;   
00360         KFbxVector4 lNormal;    
00361         KFbxVector2 lUV;        
00362 
00363         int lEdgeIndex;         
00364     };
00365 
00367     class KVertexNormalInfo
00368     {
00369     public:
00370         KVertexNormalInfo():
00371           mTotalNormal(0,0,0),
00372           mNumNormal(0)
00373           {
00374           };
00375 
00376           KFbxVector4 mTotalNormal; 
00377           int mNumNormal;          
00378     };
00379 
00380     typedef KArrayTemplate< KDuplicateVertex > KArrayOfDuplicateVertex;
00381 
00385     bool CheckSamePointTwice();
00386 
00392     int RemoveBadPolygons();
00393 
00395 
00400 
00406     void BuildSplitList(KArrayTemplate<KArrayOfDuplicateVertex* >&pSplitList, ESplitObject pObject);
00407 
00412     void SplitPointsForHardEdge(KArrayTemplate<KArrayOfDuplicateVertex* > &pSplitList, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00413 
00419     bool BuildMergeList(KArrayTemplate<int> &pMergeList,ESplitObject pObject , bool pExport = false);
00420 
00424     void MergePointsForPolygonVerteNormals(KArrayTemplate<int> &pMergeList);
00425 
00427 
00428 
00433 
00437     void BuildMeshEdgeArray();
00438 
00442     int GetMeshEdgeCount() const;
00443 
00452     int GetMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool& pReversed );
00453 
00454     int GetMeshEdgeIndexForPolygon( int pPolygon, int pPositionInPolygon );
00455 
00462     void GetMeshEdgeVertices( int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex );
00463 
00468     void BeginGetMeshEdgeVertices();
00469 
00470     void EndGetMeshEdgeVertices();
00471 
00475     void SetMeshEdgeCount( int pEdgeCount );
00476 
00481     inline void SetMeshEdge( int pEdgeIndex, int pValue )
00482     {
00483         if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue;
00484     }
00485 
00495     int AddMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00496 
00497     int SetMeshEdgeIndex( int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00498 
00502     void BeginAddMeshEdgeIndex();
00503 
00506     void EndAddMeshEdgeIndex();
00507 
00508 
00515     int AddMeshEdgeIndexForPolygon( int pPolygonIndex, int pPositionInPolygon );
00516 
00527     bool SetMeshEdgeIndex( int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon );
00528 
00529 
00530     struct KFbxComponentMap
00531     {
00532         KArrayTemplate<int> mData;
00533         KArrayTemplate<int> mOffsets;
00534 
00535         int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
00536         int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
00537         int GetComponentCount() { return mOffsets.GetCount() - 1; }
00538     };
00539 
00540     void ComputeComponentMaps( KFbxComponentMap& pEdgeToPolyMap, KFbxComponentMap& pPolyToEdgeMap );
00541 
00545     bool IsTriangleMesh() const;
00546 
00548 
00550 //
00551 //  WARNING!
00552 //
00553 //  Anything beyond these lines may not be documented accurately and is
00554 //  subject to change without notice.
00555 //
00557 
00558 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00559 
00560 public:
00561 
00565     inline void ReservePolygonCount( int pCount ) { mPolygons.Reserve( pCount ); }
00566 
00571     inline void ReservePolygonVertexCount( int pCount ) { mPolygonVertices.Reserve( pCount ); }
00572 
00573     // Clone
00574     virtual KFbxObject* Clone(KFbxObject* pContainer, KFbxObject::ECloneType pCloneType) const;
00575 
00576     bool GetTextureUV(KFbxLayerElementArrayTemplate<KFbxVector2>** pLockableArray, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
00577     bool GetMaterialIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray) const;
00578     bool GetTextureIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray, KFbxLayerElement::ELayerElementType pTextureType) const;
00579 
00580 protected:
00581 
00582     void InitTextureIndices(KFbxLayerElementTexture* pLayerElementTexture, KFbxLayerElement::EMappingMode pMappingMode);
00583     void RemoveTextureIndex(KFbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
00584     void RemoveUVIndex(KFbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
00585 
00586     bool IsBadPoly(int pPolygonIndex);
00587 
00588     KFbxMesh(KFbxSdkManager& pManager, char const* pName);
00589     ~KFbxMesh();
00590 
00591     virtual void Destruct(bool pRecursive, bool pDependents);
00592 
00594     KFbxMesh& operator= (KFbxMesh const& pMesh);
00595 
00596     virtual KString     GetTypeName() const;
00597     virtual KStringList GetTypeFlags() const;
00598 
00599     int    mUCount, mVCount;
00600     int    mUCountExtent, mVCountExtent;
00601     int    mUStep, mVStep;
00602     bool    mUClosed, mVClosed;
00603     bool    mUCapped, mVCapped;
00604 
00605     struct KFbxPolygon
00606     {
00607         int mIndex;
00608         int mSize;
00609         int mGroup;
00610     };
00611 
00612     struct KFbxSplitEdgeData
00613     {
00614         int mOriginalEdge;
00615         bool mIsNew;
00616     };
00617 
00618     KArrayTemplate<KFbxPolygon> mPolygons;
00619     KArrayTemplate<int> mPolygonVertices;
00620 
00621     struct KFbxPolyIndex
00622     {
00623         int mPolygonIndex;
00624         int mSubPolygonIndex;
00625     };
00626 
00627     struct KFbxV2PVMap
00628     {
00629         KFbxPolyIndex* mV2PV;
00630         int* mV2PVOffset;
00631         int* mV2PVCount;
00632         bool mValid;
00633     };
00634 
00635     KFbxV2PVMap mV2PVMap;
00636 
00637     struct KFbxEdgeLookup
00638     {
00639         KArrayTemplate<int> mPVFlags;
00640         bool mValid;
00641     };
00642 
00643     KFbxEdgeLookup mPVEndFlags;
00644 
00645 protected:
00646     KArrayTemplate< int > mEdgeArray;
00647 
00648     // finds the poly index for the given edge
00649     int FindPolygonIndex( int pEdgeIndex );
00650 
00651     void PolySetTexture(KFbxLayer* pLayer, int pTextureIndex,
00652                         KFbxLayerElement::ELayerElementType pTextureType);
00653 
00654     friend class KFbxReaderFbx;
00655     friend class KFbxReaderFbx6;
00656     friend class KFbxWriterFbx;
00657     friend class KFbxWriterFbx6;
00658     friend struct KFbxWriterFbx7Impl;
00659     friend class KFbxGeometryConverter;
00660     friend class KFbxWriter3DS;
00661 
00662 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00663 
00664 };
00665 
00666 
00667 typedef KFbxMesh* HKFbxMesh;
00668 
00669 #include <fbxfilesdk_nsend.h>
00670 
00671 #endif // #ifndef _FBXSDK_MESH_H_
00672 
00673