Team Fortress 2 Source Code as on 22/4/2020
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.

183 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //===================================================================
  9. // Useful macros
  10. //
  11. #define CONSTRUCTOR
  12. #define DESTRUCTOR
  13. #define EXPORT_THIS __declspec(dllexport)
  14. #define DEFAULT_EXT _T("vvw")
  15. #define FStrEq(sz1, sz2) (strcmp((sz1), (sz2)) == 0)
  16. //=============================================================================
  17. // TREE-ENUMERATION PROCEDURES
  18. //=============================================================================
  19. #define ASSERT_AND_ABORT(f, sz) \
  20. if (!(f)) \
  21. { \
  22. ASSERT_MBOX(FALSE, sz); \
  23. cleanup( ); \
  24. return TREE_ABORT; \
  25. }
  26. // Integer constants for this class
  27. enum
  28. {
  29. MAX_NAME_CHARS = 70,
  30. UNDESIRABLE_NODE_MARKER = -7777
  31. };
  32. // For keeping info about each (non-ignored) 3dsMax node in the tree
  33. typedef struct
  34. {
  35. char szNodeName[MAX_NAME_CHARS]; // usefull for lookups
  36. Matrix3 mat3NodeTM; // node's transformation matrix (at time zero)
  37. Matrix3 mat3ObjectTM; // object-offset transformation matrix (at time zero)
  38. int imaxnodeParent; // cached index of parent node
  39. } MaxNode;
  40. typedef struct
  41. {
  42. float flDist;
  43. float flWeight;
  44. } MaxVertWeight;
  45. //===================================================================
  46. // Class that implements the scene-export.
  47. //
  48. class VWeightExportClass : public SceneExport
  49. {
  50. friend BOOL CALLBACK ExportOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  51. friend class CollectModelTEP;
  52. public:
  53. CONSTRUCTOR VWeightExportClass (void);
  54. DESTRUCTOR ~VWeightExportClass (void);
  55. // Required by classes derived from SceneExport
  56. virtual int ExtCount (void) { return 1; }
  57. virtual const TCHAR* Ext (int i) { return DEFAULT_EXT; }
  58. virtual const TCHAR* LongDesc (void) { return _T("Valve Skeletal Model Exporter for 3D Studio Max"); }
  59. virtual const TCHAR* ShortDesc (void) { return _T("Valve VVW"); }
  60. virtual const TCHAR* AuthorName (void) { return _T("Valve, LLC"); }
  61. virtual const TCHAR* CopyrightMessage(void) { return _T("Copyright (c) 1998, Valve LLC"); }
  62. virtual const TCHAR* OtherMessage1 (void) { return _T(""); }
  63. virtual const TCHAR* OtherMessage2 (void) { return _T(""); }
  64. virtual unsigned int Version (void) { return 201; }
  65. virtual void ShowAbout (HWND hWnd) { return; }
  66. // virtual int DoExport (const TCHAR *name, ExpInterface *ei, Interface *i);
  67. virtual int DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts=FALSE,DWORD options=0); // Export file
  68. MaxNode m_MaxNode[512]; // array of nodes
  69. long m_cMaxNode; // # of nodes
  70. MaxVertWeight *m_MaxVertex[10000];
  71. long m_cMaxVertex;
  72. // Animation metrics (gleaned from 3dsMax and cached for convenience)
  73. Interval m_intervalOfAnimation;
  74. TimeValue m_tvStart;
  75. TimeValue m_tvEnd;
  76. int m_tpf; // ticks-per-frame
  77. private:
  78. void CollectNodes( INode *pnode );
  79. BOOL CollectModel( ExpInterface *pexpiface );
  80. };
  81. //===================================================================
  82. // Basically just a ClassFactory for communicating with 3DSMAX.
  83. //
  84. class VWeightExportClassDesc : public ClassDesc
  85. {
  86. public:
  87. int IsPublic (void) { return TRUE; }
  88. void * Create (BOOL loading=FALSE) { return new VWeightExportClass; }
  89. const TCHAR * ClassName (void) { return _T("VWeightExport"); }
  90. SClass_ID SuperClassID (void) { return SCENE_EXPORT_CLASS_ID; }
  91. Class_ID ClassID (void) { return Class_ID(0x554b1092, 0x206a444f); }
  92. const TCHAR * Category (void) { return _T(""); }
  93. };
  94. //===================================================================
  95. // Tree Enumeration Callback
  96. // Just counts the nodes in the node tree
  97. //
  98. class CountNodesTEP : public ITreeEnumProc
  99. {
  100. public:
  101. virtual int callback(INode *node);
  102. int m_cNodes; // running count of nodes
  103. };
  104. //===================================================================
  105. // Tree Enumeration Callback
  106. // Collects the nodes in the tree into the global array
  107. //
  108. class CollectNodesTEP : public ITreeEnumProc
  109. {
  110. public:
  111. virtual int callback(INode *node);
  112. VWeightExportClass *m_phec;
  113. };
  114. //===================================================================
  115. // Tree Enumeration Callback
  116. // Dumps the triangle meshes to a file.
  117. //
  118. class CollectModelTEP : public ITreeEnumProc
  119. {
  120. public:
  121. virtual int callback(INode *node);
  122. void cleanup(void);
  123. // FILE *m_pfile; // write to this file
  124. TimeValue m_tvToDump; // dump snapshot at this frame time
  125. VWeightExportClass *m_phec;
  126. IPhyContextExport *m_mcExport;
  127. IPhysiqueExport *m_phyExport;
  128. Modifier *m_phyMod;
  129. Modifier *m_bonesProMod;
  130. BonesPro_WeightArray *m_wa;
  131. private:
  132. int CollectWeights( int iVertex, MaxVertWeight *pweight );
  133. };
  134. //===================================================================
  135. // Prototype declarations
  136. //
  137. void ResetINodeMap( void );
  138. int BuildINodeMap(INode *pnode);
  139. void AddINode( INode *pnode );
  140. int GetIndexOfNodeName( TCHAR *szNodeName, BOOL fAssertPropExists = TRUE );
  141. int GetIndexOfINode( INode *pnode, BOOL fAssertPropExists = TRUE);
  142. BOOL FUndesirableNode( INode *pnode);
  143. BOOL FNodeMarkedToSkip( INode *pnode);
  144. Modifier *FindPhysiqueModifier( INode *nodePtr );
  145. Modifier *FindBonesProModifier( INode *nodePtr );
  146. int AssertFailedFunc(char *sz);
  147. #define ASSERT_MBOX(f, sz) ((f) ? 1 : AssertFailedFunc(sz))
  148. void GetUnifiedCoord( Point3 &p1, MaxVertWeight pweight[], MaxNode maxNode[], int cMaxNode );
  149. int GetBoneWeights( IPhyContextExport *mcExport, int iVertex, MaxVertWeight *pweight);
  150. int GetBoneWeights( Modifier * bonesProMod, int iVertex, MaxVertWeight *pweight);
  151. void SetBoneWeights( Modifier * bonesProMod, int iVertex, MaxVertWeight *pweight);