Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.9 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ==========
  2. //
  3. // Autodesk FBX <-> Valve DMX
  4. //
  5. //=============================================================================
  6. #ifndef DMFBXSERIALIZER_H
  7. #define DMFBXSERIALIZER_H
  8. #if defined( _WIN32 )
  9. #pragma once
  10. #endif
  11. // FBX includes
  12. #include <fbxsdk.h>
  13. // Valve includes
  14. #include "datamodel/idatamodel.h"
  15. #include "movieobjects/dmeaxissystem.h"
  16. #include "tier1/utlbuffer.h"
  17. #include "tier1/utlmap.h"
  18. #include "tier1/utlstring.h"
  19. #include "tier1/utlvector.h"
  20. //-----------------------------------------------------------------------------
  21. // Forward declarations
  22. //-----------------------------------------------------------------------------
  23. class CDmeCombinationOperator;
  24. class CDmeDag;
  25. class CDmeMesh;
  26. class CDmeModel;
  27. //-----------------------------------------------------------------------------
  28. // Serialization class for FBX files
  29. //-----------------------------------------------------------------------------
  30. class CDmFbxSerializer
  31. {
  32. public:
  33. CDmFbxSerializer();
  34. virtual ~CDmFbxSerializer();
  35. const char *GetName() const { return "fbx"; }
  36. const char *GetDescription() const { return "Autodesk� FBX�"; }
  37. // CDmFbxSerializer
  38. CDmElement *ReadFBX( const char *pszFilename );
  39. // Feed the CDmElement returned by ReadFBX to see if there were non-fatal conversion errors which the user should be informed about
  40. static bool HasConversionErrors( CDmElement *pDmRoot );
  41. // Feed the CDmElement returned by ReadFBX to see if there were non-fatal conversion errors which the user should be informed about, they are added to pConversionErrors, if no errors, pConversionErrors is not touched
  42. static void GetConversionErrors( CDmElement *pDmRoot, CUtlVector< CUtlString > *pConversionErrors );
  43. bool Verbose1() const { return m_nOptVerbosity >= 1; }
  44. bool Verbose2() const { return m_nOptVerbosity >= 2; }
  45. // UtlHashtable is non-functional in //ValveGames/main 5/16/2012
  46. typedef CUtlMap< FbxNode *, CDmeDag * > FbxToDmxMap_t;
  47. typedef void( *HandleUVFunc_t )( CUtlVector< int > &, FbxMesh *, FbxGeometryElementUV *, int, int );
  48. protected:
  49. struct UVChannelData_t
  50. {
  51. FbxGeometryElementUV *m_pFbxElementUV;
  52. HandleUVFunc_t m_pFunc;
  53. CUtlVector< int > m_nIndices;
  54. };
  55. //-----------------------------------------------------------------------------
  56. // For oddly encoded vertex paint data coming from 3DSMax
  57. //-----------------------------------------------------------------------------
  58. struct UVColorChannelData_t
  59. {
  60. public:
  61. UVColorChannelData_t()
  62. {
  63. for ( int i = 0; i < ARRAYSIZE( m_uvChannelData ); ++i )
  64. {
  65. m_uvChannelData[i].m_pFbxElementUV = NULL;
  66. m_uvChannelData[i].m_pFunc = NULL;
  67. }
  68. }
  69. CUtlString m_sChannelName;
  70. UVChannelData_t m_uvChannelData[3];
  71. };
  72. FbxScene *LoadFbxScene( FbxTime::EMode &eFbxTimeMode, const char *pszFilename );
  73. void LoadModelAndSkeleton_R( FbxToDmxMap_t &fbxToDmxMap, CDmeModel *pDmeModel, CDmeDag *pDmeDagParent, FbxNode *pFbxNode, bool bAnimation, int nDepth ) const;
  74. CDmeDag *FbxNodeToDmeDag( CDmeDag *pDmeDagParent, FbxNode *pFbxNode, const char *pszDmeType, FbxMatrix *pmOutScale = NULL ) const;
  75. CDmeMesh *FbxShapeToDmeMesh( CDmeDag *pDmeDag, FbxNode *pFbxNode, const FbxMatrix &mScale ) const;
  76. bool FbxMeshToDmeFaceSets( CDmeDag *pDmeDag, CDmeMesh *pDmeMesh, FbxMesh *pFbxMesh, CUtlVector< int > &nPolygonToFaceSetMap ) const;
  77. bool FindMaterialResource( CUtlString &sOutMaterialPath, const char *pszInMaterialName, CUtlVector< CUtlString > &materialSearchErrorList ) const;
  78. bool GetFbxMaterialPathFromFbxFileTexture( CUtlString &sMaterialPath, FbxFileTexture *pFileTexture, CUtlVector< CUtlString > &materialSearchErrorList ) const;
  79. bool GetFbxMaterialPath( CUtlString &sMaterialPath, FbxSurfaceMaterial *pFbxMat, CUtlVector< CUtlString > &materialSearchErrorList ) const;
  80. void SkinMeshes_R( const FbxToDmxMap_t &fbxToDmxMap, CDmeModel *pDmeModel, FbxNode *pFbxNode ) const;
  81. void SkinMesh( CDmeDag *pDmeDag, const FbxToDmxMap_t &fbxToDmxMap, CDmeModel *pDmeModel, FbxNode *pFbxNode ) const;
  82. void AddBlendShapes_R( const FbxToDmxMap_t &fbxToDmxMap, CDmElement *pDmeRoot, FbxNode *pFbxNode ) const;
  83. void AddBlendShape( CDmeDag *pDmeDag, const FbxToDmxMap_t &fbxToDmxMap, CDmElement *pDmeRoot, FbxNode *pFbxNode ) const;
  84. CDmeCombinationOperator *FindOrCreateComboOp( CDmElement *pDmeRoot ) const;
  85. bool FindOrCreateControl( CDmeCombinationOperator *pDmeComboOp, const char *pszName ) const;
  86. void GetName( CUtlString &sCleanName, const FbxNode *pFbxNode ) const;
  87. void CleanupName( CUtlString &sCleanName, const char *pszName ) const;
  88. void LoadAnimation( CDmElement *pDmeRoot, CDmeModel *pDmeModel, const FbxToDmxMap_t &fbxToDmxMap, FbxScene *pFbxScene, FbxNode *pFbxRootNode, FbxTime::EMode eFbxTimeMode ) const;
  89. static FbxManager *GetFbxManager();
  90. static void AddConversionError( DmFileId_t nDmFileId, const char *pszErrorMsg );
  91. void ComputeVstFlexSliderAnimDataList_R( FbxAnimLayer *pFbxAnimLayer, CUtlVector< struct FbxDmxAnimData_t * > &animDataList, class CDmeChannelsClip *pDmeChannelsClip, const CDmFbxSerializer::FbxToDmxMap_t &fbxToDmxMap, FbxNode *pFbxNode ) const;
  92. void ComputeAnimDataList_R( FbxAnimLayer *pFbxAnimLayer, CUtlVector< struct FbxDmxAnimData_t * > &animDataList, class CDmeChannelsClip *pDmeChannelsClip, const CDmFbxSerializer::FbxToDmxMap_t &fbxToDmxMap, FbxNode *pFbxNode, struct FbxDmxAnimData_t *pAnimDataParent ) const;
  93. void AddColorData( class CDmeVertexData *pDmeVertexData, const CUtlVector< int > &nIndices, const FbxGeometryElementVertexColor *pFbxElement ) const;
  94. void AddUVColorData( CDmeVertexData *pDmeVertexData, const UVColorChannelData_t &uvColorData ) const;
  95. public:
  96. int m_nOptVerbosity;
  97. bool m_bOptUnderscoreForCorrectors;
  98. bool m_bAnimation;
  99. bool m_bReturnDmeModel;
  100. CDmeAxisSystem::Axis_t m_eOptUpAxis;
  101. CDmeAxisSystem::ForwardParity_t m_eOptForwardParity;
  102. CDmeAxisSystem::CoordSys_t m_eCoordSys;
  103. CUtlVector< CUtlString > m_sOptMaterialSearchPathList;
  104. float m_flOptScale;
  105. };
  106. #endif // DMFBXSERIALIZER_H