FBX C++ API Reference
fbxmesh.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2017 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_SCENE_GEOMETRY_MESH_H_
14 #define _FBXSDK_SCENE_GEOMETRY_MESH_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
21 
22 #include <fbxsdk/fbxsdk_nsbegin.h>
23 
34 {
36 
37 public:
41 
53  void BeginPolygon(int pMaterial=-1, int pTexture=-1, int pGroup=-1, bool pLegacy=true);
54 
61  void BeginPolygonExt(int pMaterial, int* pTextures);
62 
67  void AddPolygon(int pIndex, int pTextureUVIndex = -1);
68 
70  void EndPolygon();
71 
74  inline int GetPolygonCount() const { return mPolygons.GetCount(); }
75 
79  inline int GetPolygonSize(int pPolygonIndex) const
80  {
81  return ( pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount() ) ? mPolygons[pPolygonIndex].mSize : -1;
82  }
83 
89  int GetPolygonGroup(int pPolygonIndex) const;
90 
96  inline void SetPolygonGroup(int pPolygonIndex, int pGroup) const
97  {
98  if( pPolygonIndex >= 0 && pPolygonIndex<mPolygons.GetCount() ) mPolygons[pPolygonIndex].mGroup = pGroup;
99  }
100 
105  inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
106  {
107  return ( pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon >= 0 && pPositionInPolygon < mPolygons[pPolygonIndex].mSize ) ?
108  mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
109  }
110 
117  bool GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, FbxVector4& pNormal) const;
118 
122  bool GetPolygonVertexNormals(FbxArray<FbxVector4>& pNormals) const;
123 
135  bool GetPolygonVertexUV(int pPolyIndex, int pVertexIndex, const char* pUVSetName, FbxVector2& pUV, bool& pUnmapped) const;
136 
148  bool GetPolygonVertexUVs(const char* pUVSetName, FbxArray<FbxVector2>& pUVs, FbxArray<int>* pUnmappedUVId = NULL) const;
149 
154  int* GetPolygonVertices() const;
155 
160  inline int GetPolygonVertexCount() const { return mPolygonVertices.Size(); }
161 
179  int GetPolygonVertexIndex(int pPolygonIndex) const;
180 
186  int RemovePolygon(int pPolygonIndex);
187 
193  int RemoveDuplicatedEdges(FbxArray<int>& pEdgeIndexList);
195 
207  void InitTextureUV(int pCount, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
208 
215  void AddTextureUV(FbxVector2 pUV, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
216 
219  int GetTextureUVCount(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
220 
223  int GetUVLayerCount() const;
224 
233  FbxArray<FbxLayerElement::EType> GetAllChannelUV(int pLayer);
235 
253  void InitMaterialIndices(FbxLayerElement::EMappingMode pMappingMode);
254 
266  void InitTextureIndices(FbxLayerElement::EMappingMode pMappingMode, FbxLayerElement::EType pTextureType);
267 
282  void InitTextureUVIndices(FbxLayerElement::EMappingMode pMappingMode, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
283 
293  int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
294 
303  void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, FbxLayerElement::EType pTypeIdentifier);
305 
310  void Reset();
311 
318  bool GenerateNormals(bool pOverwrite=false, bool pByCtrlPoint = false, bool pCW=false);
319 
323  bool CheckIfVertexNormalsCCW();
324 
327  {
328  public:
330  lVertexPolyIndex(0),
331  lNewVertexIndex(0),
332  lNormal(0, 0, 0),
333  lUV(0, 0),
334  lEdgeIndex(0)
335  {
336  }
337 
343  };
344 
347  {
348  public:
350  mTotalNormal(0, 0, 0),
351  mNumNormal(0)
352  {
353  }
354 
357  };
358 
361  bool CheckSamePointTwice() const;
362 
367  int RemoveBadPolygons();
369 
378  bool SplitPoints(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
379 
386  bool BuildMergeList(FbxArray<int>& pMergeList);
387 
390  void MergePointsForPolygonVerteNormals(FbxArray<int> &pMergeList);
392 
396  void BuildMeshEdgeArray();
397 
400  int GetMeshEdgeCount() const;
401 
409  int GetMeshEdgeIndex(int pStartVertexIndex, int pEndVertexIndex, bool& pReversed, int pExistedEdgeCount=-1);
410 
414  void BeginGetMeshEdgeIndexForPolygon();
415 
419  void EndGetMeshEdgeIndexForPolygon();
420 
427  int GetMeshEdgeIndexForPolygon(int pPolygon, int pPositionInPolygon);
428 
433  void GetMeshEdgeVertices(int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex) const;
434 
438  void BeginGetMeshEdgeVertices();
439 
443  void EndGetMeshEdgeVertices();
444 
447  void SetMeshEdgeCount(int pEdgeCount);
448 
453  inline bool SetMeshEdge(int pEdgeIndex, int pValue)
454  {
455  if (pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount())
456  {
457  FBX_ASSERT(pValue >= 0 && pValue < mPolygonVertices.GetCount());
458 
459  if (pValue < 0 || pValue >= mPolygonVertices.GetCount())
460  {
461  pValue = 0;
462  return false;
463  }
464 
465  mEdgeArray[pEdgeIndex] = pValue;
466  }
467  return true;
468  }
469 
477  int AddMeshEdgeIndex(int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates);
478 
490  int SetMeshEdgeIndex(int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates, int pExistedEdgeCount=-1);
491 
494  void BeginAddMeshEdgeIndex();
495 
497  void EndAddMeshEdgeIndex();
498 
503  int AddMeshEdgeIndexForPolygon(int pPolygonIndex, int pPositionInPolygon);
504 
514  bool SetMeshEdgeIndex(int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon);
515 
518  bool IsTriangleMesh() const;
520 
523  inline void ReservePolygonCount(int pCount) { mPolygons.Reserve(pCount); }
524 
527  inline void ReservePolygonVertexCount(int pCount) { mPolygonVertices.Reserve(pCount); }
528 
529  bool GetTextureUV(FbxLayerElementArrayTemplate<FbxVector2>** pLockableArray, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse) const;
530  bool GetMaterialIndices(FbxLayerElementArrayTemplate<int>** pLockableArray) const;
531  bool GetTextureIndices(FbxLayerElementArrayTemplate<int>** pLockableArray, FbxLayerElement::EType pTextureType) const;
532 
538  double GetEdgeCreaseInfo(int pEdgeIndex);
539 
543  bool GetEdgeCreaseInfoArray(FbxLayerElementArrayTemplate<double>** pCreaseArray);
544 
548  double GetVertexCreaseInfo(int pVertexIndex);
549 
553  bool GetVertexCreaseInfoArray(FbxLayerElementArrayTemplate<double>** pCreaseArray);
554 
559  bool SetEdgeCreaseInfo(int pEdgeIndex, double pWeight);
560 
564  bool SetEdgeCreaseInfoArray(FbxArray<double>* pWeightArray);
565 
570  bool SetVertexCreaseInfo(int pVertexIndex, double pWeight);
571 
575  bool SetVertexCreaseInfoArray(FbxArray<double>* pWeightArray);
577 
584  {
588  eFine
589  };
590 
593  {
596  eCreaseEdge
597  };
598 
602  FbxMesh::ESmoothness GetMeshSmoothness() const;
603 
607  void SetMeshSmoothness(FbxMesh::ESmoothness pSmoothness);
608 
611  int GetMeshPreviewDivisionLevels() const;
612 
615  void SetMeshPreviewDivisionLevels(int pPreviewDivisionLevels);
616 
620  int GetMeshRenderDivisionLevels() const;
621 
624  void SetMeshRenderDivisionLevels(int pRenderDivisionLevels);
625 
628  bool GetDisplaySubdivisions() const;
629 
632  void SetDisplaySubdivisions(bool pDisplySubdivisions);
633 
636  EBoundaryRule GetBoundaryRule() const;
637 
641  void SetBoundaryRule(EBoundaryRule pBoundaryRule);
642 
645  bool GetPreserveBorders() const;
646 
650  void SetPreserveBorders(bool pPreserveBorders);
651 
654  bool GetPreserveHardEdges() const;
655 
659  void SetPreserveHardEdges(bool pPreserveHardEdges);
660 
663  bool GetPropagateEdgeHardness() const;
664 
668  void SetPropagateEdgeHardness(bool pPropagateEdgeHardness);
670 
676  bool GetPolyHoleInfo(int pFaceIndex);
677 
681  bool GetPolyHoleInfoArray(FbxLayerElementArrayTemplate<bool>** pHoleArray);
682 
687  bool SetPolyHoleInfo(int pFaceIndex, bool pIsHole);
688 
692  bool SetPolyHoleInfoArray(FbxArray<bool>* pHoleArray);
694 
707  bool GenerateTangentsData(const char* pUVSetName=NULL, bool pOverwrite=false, bool pIgnoreTangentFlip = false);
708 
719  bool GenerateTangentsData(int pUVSetLayerIndex, bool pOverwrite=false, bool pIgnoreTangentFlip = false);
720 
721 
731  bool GenerateTangentsDataForAllUVSets(bool pOverwrite=false, bool pIgnoreTangentFlip=false);
733 
734 /*****************************************************************************************************************************
735 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
736 *****************************************************************************************************************************/
737 #ifndef DOXYGEN_SHOULD_SKIP_THIS
738  FbxObject& Copy(const FbxObject& pObject) override;
739  void Compact() override;
740 
741  //Please use GetPolygonVertexIndex and GetPolygonVertices to access these arrays.
742  //DO NOT MODIFY them directly, otherwise unexpected behavior will occur.
743  //These members are public only for application data copy performance reasons.
744  struct PolygonDef{ int mIndex; int mSize; int mGroup; };
745 
746  FbxArray<PolygonDef> mPolygons;
747  FbxArray<int> mPolygonVertices;
748  FbxArray<int> mEdgeArray;
749 
750  //These are only used in context of triangulation to backup original polygon layout necessary for handling mesh cache after triangulation
751  FbxArray<PolygonDef>* mOriginalPolygons;
752  FbxArray<int>* mOriginalPolygonVertices;
753  int mOriginalControlPointsCount;
754 
755  //Internal structure used to keep the mapping information between edges and polygons.
756  struct ComponentMap
757  {
758  FbxArray<int> mData; // The array to store data.
759  FbxArray<int> mOffsets; // The array to store the offsets of the data in mData.
760 
761  int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
762  int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
763  int GetComponentCount() { return mOffsets.GetCount() - 1; }
764  };
765  void ComputeComponentMaps(ComponentMap& pEdgeToPolyMap, ComponentMap& pPolyToEdgeMap);
766 
767  // Internal structure used to keep the mapping information between the control points and the
768  // vertices referencing them
769  class FBXSDK_DLL ControlPointToVerticesMap
770  {
771  public:
772  bool Valid();
773 
774  void FillWithControlPointInfo(FbxMesh* pMesh);
775  bool FillWithAdjacencyInfo(FbxMesh* pMesh, int pNbControlPoints);
776 
777  int GetCount();
778  void Clear();
779 
780  int GetCount(int pControlPoint) const;
781  int GetVertex(int pControlPoint, int pVertex) const;
782 
783  private:
784  FbxArray<int> mStartIndices;
785  FbxArray<int> mVertexIndices;
786  };
787  void ComputeControlPointToVerticesMap(ControlPointToVerticesMap& pMap);
788 
789  // this function will compare the vertex normals with the corresponding ones in pMesh and
790  // make them similar (i.e: if pMesh(NVi) == pMesh(NVj) then make this(NVi) == this(NVj))
791  bool ConformNormalsTo(const FbxMesh* pMesh);
792 
793 protected:
794  void Construct(const FbxObject* pFrom) override;
795  void Destruct(bool pRecursive) override;
796  void ContentClear() override;
797 
798  void InitTextureIndices(FbxLayerElementTexture* pLayerElementTexture, FbxLayerElement::EMappingMode pMappingMode);
799  void RemoveTextureIndex(FbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
800  void RemoveUVIndex(FbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
801 
802  bool GetBadPolyIndices(FbxArray<int>& pArrayBadPolyIndices, bool pCheckOne) const;
803 
804  struct SplitEdgeData { int mOriginalEdge; bool mIsNew; };
805 
806  ESmoothness mSmoothness;
807  int mPreviewDivisionLevels;
808  int mRenderDivisionLevels;
809 
810  bool mDisplaySubdivisions;
811  EBoundaryRule mBoundaryRule;
812  bool mPreserveBorders;
813  bool mPreserveHardEdges;
814  bool mPropagateEdgeHardness;
815 
816  struct PolygonIndexDef { int mPolygonIndex; int mSubPolygonIndex; };
817 
818  struct V2PVMap
819  {
820  struct EdgeCompare
821  {
822  inline int operator()(FbxPair<int, int> const& pKeyA, FbxPair<int, int> const& pKeyB) const
823  {
824  int lResult = pKeyA.mSecond - pKeyB.mSecond;
825  if (lResult == 0) return pKeyA.mFirst - pKeyB.mFirst;
826  else return lResult;
827  }
828  };
829 
830  PolygonIndexDef* mV2PV;
831  int* mV2PVOffset;
832  int* mV2PVCount;
833  FbxSet<FbxPair<int, int>, EdgeCompare, FbxHungryAllocator> mPVEdges;
834  bool mValid;
835 
836  //Used for fast search in GetMeshEdgeIndexForPolygon this array does not follow the same allocation as the above ones because
837  //it is not used in the normal BeginAddMeshEdgeIndex(). It is filled only by the call to BeginGetMeshEdgeIndexForPolygon().
838  FbxArray<int> mV2Edge;
839  } mV2PVMap;
840 
841  struct EdgeLookupDef { FbxArray<int> mPVFlags; bool mValid; } mPVEndFlags;
842 
843  //Finds the polygon index for the given edge
844  int FindPolygonIndex(int pEdgeIndex);
845  static int PolygonIndexCompare(const void* p1, const void* p2);
846  void PolySetTexture(FbxLayer* pLayer, int pTextureIndex, FbxLayerElement::EType pTextureType);
847  template<class T> bool GetPolygonVertexLayerElementIndex(const FbxLayerElementTemplate<T>* pLayerElement, int pPolyIndex, int pVertexIndex, int& pIndex) const;
848  template<class T> bool GetPolygonVertexLayerElementValue(const FbxLayerElementTemplate<T>* pLayerElement, int pPolyIndex, int pVertexIndex, T& pValue, bool pAllowUnmapped) const;
849 
850  friend class FbxGeometryConverter;
851 
852 private:
853  bool GenerateTangentsData(FbxLayerElementUV* pUVSet, int pLayerIndex, bool pOverwrite=false, bool pIgnoreTangentFlip = false);
854  void FillMeshEdgeTable(FbxArray<int>& pTable, int* pValue, void (*FillFct)(FbxArray<int>& pTable, int pIndex, int* pValue));
855  void ComputeNormalsPerCtrlPoint(FbxArray<VertexNormalInfo>& lNormalInfo, bool pCW=false);
856  void ComputeNormalsPerPolygonVertex(FbxArray<VertexNormalInfo>& lNormalInfo, bool pCW=false);
857  void GenerateNormalsByCtrlPoint(bool pCW);
858 
859  int GetIndex(int index, int capacity) const;
860 
861 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
862 };
863 
864 #include <fbxsdk/fbxsdk_nsend.h>
865 
866 #endif /* _FBXSDK_SCENE_GEOMETRY_MESH_H_ */
#define FBXSDK_OBJECT_DECLARE(Class, Parent)
Macro used to declare a new class derived from FbxObject.
Definition: fbxobject.h:61
FbxNodeAttribute::EType GetAttributeType() const override
Returns the node attribute type.
FBX SDK environment definition.
FbxLayer class provides a base for the layering mechanism.
Definition: fbxlayer.h:2391
virtual void Compact()
Compact the memory used by this object.
Both display cage and smooth mesh.
Definition: fbxmesh.h:587
Internal structure used to keep the duplicate vertex information.
Definition: fbxmesh.h:326
FbxLayerElementArrayTemplate provides data array manipulation of the data buffer for FbxLayerElement...
Definition: fbxlayer.h:868
#define NULL
Definition: fbxarch.h:213
virtual FbxObject & Copy(const FbxObject &pObject)
Copy an object content into this object.
int GetPolygonCount() const
Get the polygon count of this mesh.
Definition: fbxmesh.h:74
Layer element for mapping UVs to a geometry.
Definition: fbxlayer.h:1500
int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
Get a polygon vertex (i.e: an index to a control point).
Definition: fbxmesh.h:105
int lNewVertexIndex
The new index of the vertex.
Definition: fbxmesh.h:339
EType
Node attribute types.
void ReservePolygonCount(int pCount)
Reserve memory in the polygon array to hold the specified number of polygons.
Definition: fbxmesh.h:523
int mNumNormal
Number of normals added.
Definition: fbxmesh.h:356
This allocator only frees the allocated memory when it is deleted.
void ReservePolygonVertexCount(int pCount)
Reserve memory in the polygon vertex array to hold the specified number of polygon vertices...
Definition: fbxmesh.h:527
This class complements the FbxLayerElement class.
Definition: fbxlayer.h:1042
The base class of most FBX objects.
Definition: fbxobject.h:157
EMappingMode
Determines how the element is mapped to a surface.
Definition: fbxlayer.h:140
This class template holds a pair of objects.
Definition: fbxpair.h:22
Not active "smooth mesh preview".
Definition: fbxmesh.h:586
This class implements an efficient set based on value comparison, which stores values.
Definition: fbxset.h:25
EBoundaryRule
the boundary rule.
Definition: fbxmesh.h:592
FbxVector4 mTotalNormal
Sum of all the normals found.
Definition: fbxmesh.h:355
int lEdgeIndex
The edge index.
Definition: fbxmesh.h:342
int GetPolygonVertexCount() const
Gets the number of polygon vertices in the mesh.
Definition: fbxmesh.h:160
void SetPolygonGroup(int pPolygonIndex, int pGroup) const
Assign the specified polygon a group ID.
Definition: fbxmesh.h:96
Default value.
Definition: fbxmesh.h:594
FbxVector4 lNormal
The normal associated with this duplicate control point.
Definition: fbxmesh.h:340
int lVertexPolyIndex
Index in mPolygonsVertex where the vertex is found.
Definition: fbxmesh.h:338
Default value, not active "smooth mesh preview".
Definition: fbxmesh.h:585
Layer element for mapping Textures to a geometry.
Definition: fbxlayer.h:2201
EType
Layer Element type identifier.
Definition: fbxlayer.h:75
Second mSecond
The second object in the pair.
Definition: fbxpair.h:57
A four double mathematic vector class.
Definition: fbxvector4.h:25
#define FBXSDK_DLL
Definition: fbxarch.h:176
bool SetMeshEdge(int pEdgeIndex, int pValue)
Sets element in edge array to specific value.
Definition: fbxmesh.h:453
The base class of geometric objects that support control point deformations (e.g. ...
Definition: fbxgeometry.h:45
This class provides the functionality to convert geometry nodes attributes (FbxMesh, FbxNurbs and FbxPatch) and mainly focuses on the two major categories: Triangulation and conversion between NURBS and Patches surfaces.
First mFirst
The first object in the pair.
Definition: fbxpair.h:56
A two double mathematic vector class.
Definition: fbxvector2.h:23
FbxVector2 lUV
The UV associated with this duplicate control point.
Definition: fbxmesh.h:341
int GetPolygonSize(int pPolygonIndex) const
Get the number of polygon vertices in a polygon.
Definition: fbxmesh.h:79
Class for array of basic elements such as pointers and basic types.
Definition: fbxarray.h:37
Internal structure used to compute the normals on a mesh.
Definition: fbxmesh.h:346
ESmoothness
Display Smoothness.
Definition: fbxmesh.h:583
A mesh is a geometry made of polygons.
Definition: fbxmesh.h:33
Used for hard corner.
Definition: fbxmesh.h:595