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.

288 lines
8.2 KiB

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