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 
20 
21 #include <fbxsdk/fbxsdk_nsbegin.h>
22 
33 {
35 
36 public:
40 
52  void BeginPolygon(int pMaterial=-1, int pTexture=-1, int pGroup=-1, bool pLegacy=true);
53 
60  void BeginPolygonExt(int pMaterial, int* pTextures);
61 
66  void AddPolygon(int pIndex, int pTextureUVIndex = -1);
67 
69  void EndPolygon();
70 
73  inline int GetPolygonCount() const { return mPolygons.GetCount(); }
74 
78  inline int GetPolygonSize(int pPolygonIndex) const
79  {
80  return ( pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount() ) ? mPolygons[pPolygonIndex].mSize : -1;
81  }
82 
88  int GetPolygonGroup(int pPolygonIndex) const;
89 
95  inline void SetPolygonGroup(int pPolygonIndex, int pGroup) const
96  {
97  if( pPolygonIndex >= 0 && pPolygonIndex<mPolygons.GetCount() ) mPolygons[pPolygonIndex].mGroup = pGroup;
98  }
99 
104  inline int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
105  {
106  return ( pPolygonIndex >= 0 && pPolygonIndex < mPolygons.GetCount() && pPositionInPolygon >= 0 && pPositionInPolygon < mPolygons[pPolygonIndex].mSize ) ?
107  mPolygonVertices[mPolygons[pPolygonIndex].mIndex + pPositionInPolygon] : -1;
108  }
109 
116  bool GetPolygonVertexNormal(int pPolyIndex, int pVertexIndex, FbxVector4& pNormal) const;
117 
121  bool GetPolygonVertexNormals(FbxArray<FbxVector4>& pNormals) const;
122 
134  bool GetPolygonVertexUV(int pPolyIndex, int pVertexIndex, const char* pUVSetName, FbxVector2& pUV, bool& pUnmapped) const;
135 
147  bool GetPolygonVertexUVs(const char* pUVSetName, FbxArray<FbxVector2>& pUVs, FbxArray<int>* pUnmappedUVId = NULL) const;
148 
153  int* GetPolygonVertices() const;
154 
159  inline int GetPolygonVertexCount() const { return mPolygonVertices.Size(); }
160 
178  int GetPolygonVertexIndex(int pPolygonIndex) const;
179 
185  int RemovePolygon(int pPolygonIndex);
186 
192  int RemoveDuplicatedEdges(FbxArray<int>& pEdgeIndexList);
194 
206  void InitTextureUV(int pCount, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
207 
214  void AddTextureUV(FbxVector2 pUV, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
215 
218  int GetTextureUVCount(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
219 
222  int GetUVLayerCount() const;
223 
232  FbxArray<FbxLayerElement::EType> GetAllChannelUV(int pLayer);
234 
252  void InitMaterialIndices(FbxLayerElement::EMappingMode pMappingMode);
253 
265  void InitTextureIndices(FbxLayerElement::EMappingMode pMappingMode, FbxLayerElement::EType pTextureType);
266 
281  void InitTextureUVIndices(FbxLayerElement::EMappingMode pMappingMode, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
282 
292  int GetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
293 
302  void SetTextureUVIndex(int pPolygonIndex, int pPositionInPolygon, int pIndex, FbxLayerElement::EType pTypeIdentifier);
304 
309  void Reset();
310 
317  bool GenerateNormals(bool pOverwrite=false, bool pByCtrlPoint = false, bool pCW=false);
318 
322  bool CheckIfVertexNormalsCCW();
323 
326  {
327  public:
329  lVertexPolyIndex(0),
330  lNewVertexIndex(0),
331  lNormal(0, 0, 0),
332  lUV(0, 0),
333  lEdgeIndex(0)
334  {
335  }
336 
342  };
343 
346  {
347  public:
349  mTotalNormal(0, 0, 0),
350  mNumNormal(0)
351  {
352  }
353 
356  };
357 
360  bool CheckSamePointTwice() const;
361 
366  int RemoveBadPolygons();
368 
375  bool SplitPoints(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
376 
380  bool BuildMergeList(FbxArray<int>& pMergeList, bool pExport=false);
381 
384  void MergePointsForPolygonVerteNormals(FbxArray<int> &pMergeList);
386 
390  void BuildMeshEdgeArray();
391 
394  int GetMeshEdgeCount() const;
395 
403  int GetMeshEdgeIndex(int pStartVertexIndex, int pEndVertexIndex, bool& pReversed, int pExistedEdgeCount=-1);
404 
408  void BeginGetMeshEdgeIndexForPolygon();
409 
413  void EndGetMeshEdgeIndexForPolygon();
414 
421  int GetMeshEdgeIndexForPolygon(int pPolygon, int pPositionInPolygon);
422 
427  void GetMeshEdgeVertices(int pEdgeIndex, int& pStartVertexIndex, int& pEndVertexIndex) const;
428 
432  void BeginGetMeshEdgeVertices();
433 
437  void EndGetMeshEdgeVertices();
438 
441  void SetMeshEdgeCount(int pEdgeCount);
442 
446  inline void SetMeshEdge(int pEdgeIndex, int pValue){ if( pEdgeIndex >= 0 && pEdgeIndex < mEdgeArray.GetCount() ) mEdgeArray[pEdgeIndex] = pValue; }
447 
455  int AddMeshEdgeIndex(int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates);
456 
468  int SetMeshEdgeIndex(int pEdgeIndex, int pStartVertexIndex, int pEndVertexIndex, bool pCheckForDuplicates, int pExistedEdgeCount=-1);
469 
472  void BeginAddMeshEdgeIndex();
473 
475  void EndAddMeshEdgeIndex();
476 
481  int AddMeshEdgeIndexForPolygon(int pPolygonIndex, int pPositionInPolygon);
482 
492  bool SetMeshEdgeIndex(int pEdgeIndex, int pPolygonIndex, int pPositionInPolygon);
493 
496  bool IsTriangleMesh() const;
498 
501  inline void ReservePolygonCount(int pCount) { mPolygons.Reserve(pCount); }
502 
505  inline void ReservePolygonVertexCount(int pCount) { mPolygonVertices.Reserve(pCount); }
506 
507  bool GetTextureUV(FbxLayerElementArrayTemplate<FbxVector2>** pLockableArray, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse) const;
508  bool GetMaterialIndices(FbxLayerElementArrayTemplate<int>** pLockableArray) const;
509  bool GetTextureIndices(FbxLayerElementArrayTemplate<int>** pLockableArray, FbxLayerElement::EType pTextureType) const;
510 
516  double GetEdgeCreaseInfo(int pEdgeIndex);
517 
521  bool GetEdgeCreaseInfoArray(FbxLayerElementArrayTemplate<double>** pCreaseArray);
522 
526  double GetVertexCreaseInfo(int pVertexIndex);
527 
531  bool GetVertexCreaseInfoArray(FbxLayerElementArrayTemplate<double>** pCreaseArray);
532 
537  bool SetEdgeCreaseInfo(int pEdgeIndex, double pWeight);
538 
542  bool SetEdgeCreaseInfoArray(FbxArray<double>* pWeightArray);
543 
548  bool SetVertexCreaseInfo(int pVertexIndex, double pWeight);
549 
553  bool SetVertexCreaseInfoArray(FbxArray<double>* pWeightArray);
555 
562  {
566  eFine
567  };
568 
571  {
574  eCreaseEdge
575  };
576 
580  FbxMesh::ESmoothness GetMeshSmoothness() const;
581 
585  void SetMeshSmoothness(FbxMesh::ESmoothness pSmoothness);
586 
589  int GetMeshPreviewDivisionLevels() const;
590 
593  void SetMeshPreviewDivisionLevels(int pPreviewDivisionLevels);
594 
598  int GetMeshRenderDivisionLevels() const;
599 
602  void SetMeshRenderDivisionLevels(int pRenderDivisionLevels);
603 
606  bool GetDisplaySubdivisions() const;
607 
610  void SetDisplaySubdivisions(bool pDisplySubdivisions);
611 
614  EBoundaryRule GetBoundaryRule() const;
615 
619  void SetBoundaryRule(EBoundaryRule pBoundaryRule);
620 
623  bool GetPreserveBorders() const;
624 
628  void SetPreserveBorders(bool pPreserveBorders);
629 
632  bool GetPreserveHardEdges() const;
633 
637  void SetPreserveHardEdges(bool pPreserveHardEdges);
638 
641  bool GetPropagateEdgeHardness() const;
642 
646  void SetPropagateEdgeHardness(bool pPropagateEdgeHardness);
648 
654  bool GetPolyHoleInfo(int pFaceIndex);
655 
659  bool GetPolyHoleInfoArray(FbxLayerElementArrayTemplate<bool>** pHoleArray);
660 
665  bool SetPolyHoleInfo(int pFaceIndex, bool pIsHole);
666 
670  bool SetPolyHoleInfoArray(FbxArray<bool>* pHoleArray);
672 
685  bool GenerateTangentsData(const char* pUVSetName=NULL, bool pOverwrite=false, bool pIgnoreTangentFlip = false);
686 
697  bool GenerateTangentsData(int pUVSetLayerIndex, bool pOverwrite=false, bool pIgnoreTangentFlip = false);
698 
699 
709  bool GenerateTangentsDataForAllUVSets(bool pOverwrite=false, bool pIgnoreTangentFlip=false);
711 
712 /*****************************************************************************************************************************
713 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
714 *****************************************************************************************************************************/
715 #ifndef DOXYGEN_SHOULD_SKIP_THIS
716  virtual FbxObject& Copy(const FbxObject& pObject);
717  virtual void Compact();
718 
719  //Please use GetPolygonVertexIndex and GetPolygonVertices to access these arrays.
720  //DO NOT MODIFY them directly, otherwise unexpected behavior will occur.
721  //These members are public only for application data copy performance reasons.
722  struct PolygonDef{ int mIndex; int mSize; int mGroup; };
723 
724  FbxArray<PolygonDef> mPolygons;
725  FbxArray<int> mPolygonVertices;
726  FbxArray<int> mEdgeArray;
727 
728  //These are only used in context of triangulation to backup original polygon layout necessary for handling mesh cache after triangulation
729  FbxArray<PolygonDef>* mOriginalPolygons;
730  FbxArray<int>* mOriginalPolygonVertices;
731  int mOriginalControlPointsCount;
732 
733  //Internal structure used to keep the mapping information between edges and polygons.
734  struct ComponentMap
735  {
736  FbxArray<int> mData; // The array to store data.
737  FbxArray<int> mOffsets; // The array to store the offsets of the data in mData.
738 
739  int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
740  int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
741  int GetComponentCount() { return mOffsets.GetCount() - 1; }
742  };
743  void ComputeComponentMaps(ComponentMap& pEdgeToPolyMap, ComponentMap& pPolyToEdgeMap);
744 
745  // Internal structure used to keep the mapping information between the control points and the
746  // vertices referencing them
747  class FBXSDK_DLL ControlPointToVerticesMap
748  {
749  public:
750  ControlPointToVerticesMap();
751  ~ControlPointToVerticesMap();
752  bool Valid();
753 
754  void Fill(FbxMesh* pMesh);
755 
756  int GetCount();
757  bool Init(int pNbEntries);
758  void Clear();
759 
760  FbxArray<int>* GetVerticesArray(int pControlPoint);
761  FbxArray<int>* operator[](int pControlPoint);
762 
763  private:
764  FbxArray< FbxArray<int>* > mMap;
765  };
766  void ComputeControlPointToVerticesMap(ControlPointToVerticesMap& pMap);
767 
768  // this function will compare the vertex normals with the corresponding ones in pMesh and
769  // make them similar (i.e: if pMesh(NVi) == pMesh(NVj) then make this(NVi) == this(NVj))
770  bool ConformNormalsTo(const FbxMesh* pMesh);
771 
772 protected:
773  virtual void Construct(const FbxObject* pFrom);
774  virtual void Destruct(bool pRecursive);
775  virtual void ContentClear();
776 
777  void InitTextureIndices(FbxLayerElementTexture* pLayerElementTexture, FbxLayerElement::EMappingMode pMappingMode);
778  void RemoveTextureIndex(FbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
779  void RemoveUVIndex(FbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
780 
781  bool GetBadPolyIndices(FbxArray<int>& pArrayBadPolyIndices, bool pCheckOne) const;
782 
783  struct SplitEdgeData { int mOriginalEdge; bool mIsNew; };
784 
785  ESmoothness mSmoothness;
786  int mPreviewDivisionLevels;
787  int mRenderDivisionLevels;
788 
789  bool mDisplaySubdivisions;
790  EBoundaryRule mBoundaryRule;
791  bool mPreserveBorders;
792  bool mPreserveHardEdges;
793  bool mPropagateEdgeHardness;
794 
795  struct PolygonIndexDef { int mPolygonIndex; int mSubPolygonIndex; };
796 
797  struct V2PVMap
798  {
799  PolygonIndexDef* mV2PV;
800  int* mV2PVOffset;
801  int* mV2PVCount;
802  FbxArray<FbxSet<int>* > mPVEdge;
803  bool mValid;
804 
805  //Used for fast search in GetMeshEdgeIndexForPolygon this array does not follow the same allocation as the above ones because
806  //it is not used in the normal BeginAddMeshEdgeIndex(). It is filled only by the call to BeginGetMeshEdgeIndexForPolygon().
807  FbxArray<int> mV2Edge;
808  } mV2PVMap;
809 
810  struct EdgeLookupDef { FbxArray<int> mPVFlags; bool mValid; } mPVEndFlags;
811 
812  //Finds the polygon index for the given edge
813  int FindPolygonIndex(int pEdgeIndex);
814  static int PolygonIndexCompare(const void* p1, const void* p2);
815  void PolySetTexture(FbxLayer* pLayer, int pTextureIndex, FbxLayerElement::EType pTextureType);
816  template<class T> bool GetPolygonVertexLayerElementIndex(const FbxLayerElementTemplate<T>* pLayerElement, int pPolyIndex, int pVertexIndex, int& pIndex) const;
817  template<class T> bool GetPolygonVertexLayerElementValue(const FbxLayerElementTemplate<T>* pLayerElement, int pPolyIndex, int pVertexIndex, T& pValue, bool pAllowUnmapped) const;
818 
819  friend class FbxGeometryConverter;
820 
821 private:
822  bool GenerateTangentsData(FbxLayerElementUV* pUVSet, int pLayerIndex, bool pOverwrite=false, bool pIgnoreTangentFlip = false);
823  void FillMeshEdgeTable(FbxArray<int>& pTable, int* pValue, void (*FillFct)(FbxArray<int>& pTable, int pIndex, int* pValue));
824  void ComputeNormalsPerCtrlPoint(FbxArray<VertexNormalInfo>& lNormalInfo, bool pCW=false);
825  void ComputeNormalsPerPolygonVertex(FbxArray<VertexNormalInfo>& lNormalInfo, bool pCW=false);
826  void GenerateNormalsByCtrlPoint(bool pCW);
827 
828 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
829 };
830 
831 #include <fbxsdk/fbxsdk_nsend.h>
832 
833 #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
FBX SDK environment definition.
void SetMeshEdge(int pEdgeIndex, int pValue)
Sets element in edge array to specific value.
Definition: fbxmesh.h:446
FbxLayer class provides a base for the layering mechanism.
Definition: fbxlayer.h:2369
virtual FbxNodeAttribute::EType GetAttributeType() const
Returns the node attribute type.
virtual void Compact()
Compact the memory used by this object.
int GetPolygonVertexCount() const
Gets the number of polygon vertices in the mesh.
Definition: fbxmesh.h:159
Both display cage and smooth mesh.
Definition: fbxmesh.h:565
Internal structure used to keep the duplicate vertex information.
Definition: fbxmesh.h:325
int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
Get a polygon vertex (i.e: an index to a control point).
Definition: fbxmesh.h:104
FbxLayerElementArrayTemplate provides data array manipulation of the data buffer for FbxLayerElement...
Definition: fbxlayer.h:858
#define NULL
Definition: fbxarch.h:210
virtual FbxObject & Copy(const FbxObject &pObject)
Copy an object content into this object.
int GetPolygonSize(int pPolygonIndex) const
Get the number of polygon vertices in a polygon.
Definition: fbxmesh.h:78
Layer element for mapping UVs to a geometry.
Definition: fbxlayer.h:1478
int lNewVertexIndex
The new index of the vertex.
Definition: fbxmesh.h:338
EType
Node attribute types.
void ReservePolygonCount(int pCount)
Reserve memory in the polygon array to hold the specified number of polygons.
Definition: fbxmesh.h:501
int mNumNormal
Number of normals added.
Definition: fbxmesh.h:355
void ReservePolygonVertexCount(int pCount)
Reserve memory in the polygon vertex array to hold the specified number of polygon vertices...
Definition: fbxmesh.h:505
void SetPolygonGroup(int pPolygonIndex, int pGroup) const
Assign the specified polygon a group ID.
Definition: fbxmesh.h:95
This class complements the FbxLayerElement class.
Definition: fbxlayer.h:1022
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
Not active "smooth mesh preview".
Definition: fbxmesh.h:564
EBoundaryRule
the boundary rule.
Definition: fbxmesh.h:570
FbxVector4 mTotalNormal
Sum of all the normals found.
Definition: fbxmesh.h:354
int lEdgeIndex
The edge index.
Definition: fbxmesh.h:341
Default value.
Definition: fbxmesh.h:572
FbxVector4 lNormal
The normal associated with this duplicate control point.
Definition: fbxmesh.h:339
int lVertexPolyIndex
Index in mPolygonsVertex where the vertex is found.
Definition: fbxmesh.h:337
Default value, not active "smooth mesh preview".
Definition: fbxmesh.h:563
int GetPolygonCount() const
Get the polygon count of this mesh.
Definition: fbxmesh.h:73
Layer element for mapping Textures to a geometry.
Definition: fbxlayer.h:2179
EType
Layer Element type identifier.
Definition: fbxlayer.h:75
A four double mathematic vector class.
Definition: fbxvector4.h:25
#define FBXSDK_DLL
Definition: fbxarch.h:173
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.
A two double mathematic vector class.
Definition: fbxvector2.h:23
FbxVector2 lUV
The UV associated with this duplicate control point.
Definition: fbxmesh.h:340
Class for array of basic elements such as pointers and basic types.
Definition: fbxarray.h:23
Internal structure used to compute the normals on a mesh.
Definition: fbxmesh.h:345
ESmoothness
Display Smoothness.
Definition: fbxmesh.h:561
A mesh is a geometry made of polygons.
Definition: fbxmesh.h:32
Used for hard corner.
Definition: fbxmesh.h:573