00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013 #ifndef _FBXSDK_SCENE_GEOMETRY_MESH_H_
00014 #define _FBXSDK_SCENE_GEOMETRY_MESH_H_
00015
00016 #include <fbxsdk/fbxsdk_def.h>
00017
00018 #include <fbxsdk/scene/geometry/fbxgeometry.h>
00019
00020 #include <fbxsdk/core/math/fbxvector4.h>
00021 #include <fbxsdk/core/math/fbxvector2.h>
00022
00023 #include <fbxsdk/core/base/fbxarray.h>
00024
00025 #include <fbxsdk/fbxsdk_nsbegin.h>
00026
00027 class FbxMesh;
00028 class FbxManager;
00029
00040 class FBXSDK_DLL FbxMesh : public FbxGeometry
00041 {
00042 FBXSDK_OBJECT_DECLARE(FbxMesh,FbxGeometry);
00043
00044 public:
00048 virtual FbxNodeAttribute::EType GetAttributeType() const;
00049
00054
00070 void BeginPolygon(int pMaterial = -1, int pTexture = -1, int pGroup = -1, bool pLegacy=true);
00071
00082 void BeginPolygonExt(int pMaterial, int* pTextures);
00083
00091 void AddPolygon(int pIndex, int pTextureUVIndex = -1);
00092
00094 void EndPolygon();
00095
00099 inline int GetPolygonCount() const { return mPolygons.GetCount(); }
00100
00106 inline int GetPolygonSize(int pPolygonIndex) const
00107 {
00108 return (pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount()) ? mPolygons[pPolygonIndex].mSize : -1;
00109 }
00110
00119 int GetPolygonGroup(int pPolygonIndex) const;
00120
00128 inline void SetPolygonGroup(int pPolygonIndex, int pGroup) const
00129 {
00130 if (pPolygonIndex >= 0 && pPolygonIndex<mPolygons.GetCount())
00131 mPolygons[pPolygonIndex].mGroup = pGroup;
00132 }
00133
00142 inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
00143 {
00144 return (pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon >= 0 && pPositionInPolygon < mPolygons[pPolygonIndex].mSize) ?
00145 mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
00146 }
00147
00155 bool GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, FbxVector4& pNormal) const;
00156
00161 bool GetPolygonVertexNormals(FbxArray<FbxVector4>& pNormals) const;
00162
00171 bool GetPolygonVertexUV(int pPolyIndex, int pVertexIndex, const char* pUVSetName, FbxVector2& pUV) const;
00172
00178 bool GetPolygonVertexUVs(const char* pUVSetName, FbxArray<FbxVector2>& pUVs) const;
00179
00187 int* GetPolygonVertices() const;
00188
00196 int GetPolygonVertexCount() const;
00197
00217 int GetPolygonVertexIndex( int pPolygonIndex ) const;
00218
00225 int RemovePolygon(int pPolygonIndex);
00226
00233 int RemoveDuplicatedEdges(FbxArray<int>& pEdgeIndexList);
00234
00236
00246
00253 void InitTextureUV(int pCount, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
00254
00262 void AddTextureUV(FbxVector2 pUV, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
00263
00267 int GetTextureUVCount(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
00268
00272 int GetUVLayerCount() const;
00273
00284 FbxArray<FbxLayerElement::EType> GetAllChannelUV(int pLayer);
00285
00287
00297
00311 void InitMaterialIndices(FbxLayerElement::EMappingMode pMappingMode);
00312
00325 void InitTextureIndices(FbxLayerElement::EMappingMode pMappingMode, FbxLayerElement::EType pTextureType);
00326
00342 void InitTextureUVIndices(FbxLayerElement::EMappingMode pMappingMode, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
00343
00354 int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
00355
00356
00366 void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, FbxLayerElement::EType pTypeIdentifier);
00367
00369
00374
00378 void Reset();
00379
00385 void ComputeVertexNormals(bool pCW = false);
00386
00391 bool CheckIfVertexNormalsCCW();
00392
00394 class DuplicateVertex
00395 {
00396 public:
00398 DuplicateVertex() :
00399 lVertexPolyIndex(0),
00400 lNewVertexIndex(0),
00401 lNormal(0,0,0)
00402 {
00403 };
00404
00405 int lVertexPolyIndex ;
00406 int lNewVertexIndex;
00407 FbxVector4 lNormal;
00408 FbxVector2 lUV;
00409
00410 int lEdgeIndex;
00411 };
00412
00414 class VertexNormalInfo
00415 {
00416 public:
00418 VertexNormalInfo():
00419 mTotalNormal(0,0,0),
00420 mNumNormal(0)
00421 {
00422 };
00423
00424 FbxVector4 mTotalNormal;
00425 int mNumNormal;
00426 };
00427
00431 bool CheckSamePointTwice() const;
00432
00438 int RemoveBadPolygons();
00439
00441
00446
00452 bool SplitPoints(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
00453
00458 bool BuildMergeList(FbxArray<int>& pMergeList, bool pExport=false);
00459
00463 void MergePointsForPolygonVerteNormals(FbxArray<int> &pMergeList);
00464
00466
00467
00472
00476 void BuildMeshEdgeArray();
00477
00481 int GetMeshEdgeCount() const;
00482
00492 int GetMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool& pReversed, int pExistedEdgeCount = -1 );
00493
00499 int GetMeshEdgeIndexForPolygon( int pPolygon, int pPositionInPolygon );
00500
00507 void GetMeshEdgeVertices( int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex ) const;
00508
00513 void BeginGetMeshEdgeVertices();
00514
00519 void EndGetMeshEdgeVertices();
00520
00524 void SetMeshEdgeCount( int pEdgeCount );
00525
00530 inline void SetMeshEdge( int pEdgeIndex, int pValue )
00531 {
00532 if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue;
00533 }
00534
00544 int AddMeshEdgeIndex( int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates );
00545
00558 int SetMeshEdgeIndex( int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates, int pExistedEdgeCount=-1 );
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 ComponentMap
00593 {
00594 FbxArray<int> mData;
00595 FbxArray<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( ComponentMap& pEdgeToPolyMap, ComponentMap& 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 bool GetTextureUV(FbxLayerElementArrayTemplate<FbxVector2>** pLockableArray, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse) const;
00624 bool GetMaterialIndices(FbxLayerElementArrayTemplate<int>** pLockableArray) const;
00625 bool GetTextureIndices(FbxLayerElementArrayTemplate<int>** pLockableArray, FbxLayerElement::EType pTextureType) const;
00626
00627
00632
00637 double GetEdgeCreaseInfo(int pEdgeIndex);
00638
00643 bool GetEdgeCreaseInfoArray(FbxLayerElementArrayTemplate<double>** pCreaseArray);
00644
00649 double GetVertexCreaseInfo(int pVertexIndex);
00650
00655 bool GetVertexCreaseInfoArray(FbxLayerElementArrayTemplate<double>** pCreaseArray);
00656
00662 bool SetEdgeCreaseInfo(int pEdgeIndex, double pWeight);
00663
00668 bool SetEdgeCreaseInfoArray(FbxArray<double>* pWeightArray);
00669
00675 bool SetVertexCreaseInfo(int pVertexIndex, double pWeight);
00676
00681 bool SetVertexCreaseInfoArray(FbxArray<double>* pWeightArray);
00682
00684
00689
00694 enum ESmoothness
00695 {
00696 eHull,
00697 eRough,
00698 eMedium,
00699 eFine
00700 };
00701
00705 enum EBoundaryRule
00706 {
00707 eLegacy,
00708 eCreaseAll,
00709 eCreaseEdge
00710 };
00711
00716 FbxMesh::ESmoothness GetMeshSmoothness() const;
00717
00722 void SetMeshSmoothness(FbxMesh::ESmoothness pSmoothness);
00723
00727 int GetMeshPreviewDivisionLevels() const;
00728
00732 void SetMeshPreviewDivisionLevels(int pPreviewDivisionLevels);
00733
00738 int GetMeshRenderDivisionLevels() const;
00739
00743 void SetMeshRenderDivisionLevels(int pRenderDivisionLevels);
00744
00748 bool GetDisplaySubdivisions() const;
00749
00753 void SetDisplaySubdivisions(bool pDisplySubdivisions);
00754
00758 EBoundaryRule GetBoundaryRule() const;
00759
00764 void SetBoundaryRule(EBoundaryRule pBoundaryRule);
00765
00769 bool GetPreserveBorders() const;
00770
00775 void SetPreserveBorders(bool pPreserveBorders);
00776
00780 bool GetPreserveHardEdges() const;
00781
00786 void SetPreserveHardEdges(bool pPreserveHardEdges);
00787
00791 bool GetPropagateEdgeHardness() const;
00792
00797 void SetPropagateEdgeHardness(bool pPropagateEdgeHardness);
00798
00800
00805
00810 bool GetPolyHoleInfo(int pFaceIndex);
00811
00816 bool GetPolyHoleInfoArray(FbxLayerElementArrayTemplate<bool>** pHoleArray);
00817
00818
00824 bool SetPolyHoleInfo(int pFaceIndex, bool pIsHole);
00825
00830 bool SetPolyHoleInfoArray(FbxArray<bool>* pHoleArray);
00831
00833
00838 private:
00839
00840 bool GenerateTangentsData(FbxLayerElementUV* pUVSet, int pLayerIndex, bool pOverwrite = false);
00841
00842 bool ComputeTangents(FbxVector4* pPolyVetices, FbxVector2* pUvs, int pPolySize, FbxArray<FbxVector4> &pTan1, FbxArray<FbxVector4> &pTan2);
00843
00844 public:
00845
00855 bool GenerateTangentsData(FbxString pUVSetName = "", bool pOverwrite = false);
00856
00865 bool GenerateTangentsData(int pUVSetLayerIndex, bool pOverwrite = false);
00866
00867
00875 bool GenerateTangentsDataForAllUVSets(bool pOverwrite = false);
00876
00878
00880
00881
00882
00883
00884
00885
00887 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00888
00889 virtual FbxObject& Copy(const FbxObject& pObject);
00890
00891 protected:
00892 void InitTextureIndices(FbxLayerElementTexture* pLayerElementTexture, FbxLayerElement::EMappingMode pMappingMode);
00893 void RemoveTextureIndex(FbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
00894 void RemoveUVIndex(FbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
00895
00902 bool GetBadPolyIndices(FbxArray<int>& pArrayBadPolyIndices, bool pCheckOne) const;
00903
00904 FbxMesh(FbxManager& pManager, char const* pName);
00905
00906 virtual void Destruct(bool pRecursive, bool pDependents);
00907
00908 struct SplitEdgeData
00909 {
00910 int mOriginalEdge;
00911 bool mIsNew;
00912 };
00913
00914
00915 ESmoothness mSmoothness;
00916 int mPreviewDivisionLevels;
00917 int mRenderDivisionLevels;
00918
00919 bool mDisplaySubdivisions;
00920 EBoundaryRule mBoundaryRule;
00921 bool mPreserveBorders;
00922 bool mPreserveHardEdges;
00923 bool mPropagateEdgeHardness;
00924
00925 public:
00926
00927
00928
00929 struct PolygonDef{ int mIndex; int mSize; int mGroup; };
00930 FbxArray<PolygonDef> mPolygons;
00931 FbxArray<int> mPolygonVertices;
00932
00933 protected:
00934 struct PolygonIndexDef
00935 {
00936 int mPolygonIndex;
00937 int mSubPolygonIndex;
00938 };
00939
00940 struct V2PVMap
00941 {
00942 PolygonIndexDef* mV2PV;
00943 int* mV2PVOffset;
00944 int* mV2PVCount;
00945 int* mPVEdge;
00946 bool mValid;
00947 };
00948
00949 V2PVMap mV2PVMap;
00950
00951 struct EdgeLookupDef
00952 {
00953 FbxArray<int> mPVFlags;
00954 bool mValid;
00955 };
00956
00957 EdgeLookupDef mPVEndFlags;
00958
00959 public:
00960 FbxArray< int > mEdgeArray;
00961
00962 protected:
00963
00964 int FindPolygonIndex( int pEdgeIndex );
00965 static int PolygonIndexCompare( const void *p1, const void *p2 );
00966
00967 void PolySetTexture(FbxLayer* pLayer, int pTextureIndex,
00968 FbxLayerElement::EType pTextureType);
00969 template<class T> bool GetPolygonVertexLayerElementValue(const FbxLayerElementTemplate<T>* pLayerElement,
00970 int pPolyIndex, int pVertexIndex, T& pValue) const;
00971
00972 friend class FbxGeometryConverter;
00973 friend class FbxWriter3ds;
00974
00975 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00976
00977 };
00978
00979 #include <fbxsdk/fbxsdk_nsend.h>
00980
00981 #endif