fbxsdk/scene/geometry/fbxmesh.h Source File

fbxmesh.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 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 
684  bool GenerateTangentsData(const char* pUVSetName=NULL, bool pOverwrite=false);
685 
695  bool GenerateTangentsData(int pUVSetLayerIndex, bool pOverwrite=false);
696 
697 
706  bool GenerateTangentsDataForAllUVSets(bool pOverwrite=false);
708 
709 /*****************************************************************************************************************************
710 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
711 *****************************************************************************************************************************/
712 #ifndef DOXYGEN_SHOULD_SKIP_THIS
713  virtual FbxObject& Copy(const FbxObject& pObject);
714  virtual void Compact();
715 
716  //Please use GetPolygonVertexIndex and GetPolygonVertices to access these arrays.
717  //DO NOT MODIFY them directly, otherwise unexpected behavior will occur.
718  //These members are public only for application data copy performance reasons.
719  struct PolygonDef{ int mIndex; int mSize; int mGroup; };
720 
721  FbxArray<PolygonDef> mPolygons;
722  FbxArray<int> mPolygonVertices;
723  FbxArray<int> mEdgeArray;
724 
725  //These are only used in context of triangulation to backup original polygon layout necessary for handling mesh cache after triangulation
726  FbxArray<PolygonDef>* mOriginalPolygons;
727  FbxArray<int>* mOriginalPolygonVertices;
728  int mOriginalControlPointsCount;
729 
730  //Internal structure used to keep the mapping information between edges and polygons.
731  struct ComponentMap
732  {
733  FbxArray<int> mData; // The array to store data.
734  FbxArray<int> mOffsets; // The array to store the offsets of the data in mData.
735 
736  int GetDataCount(int pIndex) { return mOffsets[pIndex + 1] - mOffsets[pIndex]; }
737  int GetData(int pIndex, int pSubIndex) { return mData[ mOffsets[pIndex] + pSubIndex ]; }
738  int GetComponentCount() { return mOffsets.GetCount() - 1; }
739  };
740  void ComputeComponentMaps(ComponentMap& pEdgeToPolyMap, ComponentMap& pPolyToEdgeMap);
741 
742  // Internal structure used to keep the mapping information between the control points and the
743  // vertices referencing them
744  class ControlPointToVerticesMap
745  {
746  public:
747  ControlPointToVerticesMap();
748  ~ControlPointToVerticesMap();
749  bool Valid();
750 
751  void Fill(FbxMesh* pMesh);
752 
753  int GetCount();
754  bool Init(int pNbEntries);
755  void Clear();
756 
757  FbxArray<int>* GetVerticesArray(int pControlPoint);
758  FbxArray<int>* operator[](int pControlPoint);
759 
760  private:
761  FbxArray< FbxArray<int>* > mMap;
762  };
763  void ComputeControlPointToVerticesMap(ControlPointToVerticesMap& pMap);
764 
765  // this function will compare the vertex normals with the corresponding ones in pMesh and
766  // make them similar (i.e: if pMesh(NVi) == pMesh(NVj) then make this(NVi) == this(NVj))
767  bool ConformNormalsTo(const FbxMesh* pMesh);
768 
769 protected:
770  virtual void Construct(const FbxObject* pFrom);
771  virtual void Destruct(bool pRecursive);
772  virtual void ContentClear();
773 
774  void InitTextureIndices(FbxLayerElementTexture* pLayerElementTexture, FbxLayerElement::EMappingMode pMappingMode);
775  void RemoveTextureIndex(FbxLayerElementTexture* pLayerElementTextures, int pPolygonIndex, int pOffset);
776  void RemoveUVIndex(FbxLayerElementUV* pLayerElementUV, int pPolygonIndex, int pOffset);
777 
778  bool GetBadPolyIndices(FbxArray<int>& pArrayBadPolyIndices, bool pCheckOne) const;
779 
780  struct SplitEdgeData { int mOriginalEdge; bool mIsNew; };
781 
782  ESmoothness mSmoothness;
783  int mPreviewDivisionLevels;
784  int mRenderDivisionLevels;
785 
786  bool mDisplaySubdivisions;
787  EBoundaryRule mBoundaryRule;
788  bool mPreserveBorders;
789  bool mPreserveHardEdges;
790  bool mPropagateEdgeHardness;
791 
792  struct PolygonIndexDef { int mPolygonIndex; int mSubPolygonIndex; };
793 
794  struct V2PVMap
795  {
796  PolygonIndexDef* mV2PV;
797  int* mV2PVOffset;
798  int* mV2PVCount;
799  FbxArray<FbxSet<int>* > mPVEdge;
800  bool mValid;
801 
802  //Used for fast search in GetMeshEdgeIndexForPolygon this array does not follow the same allocation as the above ones because
803  //it is not used in the normal BeginAddMeshEdgeIndex(). It is filled only by the call to BeginGetMeshEdgeIndexForPolygon().
804  FbxArray<int> mV2Edge;
805  } mV2PVMap;
806 
807  struct EdgeLookupDef { FbxArray<int> mPVFlags; bool mValid; } mPVEndFlags;
808 
809  //Finds the polygon index for the given edge
810  int FindPolygonIndex(int pEdgeIndex);
811  static int PolygonIndexCompare(const void* p1, const void* p2);
812  void PolySetTexture(FbxLayer* pLayer, int pTextureIndex, FbxLayerElement::EType pTextureType);
813  template<class T> bool GetPolygonVertexLayerElementIndex(const FbxLayerElementTemplate<T>* pLayerElement, int pPolyIndex, int pVertexIndex, int& pIndex) const;
814  template<class T> bool GetPolygonVertexLayerElementValue(const FbxLayerElementTemplate<T>* pLayerElement, int pPolyIndex, int pVertexIndex, T& pValue, bool pAllowUnmapped) const;
815 
816  friend class FbxGeometryConverter;
817 
818 private:
819  bool GenerateTangentsData(FbxLayerElementUV* pUVSet, int pLayerIndex, bool pOverwrite=false);
820  void FillMeshEdgeTable(FbxArray<int>& pTable, int* pValue, void (*FillFct)(FbxArray<int>& pTable, int pIndex, int* pValue));
821  void ComputeNormalsPerCtrlPoint(FbxArray<VertexNormalInfo>& lNormalInfo, bool pCW=false);
822  void ComputeNormalsPerPolygonVertex(FbxArray<VertexNormalInfo>& lNormalInfo, bool pCW=false);
823  void GenerateNormalsByCtrlPoint(bool pCW);
824 
825 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
826 };
827 
828 #include <fbxsdk/fbxsdk_nsend.h>
829 
830 #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:2362
virtual void Compact()
Compact the memory used by this object.
Both display cage and smooth mesh.
Definition: fbxmesh.h:565
Internal structure used to keep the duplicate vertex information.
Definition: fbxmesh.h:325
virtual void ContentClear()
Clears this object's content from memory.
FbxLayerElementArrayTemplate provides data array manipulation of the data buffer for FbxLayerElement...
Definition: fbxlayer.h:851
#define NULL
Definition: fbxarch.h:210
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:73
Layer element for mapping UVs to a geometry.
Definition: fbxlayer.h:1471
int GetPolygonVertex(int pPolygonIndex, int pPositionInPolygon) const
Get a polygon vertex (i.e: an index to a control point).
Definition: fbxmesh.h:104
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
virtual FbxNodeAttribute::EType GetAttributeType() const
Returns the node attribute type.
void ReservePolygonVertexCount(int pCount)
Reserve memory in the polygon vertex array to hold the specified number of polygon vertices...
Definition: fbxmesh.h:505
This class complements the FbxLayerElement class.
Definition: fbxlayer.h:1015
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
virtual void Construct(const FbxObject *pFrom)
Optional constructor override, automatically called by default constructor.
int lEdgeIndex
The edge index.
Definition: fbxmesh.h:341
int GetPolygonVertexCount() const
Gets the number of polygon vertices in the mesh.
Definition: fbxmesh.h:159
void SetPolygonGroup(int pPolygonIndex, int pGroup) const
Assign the specified polygon a group ID.
Definition: fbxmesh.h:95
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
Layer element for mapping Textures to a geometry.
Definition: fbxlayer.h:2172
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.
virtual void Destruct(bool pRecursive)
Optional destructor override, automatically called by default destructor.
A two double mathematic vector class.
Definition: fbxvector2.h:23
FbxVector2 lUV
The UV associated with this duplicate control point.
Definition: fbxmesh.h:340
int GetPolygonSize(int pPolygonIndex) const
Get the number of polygon vertices in a polygon.
Definition: fbxmesh.h:78
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