00001
00004 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00005 #define FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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 GetPolygonSize(int pPolygonIndex) const
00125 {
00126 return pPolygonIndex < mPolygons.GetCount() ? mPolygons[pPolygonIndex].mSize : -1;
00127 }
00128
00134 int GetPolygonGroup(int pPolygonIndex) const;
00135
00143 inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
00144 {
00145 return pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon < mPolygons[pPolygonIndex].mSize ?
00146 mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
00147 }
00148
00156 void GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, KFbxVector4 &pNormal) const;
00157
00164 int* GetPolygonVertices() const;
00165
00168 int GetPolygonVertexCount() const;
00169
00175 int GetPolygonVertexIndex( int pPolygonIndex ) const;
00176
00182 int RemovePolygon(int pPolygonIndex);
00183
00185
00196
00203 void InitTextureUV(int pCount, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00204
00212 void AddTextureUV(KFbxVector2 pUV, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00213
00217 int GetTextureUVCount(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00218
00221 int GetUVLayerCount();
00222
00226 KArrayTemplate<KFbxLayerElement::ELayerElementType> GetAllChannelUV(int pLayer);
00227
00229
00240
00254 void InitMaterialIndices(KFbxLayerElement::EMappingMode pMappingMode);
00255
00267 void InitTextureIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTextureType);
00268
00284 void InitTextureUVIndices(KFbxLayerElement::EMappingMode pMappingMode, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00285
00296 int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00297
00298
00308 void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, KFbxLayerElement::ELayerElementType pTypeIdentifier);
00309
00311
00316
00320 void Reset();
00321
00327 void ComputeVertexNormals(bool pCW = false);
00328
00333 bool CheckIfVertexNormalsCCW();
00334
00337 typedef enum
00338 {
00339 eBY_NORMAL
00341 } ESplitObject;
00342
00344 class KDuplicateVertex
00345 {
00346 public:
00347 KDuplicateVertex() :
00348 lVertexPolyIndex(0),
00349 lNewVertexIndex(0),
00350 lNormal(0,0,0)
00351 {
00352 };
00353
00354 int lVertexPolyIndex ;
00355 int lNewVertexIndex;
00356 KFbxVector4 lNormal;
00357 KFbxVector2 lUV;
00358
00359 int lEdgeIndex;
00360 };
00361
00363 class KVertexNormalInfo
00364 {
00365 public:
00366 KVertexNormalInfo():
00367 mTotalNormal(0,0,0),
00368 mNumNormal(0)
00369 {
00370 };
00371
00372 KFbxVector4 mTotalNormal;
00373 int mNumNormal;
00374 };
00375
00376 typedef KArrayTemplate< KDuplicateVertex > KArrayOfDuplicateVertex;
00377
00381 bool CheckSamePointTwice();
00382
00388 int RemoveBadPolygons();
00389
00391
00396
00402 void BuildSplitList(KArrayTemplate<KArrayOfDuplicateVertex* >&pSplitList, ESplitObject pObject);
00403
00408 void SplitPointsForHardEdge(KArrayTemplate<KArrayOfDuplicateVertex* > &pSplitList, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
00409
00415 bool BuildMergeList(KArrayTemplate<int> &pMergeList,ESplitObject pObject , bool pExport = false);
00416
00420 void MergePointsForPolygonVerteNormals(KArrayTemplate<int> &pMergeList);
00421
00423
00424
00429
00433 void BuildMeshEdgeArray();
00434
00438 int GetMeshEdgeCount() const;
00439
00448 int GetMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool& pReversed );
00449
00455 int GetMeshEdgeIndexForPolygon( int pPolygon, int pPositionInPolygon );
00456
00463 void GetMeshEdgeVertices( int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex );
00464
00469 void BeginGetMeshEdgeVertices();
00470
00471 void EndGetMeshEdgeVertices();
00472
00476 void SetMeshEdgeCount( int pEdgeCount );
00477
00482 inline void SetMeshEdge( int pEdgeIndex, int pValue )
00483 {
00484 if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue;
00485 }
00486
00496 int AddMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00497
00508 int SetMeshEdgeIndex( int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00509
00513 void BeginAddMeshEdgeIndex();
00514
00517 void EndAddMeshEdgeIndex();
00518
00519
00526 int AddMeshEdgeIndexForPolygon( int pPolygonIndex, int pPositionInPolygon );
00527
00538 bool SetMeshEdgeIndex( int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon );
00539
00540
00541 struct KFbxComponentMap
00542 {
00543 KArrayTemplate<int> mData;
00544 KArrayTemplate<int> mOffsets;
00545
00546 int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
00547 int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
00548 int GetComponentCount() { return mOffsets.GetCount() - 1; }
00549 };
00550
00555 void ComputeComponentMaps( KFbxComponentMap& pEdgeToPolyMap, KFbxComponentMap& pPolyToEdgeMap );
00556
00560 bool IsTriangleMesh() const;
00561
00563
00565
00566
00567
00568
00569
00570
00572
00573 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00574
00575 public:
00576
00580 inline void ReservePolygonCount( int pCount ) { mPolygons.Reserve( pCount ); }
00581
00586 inline void ReservePolygonVertexCount( int pCount ) { mPolygonVertices.Reserve( pCount ); }
00587
00588
00589 virtual KFbxObject* Clone(KFbxObject* pContainer, KFbxObject::ECloneType pCloneType) const;
00590
00591 bool GetTextureUV(KFbxLayerElementArrayTemplate<KFbxVector2>** pLockableArray, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
00592 bool GetMaterialIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray) const;
00593 bool GetTextureIndices(KFbxLayerElementArrayTemplate<int>** pLockableArray, KFbxLayerElement::ELayerElementType pTextureType) const;
00594
00595 protected:
00596
00597 void InitTextureIndices(KFbxLayerElementTexture* pLayerElementTexture, KFbxLayerElement::EMappingMode pMappingMode);
00598 void RemoveTextureIndex(KFbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
00599 void RemoveUVIndex(KFbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
00600
00601 bool IsBadPoly(int pPolygonIndex);
00602
00603 KFbxMesh(KFbxSdkManager& pManager, char const* pName);
00604 ~KFbxMesh();
00605
00606 virtual void Destruct(bool pRecursive, bool pDependents);
00607
00609 KFbxMesh& operator= (KFbxMesh const& pMesh);
00610
00611 virtual KString GetTypeName() const;
00612 virtual KStringList GetTypeFlags() const;
00613
00614 struct KFbxPolygon
00615 {
00616 int mIndex;
00617 int mSize;
00618 int mGroup;
00619 };
00620
00621 struct KFbxSplitEdgeData
00622 {
00623 int mOriginalEdge;
00624 bool mIsNew;
00625 };
00626
00627 public:
00628 KArrayTemplate<KFbxPolygon> mPolygons;
00629 KArrayTemplate<int> mPolygonVertices;
00630
00631 protected:
00632 struct KFbxPolyIndex
00633 {
00634 int mPolygonIndex;
00635 int mSubPolygonIndex;
00636 };
00637
00638 struct KFbxV2PVMap
00639 {
00640 KFbxPolyIndex* mV2PV;
00641 int* mV2PVOffset;
00642 int* mV2PVCount;
00643 bool mValid;
00644 };
00645
00646 KFbxV2PVMap mV2PVMap;
00647
00648 struct KFbxEdgeLookup
00649 {
00650 KArrayTemplate<int> mPVFlags;
00651 bool mValid;
00652 };
00653
00654 KFbxEdgeLookup mPVEndFlags;
00655
00656 public:
00657 KArrayTemplate< int > mEdgeArray;
00658
00659 protected:
00660
00661 int FindPolygonIndex( int pEdgeIndex );
00662
00663 void PolySetTexture(KFbxLayer* pLayer, int pTextureIndex,
00664 KFbxLayerElement::ELayerElementType pTextureType);
00665
00666 friend class KFbxGeometryConverter;
00667 friend class KFbxWriter3DS;
00668
00669 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00670
00671 };
00672
00673
00674 typedef KFbxMesh* HKFbxMesh;
00675
00676 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00677
00678 #endif // FBXFILESDK_KFBXPLUGINS_KFBXMESH_H
00679