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.

178 lines
5.7 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("smd")
  15. #define FStrEq(sz1, sz2) (strcmp((sz1), (sz2)) == 0)
  16. //===================================================================
  17. // Class that implements the scene-export.
  18. //
  19. class SmdExportClass : public SceneExport
  20. {
  21. friend BOOL CALLBACK ExportOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  22. friend class DumpModelTEP;
  23. friend class DumpDeformsTEP;
  24. public:
  25. CONSTRUCTOR SmdExportClass (void);
  26. DESTRUCTOR ~SmdExportClass (void);
  27. // Required by classes derived from SceneExport
  28. virtual int ExtCount (void) { return 1; }
  29. virtual const TCHAR* Ext (int i) { return DEFAULT_EXT; }
  30. virtual const TCHAR* LongDesc (void) { return _T("Valve Skeletal Model Exporter for 3D Studio Max"); }
  31. virtual const TCHAR* ShortDesc (void) { return _T("Valve SMD"); }
  32. virtual const TCHAR* AuthorName (void) { return _T("Valve, LLC"); }
  33. virtual const TCHAR* CopyrightMessage(void) { return _T("Copyright (c) 1998, Valve LLC"); }
  34. virtual const TCHAR* OtherMessage1 (void) { return _T(""); }
  35. virtual const TCHAR* OtherMessage2 (void) { return _T(""); }
  36. virtual unsigned int Version (void) { return 201; }
  37. virtual void ShowAbout (HWND hWnd) { return; }
  38. // virtual int DoExport (const TCHAR *name, ExpInterface *ei, Interface *i);
  39. virtual int DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts=FALSE,DWORD options=0); // Export file
  40. // Integer constants for this class
  41. enum
  42. {
  43. MAX_NAME_CHARS = 70,
  44. UNDESIRABLE_NODE_MARKER = -7777
  45. };
  46. // For keeping info about each (non-ignored) 3dsMax node in the tree
  47. typedef struct
  48. {
  49. char szNodeName[MAX_NAME_CHARS]; // usefull for lookups
  50. Matrix3 mat3NodeTM; // node's transformation matrix (at time zero)
  51. Matrix3 mat3ObjectTM; // object-offset transformation matrix (at time zero)
  52. int imaxnodeParent; // cached index of parent node
  53. float xRotFirstFrame; // 1st frame's X rotation
  54. float yRotFirstFrame; // 1st frame's Y rotation
  55. float zRotFirstFrame; // 1st frame's Z rotation
  56. bool isMirrored;
  57. } MaxNode;
  58. MaxNode *m_rgmaxnode; // array of nodes
  59. long m_imaxnodeMac; // # of nodes
  60. // Animation metrics (gleaned from 3dsMax and cached for convenience)
  61. Interval m_intervalOfAnimation;
  62. TimeValue m_tvStart;
  63. TimeValue m_tvEnd;
  64. int m_tpf; // ticks-per-frame
  65. private:
  66. BOOL CollectNodes (ExpInterface *expiface);
  67. BOOL DumpBones (FILE *pFile, ExpInterface *pexpiface);
  68. BOOL DumpRotations (FILE *pFile, ExpInterface *pexpiface);
  69. BOOL DumpModel (FILE *pFile, ExpInterface *pexpiface);
  70. BOOL DumpDeforms (FILE *pFile, ExpInterface *pexpiface);
  71. // Is this MAX file just the reference frame, or an animation?
  72. // If TRUE, the "bones" and "mesh" files will be created.
  73. // If FALSE, the "rots" file will be created.
  74. BOOL m_fReferenceFrame;
  75. };
  76. //===================================================================
  77. // Basically just a ClassFactory for communicating with 3DSMAX.
  78. //
  79. class SmdExportClassDesc : public ClassDesc
  80. {
  81. public:
  82. int IsPublic (void) { return TRUE; }
  83. void * Create (BOOL loading=FALSE) { return new SmdExportClass; }
  84. const TCHAR * ClassName (void) { return _T("SmdExport"); }
  85. SClass_ID SuperClassID (void) { return SCENE_EXPORT_CLASS_ID; }
  86. Class_ID ClassID (void) { return Class_ID(0x774a43fd, 0x794d2210); }
  87. const TCHAR * Category (void) { return _T(""); }
  88. };
  89. //===================================================================
  90. // Tree Enumeration Callback
  91. // Just counts the nodes in the node tree
  92. //
  93. class CountNodesTEP : public ITreeEnumProc
  94. {
  95. public:
  96. virtual int callback(INode *node);
  97. int m_cNodes; // running count of nodes
  98. };
  99. //===================================================================
  100. // Tree Enumeration Callback
  101. // Collects the nodes in the tree into the global array
  102. //
  103. class CollectNodesTEP : public ITreeEnumProc
  104. {
  105. public:
  106. virtual int callback(INode *node);
  107. SmdExportClass *m_phec;
  108. };
  109. //===================================================================
  110. // Tree Enumeration Callback
  111. // Dumps the bone offsets to a file.
  112. //
  113. class DumpNodesTEP : public ITreeEnumProc
  114. {
  115. public:
  116. virtual int callback(INode *node);
  117. FILE *m_pfile; // write to this file
  118. SmdExportClass *m_phec;
  119. };
  120. //===================================================================
  121. // Tree Enumeration Callback
  122. // Dumps the per-frame bone rotations to a file.
  123. //
  124. class DumpFrameRotationsTEP : public ITreeEnumProc
  125. {
  126. public:
  127. virtual int callback(INode *node);
  128. void cleanup(void);
  129. FILE *m_pfile; // write to this file
  130. TimeValue m_tvToDump; // dump snapshot at this frame time
  131. SmdExportClass *m_phec;
  132. };
  133. //===================================================================
  134. // Tree Enumeration Callback
  135. // Dumps the triangle meshes to a file.
  136. //
  137. class DumpModelTEP : public ITreeEnumProc
  138. {
  139. public:
  140. virtual int callback(INode *node);
  141. void cleanup(void);
  142. FILE *m_pfile; // write to this file
  143. TimeValue m_tvToDump; // dump snapshot at this frame time
  144. SmdExportClass *m_phec;
  145. IPhyContextExport *m_mcExport;
  146. IPhysiqueExport *m_phyExport;
  147. Modifier *m_phyMod;
  148. Modifier *m_bonesProMod;
  149. BonesPro_WeightArray *m_wa;
  150. private:
  151. Point3 Pt3GetRVertexNormal(RVertex *prvertex, DWORD smGroupFace);
  152. void DumpWeights( int iVertex );
  153. };