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.

287 lines
8.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Describes an asset: something that is compiled from sources,
  4. // in potentially multiple steps, to a compiled resource
  5. //
  6. //=============================================================================
  7. #include "movieobjects/dmemdlmakefile.h"
  8. #include "movieobjects/dmedag.h"
  9. #include "movieobjects/dmemdl.h"
  10. #include "datamodel/dmelementfactoryhelper.h"
  11. #include "datacache/imdlcache.h"
  12. #include "filesystem.h"
  13. #include "tier3/tier3.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Hook into datamodel
  18. //-----------------------------------------------------------------------------
  19. IMPLEMENT_ELEMENT_FACTORY( DmeSourceSkin, CDmeSourceSkin );
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. void CDmeSourceSkin::OnConstruction()
  24. {
  25. m_SkinName.Init( this, "skinName" );
  26. m_bFlipTriangles.Init( this, "flipTriangles" );
  27. m_flScale.InitAndSet( this, "scale", 1.0f );
  28. }
  29. void CDmeSourceSkin::OnDestruction()
  30. {
  31. }
  32. //-----------------------------------------------------------------------------
  33. // These can be built from DCC makefiles
  34. //-----------------------------------------------------------------------------
  35. static const char *s_pSkinMakeFiles[] =
  36. {
  37. "DmeMayaModelMakefile",
  38. "DmeXSIModelMakefile",
  39. NULL
  40. };
  41. const char **CDmeSourceSkin::GetSourceMakefileTypes()
  42. {
  43. return s_pSkinMakeFiles;
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Hook into datamodel
  47. //-----------------------------------------------------------------------------
  48. IMPLEMENT_ELEMENT_FACTORY( DmeSourceCollisionModel, CDmeSourceCollisionModel );
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. void CDmeSourceCollisionModel::OnConstruction()
  53. {
  54. }
  55. void CDmeSourceCollisionModel::OnDestruction()
  56. {
  57. }
  58. //-----------------------------------------------------------------------------
  59. // These can be built from DCC makefiles
  60. //-----------------------------------------------------------------------------
  61. const char **CDmeSourceCollisionModel::GetSourceMakefileTypes()
  62. {
  63. return s_pSkinMakeFiles;
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Hook into datamodel
  67. //-----------------------------------------------------------------------------
  68. IMPLEMENT_ELEMENT_FACTORY( DmeSourceAnimation, CDmeSourceAnimation );
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. void CDmeSourceAnimation::OnConstruction()
  73. {
  74. m_AnimationName.Init( this, "animationName" );
  75. m_SourceAnimationName.Init( this, "sourceAnimationName" );
  76. }
  77. void CDmeSourceAnimation::OnDestruction()
  78. {
  79. }
  80. //-----------------------------------------------------------------------------
  81. // These can be built from DCC makefiles
  82. //-----------------------------------------------------------------------------
  83. static const char *s_pAnimationMakeFiles[] =
  84. {
  85. "DmeMayaAnimationMakefile",
  86. "DmeXSIAnimationMakefile",
  87. NULL
  88. };
  89. const char **CDmeSourceAnimation::GetSourceMakefileTypes()
  90. {
  91. return s_pAnimationMakeFiles;
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Hook into datamodel
  95. //-----------------------------------------------------------------------------
  96. IMPLEMENT_ELEMENT_FACTORY( DmeMDLMakefile, CDmeMDLMakefile );
  97. //-----------------------------------------------------------------------------
  98. // Purpose:
  99. //-----------------------------------------------------------------------------
  100. void CDmeMDLMakefile::OnConstruction()
  101. {
  102. m_hMDL = CreateElement< CDmeMDL >( "MDLMakefile Preview" );
  103. m_bFlushMDL = false;
  104. }
  105. void CDmeMDLMakefile::OnDestruction()
  106. {
  107. DestroyElement( m_hMDL.Get() );
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Returns source types
  111. //-----------------------------------------------------------------------------
  112. static DmeMakefileType_t s_pSourceTypes[] =
  113. {
  114. { "DmeSourceSkin", "Skin", true, "makefiledir:models\\dmx", "*.dmx", "Valve DMX File (*.dmx)" },
  115. { "DmeSourceAnimation", "Animation", false, "makefiledir:animations\\dmx", "*.dmx", "Valve DMX File (*.dmx)" },
  116. { "DmeSourceCollisionModel", "Collision Model", true, "makefiledir:models\\dmx", "*.dmx", "Valve DMX File (*.dmx)" },
  117. { NULL, NULL, false, NULL, NULL, NULL },
  118. };
  119. DmeMakefileType_t* CDmeMDLMakefile::GetSourceTypes()
  120. {
  121. return s_pSourceTypes;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Makefile type
  125. //-----------------------------------------------------------------------------
  126. static DmeMakefileType_t s_MakefileType =
  127. {
  128. "DmeMDLMakefile", "Model", true, "contentdir:models", "*.dmx", "Valve Model MakeFile (*.dmx)"
  129. };
  130. DmeMakefileType_t *CDmeMDLMakefile::GetMakefileType()
  131. {
  132. return &s_MakefileType;
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Add, remove sources
  136. //-----------------------------------------------------------------------------
  137. void CDmeMDLMakefile::SetSkin( const char *pFullPath )
  138. {
  139. RemoveAllSources( "DmeSourceSkin" );
  140. AddSource( "DmeSourceSkin", pFullPath );
  141. }
  142. void CDmeMDLMakefile::AddAnimation( const char *pFullPath )
  143. {
  144. AddSource( "animation", pFullPath );
  145. }
  146. void CDmeMDLMakefile::RemoveAnimation( const char *pFullPath )
  147. {
  148. RemoveSource( "animation", pFullPath );
  149. }
  150. void CDmeMDLMakefile::RemoveAllAnimations( )
  151. {
  152. RemoveAllSources( "animation" );
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Inherited classes should re-implement these methods
  156. //-----------------------------------------------------------------------------
  157. CDmElement *CDmeMDLMakefile::CreateOutputElement( )
  158. {
  159. if ( m_bFlushMDL )
  160. {
  161. // Flush the model out of the cache; detach it from the MDL
  162. MDLHandle_t h = m_hMDL->GetMDL();
  163. if ( h != MDLHANDLE_INVALID )
  164. {
  165. g_pMDLCache->Flush( h );
  166. }
  167. m_bFlushMDL = false;
  168. }
  169. m_hMDL->SetMDL( MDLHANDLE_INVALID );
  170. // FIXME: Should we ask the tool (studiomdl) for this?
  171. // Should we have output type names? Not sure yet..
  172. // Doing the simplest thing first.
  173. char pOutputName[MAX_PATH];
  174. Q_FileBase( GetFileName(), pOutputName, sizeof(pOutputName) );
  175. if ( !pOutputName[0] )
  176. return m_hMDL.Get();
  177. char pOutputDir[MAX_PATH];
  178. GetOutputDirectory( pOutputDir, sizeof(pOutputDir) );
  179. if ( !pOutputDir[0] )
  180. return m_hMDL.Get();
  181. Q_StripTrailingSlash( pOutputDir );
  182. char pFullPath[MAX_PATH];
  183. Q_snprintf( pFullPath, sizeof(pFullPath), "%s\\%s.mdl", pOutputDir, pOutputName );
  184. char pRelativePath[MAX_PATH];
  185. g_pFullFileSystem->FullPathToRelativePathEx( pFullPath, "GAME", pRelativePath, sizeof( pRelativePath ) );
  186. MDLHandle_t h = g_pMDLCache->FindMDL( pRelativePath );
  187. m_hMDL->SetMDL( h );
  188. return m_hMDL.Get();
  189. }
  190. void CDmeMDLMakefile::DestroyOutputElement( CDmElement *pOutput )
  191. {
  192. m_bFlushMDL = true;
  193. }
  194. //-----------------------------------------------------------------------------
  195. // Compile assets
  196. //-----------------------------------------------------------------------------
  197. static const char *s_pOutputExtensions[] =
  198. {
  199. "dx80.vtx",
  200. "dx90.vtx",
  201. "sw.vtx",
  202. "mdl",
  203. "vvd",
  204. "phy",
  205. NULL
  206. };
  207. void CDmeMDLMakefile::GetOutputs( CUtlVector<CUtlString> &fullPaths )
  208. {
  209. fullPaths.RemoveAll();
  210. // FIXME: Should we ask the tool (studiomdl) for this?
  211. // Should we have output type names? Not sure yet..
  212. // Doing the simplest thing first.
  213. char pOutputName[MAX_PATH];
  214. Q_FileBase( GetFileName(), pOutputName, sizeof(pOutputName) );
  215. if ( !pOutputName[0] )
  216. return;
  217. char pOutputDir[MAX_PATH];
  218. GetOutputDirectory( pOutputDir, sizeof(pOutputDir) );
  219. if ( !pOutputDir[0] )
  220. return;
  221. Q_StripTrailingSlash( pOutputDir );
  222. char pFullPath[MAX_PATH];
  223. for ( int i = 0; s_pOutputExtensions[i]; ++i )
  224. {
  225. Q_snprintf( pFullPath, sizeof(pFullPath), "%s\\%s.%s", pOutputDir, pOutputName, s_pOutputExtensions[i] );
  226. fullPaths.AddToTail( pFullPath );
  227. }
  228. }