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.

1429 lines
47 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Code to support the uploading of user submitted items
  4. //
  5. //=============================================================================
  6. #ifndef itemtest_H
  7. #define itemtest_H
  8. #if defined( _WIN32 )
  9. #pragma once
  10. #endif
  11. // Valve includes
  12. #include "tier1/fmtstr.h"
  13. #include "tier1/KeyValues.h"
  14. #include "tier1/utlmap.h"
  15. #include "tier1/utlbuffer.h"
  16. #include "tier1/utlstring.h"
  17. #include "tier1/utlvector.h"
  18. #include "tier1/refcount.h"
  19. #include "tier1/smartptr.h"
  20. //-----------------------------------------------------------------------------
  21. //
  22. //-----------------------------------------------------------------------------
  23. class CDmeDag;
  24. class CDmElement;
  25. class CDmeMaterial;
  26. class CDmeModel;
  27. class CItemTestManifest;
  28. class CTargetVMT;
  29. class CTargetQC;
  30. class CTargetMDL;
  31. #ifdef DECLARE_LOGGING_CHANNEL
  32. DECLARE_LOGGING_CHANNEL( LOG_ITEMTEST );
  33. #endif
  34. enum ItemtestLogLevel_t
  35. {
  36. kItemtest_Log_Info,
  37. kItemtest_Log_Warning,
  38. kItemtest_Log_Error,
  39. };
  40. //=============================================================================
  41. //
  42. //=============================================================================
  43. class CItemLog
  44. {
  45. public:
  46. CItemLog( CItemLog *pItemLog = NULL ) : m_pItemLog( pItemLog ) { }
  47. void SetItemLog( CItemLog *pItemLog ) { m_pItemLog = pItemLog; }
  48. void Msg( const char *pszFormat, ... ) const;
  49. void Warning( const char *pszFormat, ... ) const;
  50. void Error( const char *pszFormat, ... ) const;
  51. virtual void Log( ItemtestLogLevel_t nLogLevel, const char *pszMessage ) const;
  52. public:
  53. CItemLog *m_pItemLog;
  54. };
  55. //=============================================================================
  56. //
  57. //=============================================================================
  58. class CItemUpload
  59. {
  60. public:
  61. // Returns the Steam AccountID as an 0x prefixed hex string, true on success, false on failure
  62. static bool GetSteamId( CUtlString &sSteamId );
  63. // Returns $VPROJECT, true on success, false on failure
  64. static bool GetVProjectDir( CUtlString &sVProjectDir );
  65. // Returns FileName( GetVProjectDir() ), true on success, false on failure
  66. static bool GetVMod( CUtlString &sVMod );
  67. // Returns $SOURCESDK_content/GetVMod(), true on success, false on failure
  68. static bool GetContentDir( CUtlString &sSDKContentDir );
  69. // Gets the SourceSDK path from the path of the executable
  70. static bool GetSourceSDKFromExe( CUtlString &sSourceSDK, CUtlString &sSourceSDKBin );
  71. static bool GetBinDirectory( CUtlString &sSDKBinDir );
  72. static bool RunCommandLine( const char *pszCmdLine, const char *pszWorkingDir, CItemLog *pLog );
  73. static bool FileExists( const char *pszFilename );
  74. static bool CopyFiles( const char *pszSourceDir, const char *pszPattern, const char *pszDestDir );
  75. static bool CopyFile( const char *pszSourceFile, const char *pszDestFile );
  76. static bool CreateDirectory( const char *pszDirectory );
  77. static bool GetDevMode() { return m_bDev; }
  78. static void SetDevMode( bool bDev ) { m_bDev = bDev; }
  79. static bool IgnoreEnvironmentVariables() { return m_bIgnoreEnvVars; }
  80. static void SetIgnoreEnvironmentVariables( bool bIgnore ) { m_bIgnoreEnvVars = bIgnore; }
  81. static void ForceSteamID( const char *pszSteamID ) { m_szForcedSteamID = pszSteamID; }
  82. static const char *GetForcedSteamID( void ) { return m_szForcedSteamID; }
  83. static bool GetP4() { return m_bP4; }
  84. static void SetP4( bool bP4 ) { m_bP4 = bP4; }
  85. static bool IsSameFile( const char *szPath1, const char *szPath2 );
  86. static bool GetCurrentExecutableFileName( CUtlString &sCurrentExecutableFileName );
  87. static bool GetSteamAppInstallLocation( CUtlString &sSteamAppInstallLocation, int nAppId );
  88. static bool InitManifest( void );
  89. static CItemTestManifest *Manifest( void ) { return m_pItemTestManifest; }
  90. // Remove punctuation and other special characters from an item name
  91. static bool SanitizeName( const char *pszName, CUtlString &sCleanName );
  92. protected:
  93. static bool m_bDev;
  94. static bool m_bIgnoreEnvVars;
  95. static bool m_bP4;
  96. static CUtlString m_szForcedSteamID;
  97. static CItemTestManifest *m_pItemTestManifest;
  98. };
  99. int GetClassCount();
  100. const char *GetClassString( int i );
  101. const char *GetClassString( const char *pszClassString );
  102. int GetClassIndex( const char *pszClassString );
  103. typedef CUtlVector< CUtlString > ExtensionList;
  104. //=============================================================================
  105. //
  106. //=============================================================================
  107. class CItemTestManifest
  108. {
  109. public:
  110. CItemTestManifest( const char *pszManifestFile, CItemLog *pItemLog );
  111. bool IsValid( void ) { return m_pManifestKV != NULL; }
  112. int GetNumClasses( void ) { return m_vecClasses.Count(); }
  113. const char *GetClass( int nClass ) { return (nClass >= 0 && nClass < m_vecClasses.Count()) ? m_vecClasses[nClass].Get() : NULL; }
  114. const char *GetClassVMTTemplate( int nClass ) { return (nClass >= 0 && nClass < m_vecClassTemplates.Count()) ? m_vecClassTemplates[nClass] : NULL; }
  115. bool HasClassVMTTemplates() { return m_vecClassTemplates.Count() > 0; }
  116. int GetNumMaterialTypes( void ) { return m_vecMaterialTypes.Count(); }
  117. const char *GetMaterialType( int nMaterial ) { return (nMaterial >= 0 && nMaterial < m_vecMaterialTypes.Count()) ? m_vecMaterialTypes[nMaterial].pszMaterialType : NULL; }
  118. int GetMaterialType( const char *pszMaterialType );
  119. int GetDefaultMaterialType( void ) { return m_nDefaultMaterialType; }
  120. int GetNumMaterialSkins( void ) { return max(m_vecMaterialSkins.Count(), 1); }
  121. const char *GetMaterialSkin( int nMaterial ) { return (nMaterial >= 0 && nMaterial < m_vecMaterialSkins.Count()) ? m_vecMaterialSkins[nMaterial].pszMaterialSkin : NULL; }
  122. int GetMaterialSkin( const char *pszMaterialSkin );
  123. const char *GetMaterialSkinFilenameAppend( int nMaterial ) { return (nMaterial >= 0 && nMaterial < m_vecMaterialSkins.Count()) ? m_vecMaterialSkins[nMaterial].pszFilenameAppend : ""; }
  124. int GetDefaultMaterialSkin( void ) { return m_nDefaultMaterialSkin; }
  125. int GetNumTextureTypes( void ) { return m_vecTextureTypes.Count(); }
  126. const char *GetTextureType( int nTexture ) { return (nTexture >= 0 && nTexture < m_vecTextureTypes.Count()) ? m_vecTextureTypes[nTexture].pszTextureType : NULL; }
  127. bool IsTextureTypeRequired( int nTexture ) { return (nTexture >= 0 && nTexture < m_vecTextureTypes.Count()) ? !m_vecTextureTypes[nTexture].bOptional : false; }
  128. int GetTextureType( const char *pszTextureType );
  129. KeyValues *GetTextureAddToVTEXConfig( const char *pszTextureType );
  130. int GetNumIconTypes( void ) { return m_vecIconTypes.Count(); }
  131. const char *GetIconType( int nIcon ) { return (nIcon >= 0 && nIcon < m_vecIconTypes.Count()) ? m_vecIconTypes[nIcon].pszIconType : NULL; }
  132. int GetIconType( const char *pszIconType );
  133. const char *GetIconFilenameAppend( int nIcon ) { return (nIcon >= 0 && nIcon < m_vecIconTypes.Count()) ? m_vecIconTypes[nIcon].pszFilenameAppend : ""; }
  134. bool GetIconDimensions( int nIcon, int &nWidth, int &nHeight );
  135. KeyValues *GetIconAddToVTEXConfig( int nIcon ) { return (nIcon >= 0 && nIcon < m_vecIconTypes.Count()) ? m_vecIconTypes[nIcon].pkvAddToVTEXConfig : NULL; }
  136. KeyValues *GetIconVMTTemplate( int nIcon ) { return (nIcon >= 0 && nIcon < m_vecIconTypes.Count()) ? m_vecIconTypes[nIcon].pkvVMTTemplate : NULL; }
  137. ExtensionList *GetMDLExtensions( void ) { return &m_vecMDLExtensions; }
  138. ExtensionList *GetAnimationMDLExtentions( void ) { return &m_vecAnimationMDLExtensions; }
  139. const char *GetVMTVarForTextureType( const char *pszTexture );
  140. const char *GetItemDirectory( void ) { return m_strItemDirectoryOverride.IsEmpty() ? m_pItemDirectory : m_strItemDirectoryOverride.String(); }
  141. const char *GetAnimationDirectory( void ) { return m_strAnimationDirectoryOverride.IsEmpty() ? m_pAnimationDirectory : m_strAnimationDirectoryOverride.String(); }
  142. const char *GetIconDirectory( void ) { return m_strIconDirectoryOverride.IsEmpty() ? m_pIconDirectory : m_strIconDirectoryOverride.String(); }
  143. const char *GetZipSourceDirectory( void ) { return m_pZipSourceDirectory; }
  144. const char *GetZipOutputDirectory( void ) { return m_pZipOutputDirectory; }
  145. const char *GetQCTemplate( void ) const { return m_pQCTemplate; }
  146. const char *GetQCITemplate( void ) const { return m_pQCITemplate; }
  147. int GetQCLODDistance( int nLOD ) { return (nLOD > 0 && nLOD <= m_vecQCLODDistances.Count()) ? m_vecQCLODDistances[nLOD-1] : nLOD; }
  148. bool UseTerseMessages( void ) { return m_bTerseMessages; }
  149. bool GetItemPathUsesSteamId( void ) { return m_bItemPathUsesSteamId; }
  150. void SetItemDirectoryOverride( const char *pszItemDirOverride ) { m_strItemDirectoryOverride = pszItemDirOverride; }
  151. void SetAnimationDirectoryOverride( const char *pszAnimationDirOverride ) { m_strAnimationDirectoryOverride = pszAnimationDirOverride; }
  152. void SetIconDirectoryOverride( const char *pszIconDirOverride ) { m_strIconDirectoryOverride = pszIconDirOverride; }
  153. private:
  154. bool ParseStringsFromManifest( KeyValues *pKV, const char *pszKeyName, CUtlVector< CUtlString > &vecList );
  155. private:
  156. CItemLog *m_pItemLog;
  157. KeyValues *m_pManifestKV;
  158. struct material_type_manifest_t
  159. {
  160. const char *pszMaterialType;
  161. };
  162. struct material_skin_manifest_t
  163. {
  164. const char *pszMaterialSkin;
  165. const char *pszFilenameAppend;
  166. };
  167. struct texture_type_manifest_t
  168. {
  169. const char *pszTextureType;
  170. KeyValues *pkvAddToVTEXConfig;
  171. bool bOptional;
  172. };
  173. struct icon_type_manifest_t
  174. {
  175. const char *pszIconType;
  176. const char *pszFilenameAppend;
  177. int nWidth;
  178. int nHeight;
  179. KeyValues *pkvAddToVTEXConfig;
  180. KeyValues *pkvVMTTemplate;
  181. };
  182. CUtlString m_strItemDirectoryOverride;
  183. CUtlString m_strAnimationDirectoryOverride;
  184. CUtlString m_strIconDirectoryOverride;
  185. const char *m_pItemDirectory;
  186. const char *m_pAnimationDirectory;
  187. const char *m_pIconDirectory;
  188. const char *m_pZipSourceDirectory;
  189. const char *m_pZipOutputDirectory;
  190. const char *m_pQCTemplate;
  191. const char *m_pQCITemplate;
  192. CUtlVector< int > m_vecQCLODDistances;
  193. CUtlVector< CUtlString > m_vecClasses;
  194. CUtlVector<material_type_manifest_t> m_vecMaterialTypes;
  195. CUtlVector<material_skin_manifest_t> m_vecMaterialSkins;
  196. CUtlVector<texture_type_manifest_t> m_vecTextureTypes;
  197. CUtlVector<icon_type_manifest_t> m_vecIconTypes;
  198. CUtlVector<const char *> m_vecClassTemplates;
  199. CUtlMap< CUtlString, CUtlString > m_vecVMTTextureRemaps;
  200. ExtensionList m_vecMDLExtensions;
  201. ExtensionList m_vecAnimationMDLExtensions;
  202. bool m_bTerseMessages;
  203. bool m_bItemPathUsesSteamId;
  204. int m_nDefaultMaterialType;
  205. int m_nDefaultMaterialSkin;
  206. };
  207. //=============================================================================
  208. //
  209. //=============================================================================
  210. template < class T >
  211. class CItemUploadGame : public CItemUpload
  212. {
  213. public:
  214. static const Vector &GetBipHead( int i );
  215. static const RadianEuler &GetBipHeadRotation( int i );
  216. static const Vector s_vBipHead[];
  217. static const RadianEuler s_eBipHead[];
  218. };
  219. //=============================================================================
  220. // See: http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
  221. //=============================================================================
  222. class CItemUploadTF : public CItemUploadGame< CItemUploadTF >
  223. {
  224. public:
  225. // These map to indices in s_szClassStrings
  226. enum ClassType_t
  227. {
  228. kDemo,
  229. kEngineer,
  230. kHeavy,
  231. kMedic,
  232. kPyro,
  233. kScout,
  234. kSniper,
  235. kSoldier,
  236. kSpy,
  237. kClassCount
  238. };
  239. };
  240. //-----------------------------------------------------------------------------
  241. //
  242. //-----------------------------------------------------------------------------
  243. class CAsset;
  244. //=============================================================================
  245. //
  246. //=============================================================================
  247. class CTargetBase : public CItemLog
  248. {
  249. public:
  250. virtual ~CTargetBase() {}
  251. // Is this target valid? A target is valid if all of it's inputs are valid and the settings make sense
  252. // This function can do any sort of validity checking required. Not called IsValid to avoid confusion
  253. // with CSmartPtr::IsValid which most CTargetBase items are wrapped in. If returns true, sMsg
  254. // string is unchanged, if returns false, sMsg contains description of first encountered problem.
  255. virtual bool IsOk( CUtlString &sMsg ) const = 0;
  256. // Does the output of this go into the content tree or the game tree
  257. virtual bool IsContent() const { return false; }
  258. // Does the output of this go under the "models" path
  259. virtual bool IsModelPath() const { return true; }
  260. // Get item directory path for this target
  261. virtual const char *GetItemDirectory() const;
  262. // Returns a string indicating the type of target, i.e. MDL, QC, DMX, VMT, VTF, TGA, etc...
  263. virtual const char *GetTypeString() const = 0;
  264. // Return the number of files that are output from this CTarget, essentially the number of extensions defined
  265. int GetOutputCount() const;
  266. // Flags specifying how a path should be returned. See flag usage below.
  267. enum PathFlags
  268. {
  269. PATH_FLAG_FILE = 0x20, // If set the filename is included in the returned path
  270. PATH_FLAG_EXTENSION = 0x10, // If set and PATH_FLAG_FILE, the returned path will include the extension on the filename
  271. PATH_FLAG_PATH = 0x08, // If set the pathname is included in the returned path
  272. PATH_FLAG_ABSOLUTE = 0x04, // If set and PATH_FLAG_PATH, the returned path will be absolute (default relative)
  273. PATH_FLAG_MODELS = 0x02, // if not set and PATH_FLAG_PATH & !PATH_FLAG_ABSOLUTE, the returned path will include the 'models' prefix, !MODELS implies !PREFIX
  274. PATH_FLAG_PREFIX = 0x01, // If not set and PATH_FLAG_PATH & !PATH_FLAG_ABSOLUTE, the returned path will include the prefix (materials | materialsrc)
  275. PATH_FLAG_ALL = 0x0ffff,
  276. PATH_FLAG_ZIP = 0x10000
  277. };
  278. // Gets the specified output path with the specified flags. See flag usage below. sOutputPath cleared on error.
  279. bool GetOutputPath( CUtlString &sOutputPath, int nIndex = 0, uint nPathFlags = PATH_FLAG_ALL ) const;
  280. // Appends all output paths to the passed array with the specified flags. See flag usage below. If bRecurse is true, calls it for each output CTargetBase as well
  281. bool GetOutputPaths( CUtlVector< CUtlString > &sOutputPaths, uint nPathFlags = PATH_FLAG_ALL, bool bRecurse = false ) const;
  282. // First compile all inputs and then compile this target which produces the expected output files
  283. // Can do all sorts of things, like load and save files or call vtex, studiomdl, etc...
  284. virtual bool Compile();
  285. // Returns the output filenames for this target and optionally for all inputs recursively, either relative or absolute
  286. bool GetOutputPaths( CUtlVector< CUtlString > &sOutputPaths, bool bRelative, bool bRecurse, bool bExtension, bool bPrefix = true ) const;
  287. // Returns the input filenames for this target and optionally for all inputs recursively, either relative or absolute
  288. virtual bool GetInputPaths( CUtlVector< CUtlString > &sInputPaths, bool bRelative = true, bool bRecurse = true, bool bExtension = true );
  289. // Gets all of the CTargetBase inputs for this CTargetBase
  290. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const
  291. {
  292. AssertMsg( 0, "Implement CTargetBase::GetInputs for derived class\n" );
  293. return false;
  294. }
  295. // Returns the extensions for the outputs of this CTargetBase. Extensions should include the .
  296. virtual const ExtensionList *GetExtensionsAndCount( void ) const
  297. {
  298. return NULL;
  299. }
  300. // Returns a prefix between the mod directory and the relative path, used for 'materials' & 'materialsrc'
  301. virtual const char *GetPrefix() const { return NULL; }
  302. // The name of this target without any extension, i.e. the filename where it should be written
  303. virtual void GetName( CUtlString &sName ) const;
  304. void SetCustomOutputName( const char *pszCustomOutputName ) { m_strCustomOutputName = pszCustomOutputName; }
  305. const CUtlString &GetCustomOutputName() const { return m_strCustomOutputName; }
  306. virtual void SetNameSuffix( const char *pszSuffix ) { m_sNameSuffix = pszSuffix; }
  307. virtual const char *GetNameSuffix() const { return m_sNameSuffix.Get(); }
  308. virtual void SetCustomRelativeDir( const char *pszCustomRelativeDir ) { m_sCustomRelativeDir = pszCustomRelativeDir; }
  309. virtual const char *GetCustomRelativeDir() const { return m_sCustomRelativeDir.IsEmpty() ? NULL : m_sCustomRelativeDir.Get(); }
  310. // The name of the asset that owns this target
  311. virtual const CUtlString &GetAssetName() const;
  312. // The asset that owns this target
  313. CAsset *Asset() const;
  314. virtual void UpdateManifest( KeyValues *pKv ) = 0;
  315. void SetIgnoreP4( bool bIgnoreP4 ) { m_bIgnoreP4 = bIgnoreP4; }
  316. KeyValues *GetCustomKeyValues() { return m_kvCustomKeys; }
  317. void SetCustomModPath( const char *pszCustomModPath ) { m_sCustomModPath = pszCustomModPath; }
  318. const char *GetCustomModPath() const { return m_sCustomModPath.IsEmpty() ? NULL : m_sCustomModPath.String(); }
  319. protected:
  320. friend class CAsset;
  321. friend class CRefCountAccessor;
  322. CTargetBase( CAsset *pAsset, const CTargetBase *pTargetParent );
  323. void AddRef()
  324. {
  325. ++m_nRefCount;
  326. }
  327. void Release()
  328. {
  329. Assert( m_nRefCount > 0 );
  330. --m_nRefCount;
  331. if ( m_nRefCount == 0 )
  332. {
  333. delete this;
  334. }
  335. }
  336. virtual bool CheckFile( const char *pszFilename ) const;
  337. // Gets the directory name for this asset. See PathFlags_t above.
  338. // PATH_FLAG_FILE & PATH_FLAG_EXTENSION are not meaningful for this function
  339. virtual bool GetDirName( CUtlString &sDirName, uint nPathFlags = PATH_FLAG_ALL ) const;
  340. // Create the output directory for this target if necessary
  341. bool CreateOutputDirectory() const;
  342. void AddOrEditP4File( const char *pszFilePath );
  343. private:
  344. CAsset *m_pAsset; // The asset that owns this target
  345. const CTargetBase *m_pTargetParent;
  346. CUtlString m_sNameSuffix;
  347. CUtlString m_sCustomRelativeDir;
  348. CUtlString m_strCustomOutputName; // Name of output file
  349. int m_nRefCount;
  350. bool m_bIgnoreP4;
  351. KeyValuesAD m_kvCustomKeys;
  352. CUtlString m_sCustomModPath;
  353. };
  354. //=============================================================================
  355. //
  356. //=============================================================================
  357. class CTargetTGA : public CTargetBase
  358. {
  359. public:
  360. virtual ~CTargetTGA();
  361. // From CTargetBase
  362. virtual bool IsOk( CUtlString &sMsg ) const;
  363. virtual bool IsContent() const { return true; }
  364. virtual bool IsModelPath() const;
  365. virtual const char *GetTypeString() const { return "TGA"; }
  366. virtual bool Compile();
  367. virtual bool GetInputPaths( CUtlVector< CUtlString > &sInputPaths, bool bRelative = true, bool bRecurse = true, bool bExtension = true );
  368. // No CTargetBase inputs for CTargetTGA
  369. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const { return true; }
  370. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  371. virtual const char *GetPrefix() const;
  372. virtual void GetName( CUtlString &sName ) const;
  373. void Clear();
  374. // An input texture file... TGA, PSD... something else?
  375. bool SetInputFile( const char *pszFilename );
  376. const CUtlString &GetInputFile() const;
  377. int GetWidth() const { return m_nWidth; }
  378. int GetHeight() const { return m_nHeight; }
  379. int GetChannelCount() const { return m_nChannelCount; }
  380. bool HasAlpha() const { return m_bAlpha; }
  381. virtual void UpdateManifest( KeyValues *pKv );
  382. void SetNoNiceFiltering( bool bNoNice ) { m_bNoNiceFiltering = bNoNice; }
  383. void SetChannelCount( int nChannels ) { m_nChannelCount = nChannels; }
  384. protected:
  385. friend class CAsset;
  386. friend class CTargetVMT;
  387. public:
  388. // Made public so we can load and validate assets before building them
  389. CTargetTGA( CAsset *pAsset, const CTargetVMT *pTargetVMT );
  390. protected:
  391. template < class T > static T NearestPowerOfTwo( T nVal );
  392. CUtlString m_sInputFile; // Arbitrary input file
  393. CUtlString m_sFileBase; // Name of file without extension or path
  394. CUtlString m_sExtension; // Extension of m_sInputFile
  395. mutable CUtlString m_sPrefix;
  396. enum {
  397. IMAGE_FILE_UNKNOWN,
  398. IMAGE_FILE_TGA,
  399. IMAGE_FILE_PSD,
  400. IMAGE_FILE_VTF
  401. } m_nSrcImageType;
  402. int m_nWidth;
  403. int m_nHeight;
  404. int m_nChannelCount;
  405. bool m_bNoNiceFiltering;
  406. bool m_bAlpha;
  407. bool m_bPowerOfTwo;
  408. const CTargetVMT *m_pTargetVMT;
  409. };
  410. //=============================================================================
  411. //
  412. //=============================================================================
  413. class CTargetVTF : public CTargetBase
  414. {
  415. public:
  416. virtual ~CTargetVTF();
  417. // From CTargetBase
  418. virtual bool IsOk( CUtlString &sMsg ) const { return m_pTargetTGA->IsOk( sMsg ); }
  419. virtual bool IsContent() const { return false; }
  420. virtual bool IsModelPath() const;
  421. virtual const char *GetTypeString() const { return "VTF"; }
  422. virtual bool Compile();
  423. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const;
  424. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  425. virtual const char *GetPrefix() const;
  426. virtual void GetName( CUtlString &sName ) const;
  427. virtual void SetNameSuffix( const char *pszSuffix ) { m_pTargetTGA->SetNameSuffix( pszSuffix ); }
  428. virtual const char *GetNameSuffix() const { return m_pTargetTGA->GetNameSuffix(); }
  429. bool SetInputFile( const char *pszFilename ) { return m_pTargetTGA->SetInputFile( pszFilename ); }
  430. const CUtlString &GetInputFile() const { return m_pTargetTGA->GetInputFile(); }
  431. bool HasAlpha() const { return m_pTargetTGA->HasAlpha(); }
  432. virtual void UpdateManifest( KeyValues *pKV )
  433. {
  434. m_pTargetTGA->UpdateManifest( pKV );
  435. }
  436. CTargetTGA *GetTargetTGA( void ) const { return m_pTargetTGA.IsValid() ? m_pTargetTGA.GetObject() : NULL; }
  437. protected:
  438. friend class CAsset;
  439. CTargetVTF( CAsset *pAsset, const CTargetVMT *pTargetVMT );
  440. const CTargetVMT *m_pTargetVMT;
  441. CSmartPtr< CTargetTGA > m_pTargetTGA;
  442. };
  443. #define kInvalidMaterialType -1
  444. #define kInvalidMaterialSkin -1
  445. #define LEGACY_MATERIALTYPE_PRIMARY 1
  446. #define LEGACY_MATERIALTYPE_SECONDARY 2
  447. //=============================================================================
  448. //
  449. //=============================================================================
  450. class CTargetVMT : public CTargetBase
  451. {
  452. public:
  453. enum ColorAlpha_t
  454. {
  455. kNoColorAlpha,
  456. kTransparency,
  457. kPaintable,
  458. kColorSpecPhong
  459. };
  460. static const char *ColorAlphaTypeToString( ColorAlpha_t nColorAlphaType )
  461. {
  462. static const char *pszColorAlphaTypeStr[] = {
  463. "NoColorAlpha",
  464. "Transparency",
  465. "Paintable",
  466. "ColorSpecPhong"
  467. };
  468. if ( nColorAlphaType < 0 || nColorAlphaType >= ARRAYSIZE( pszColorAlphaTypeStr ) )
  469. {
  470. return "Unknown";
  471. }
  472. return pszColorAlphaTypeStr[ nColorAlphaType ];
  473. }
  474. static ColorAlpha_t StringToColorAlphaType( const char *pszUserData )
  475. {
  476. if ( StringHasPrefix( pszUserData, "T" ) )
  477. return CTargetVMT::kTransparency;
  478. if ( StringHasPrefix( pszUserData, "P" ) )
  479. return CTargetVMT::kPaintable;
  480. if ( StringHasPrefix( pszUserData, "S" ) )
  481. return CTargetVMT::kColorSpecPhong;
  482. return CTargetVMT::kNoColorAlpha;
  483. }
  484. enum NormalAlpha_t
  485. {
  486. kNoNormalAlpha,
  487. kNormalSpecPhong
  488. };
  489. static const char *NormalAlphaTypeToString( NormalAlpha_t nNormalAlphaType )
  490. {
  491. static const char *pszNormalAlphaTypeStr[] = {
  492. "NoNormalAlpha",
  493. "NormalSpecPhong"
  494. };
  495. if ( nNormalAlphaType < 0 || nNormalAlphaType >= ARRAYSIZE( pszNormalAlphaTypeStr ) )
  496. {
  497. return "Unknown";
  498. }
  499. return pszNormalAlphaTypeStr[ nNormalAlphaType ];
  500. }
  501. static NormalAlpha_t StringToNormalAlphaType( const char *pszUserData )
  502. {
  503. if ( StringHasPrefix( pszUserData, "N" ) )
  504. return CTargetVMT::kNormalSpecPhong;
  505. if ( StringHasPrefix( pszUserData, "S" ) )
  506. return CTargetVMT::kNormalSpecPhong;
  507. return CTargetVMT::kNoNormalAlpha;
  508. }
  509. const char *MaterialTypeToString( int nMaterialType );
  510. static int StringToMaterialType( const char *pszUserData );
  511. // From CTargetBase
  512. virtual bool IsOk( CUtlString &sMsg ) const;
  513. virtual bool IsContent() const { return false; }
  514. virtual const char *GetTypeString() const { return "VMT"; }
  515. virtual bool Compile();
  516. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  517. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const;
  518. virtual const char *GetPrefix() const { return "materials"; }
  519. virtual void GetName( CUtlString &sName ) const;
  520. void SetMaterialId( const char *pszMaterialId );
  521. virtual void GetMaterialId( CUtlString &sMaterialId ) const { sMaterialId = m_sMaterialId; }
  522. const CUtlString &GetMaterialId() const { return m_sMaterialId; }
  523. bool SetTargetVTF( const char *pszTextureType, const char *pszFilename, int nSkinIndex = CItemUpload::Manifest()->GetDefaultMaterialSkin() );
  524. void SetColorAlphaType( ColorAlpha_t nColorAlphaType ) { m_nColorAlphaType = nColorAlphaType; }
  525. ColorAlpha_t GetColorAlphaType() const { return m_nColorAlphaType; }
  526. void SetNormalAlphaType( NormalAlpha_t nNormalAlphaType ) { m_nNormalAlphaType = nNormalAlphaType; }
  527. NormalAlpha_t GetNormalAlphaType() const { return m_nNormalAlphaType; }
  528. bool SetMaterialType( int nMaterialType );
  529. int GetMaterialType() const;
  530. void SetDuplicate( int nMaterialType );
  531. bool GetDuplicate() const { return m_bDuplicate; }
  532. void SetTargetResolution( int nWidth, int nHeight ) { m_nTargetWidth = nWidth; m_nTargetHeight = nHeight; }
  533. int GetTargetWidth( void ) const { return m_nTargetWidth; }
  534. int GetTargetHeight( void ) const { return m_nTargetHeight; }
  535. int GetNumTargetVTFS( int nSkinIndex )
  536. {
  537. if ( nSkinIndex >= 0 && nSkinIndex < m_vecTargetVTFs.Count() )
  538. {
  539. return m_vecTargetVTFs[nSkinIndex].Count();
  540. }
  541. return 0;
  542. }
  543. CTargetVTF *GetTargetVTF( int iVTF, int nSkinIndex = 0 )
  544. {
  545. if ( nSkinIndex >= 0 && nSkinIndex < m_vecTargetVTFs.Count() )
  546. {
  547. if ( iVTF >= 0 && iVTF < m_vecTargetVTFs[nSkinIndex].Count() )
  548. return m_vecTargetVTFs[nSkinIndex][iVTF].IsValid() ? m_vecTargetVTFs[nSkinIndex][iVTF].GetObject() : NULL;
  549. }
  550. return NULL;
  551. }
  552. const char *GetTextureTypeForTGA( CTargetTGA *pTGA ) const
  553. {
  554. FOR_EACH_VEC( m_vecTargetVTFs, i )
  555. {
  556. FOR_EACH_VEC( m_vecTargetVTFs[i], j )
  557. {
  558. if ( m_vecTargetVTFs[i][j].IsValid() && m_vecTargetVTFs[i][j]->GetTargetTGA() == pTGA )
  559. return CItemUpload::Manifest()->GetTextureType(j);
  560. }
  561. }
  562. return NULL;
  563. }
  564. virtual KeyValues *GetTextureAddToVTEXConfigForTGA( CTargetTGA *pTGA ) const
  565. {
  566. const char *pszTextureType = GetTextureTypeForTGA( pTGA );
  567. if ( pszTextureType )
  568. {
  569. return CItemUpload::Manifest()->GetTextureAddToVTEXConfig( pszTextureType );
  570. }
  571. return NULL;
  572. }
  573. void SetVMTKV( const KeyValues *pKV, int nSkinIndex = 0 );
  574. KeyValues *GetVMTKV( int nSkinIndex );
  575. void CreateLegacyTemplate( KeyValues *pVMTKV );
  576. virtual void UpdateManifest( KeyValues *pKV );
  577. protected:
  578. friend class CAsset;
  579. CTargetVMT( CAsset *pAsset, const CTargetBase *pTargetParent );
  580. virtual ~CTargetVMT();
  581. KeyValues *m_pVMTKV;
  582. mutable ExtensionList m_vecExtensions;
  583. CUtlVector< CUtlVector< CSmartPtr< CTargetVTF > > > m_vecTargetVTFs;
  584. ColorAlpha_t m_nColorAlphaType;
  585. NormalAlpha_t m_nNormalAlphaType;
  586. int m_nMaterialType;
  587. bool m_bDuplicate;
  588. int m_nTargetWidth;
  589. int m_nTargetHeight;
  590. CUtlString m_sMaterialId;
  591. bool SetTargetVTF( CSmartPtr< CTargetVTF > &pTargetVTF, const char *pszFilename, const char *pszSuffix ) const;
  592. };
  593. //=============================================================================
  594. //
  595. //=============================================================================
  596. class CTargetIcon : public CTargetVMT
  597. {
  598. public:
  599. virtual bool IsModelPath() const { return false; }
  600. virtual const char *GetItemDirectory() const { return CItemUpload::Manifest()->GetIconDirectory(); }
  601. virtual KeyValues *GetTextureAddToVTEXConfigForTGA( CTargetTGA *pTGA ) const { return CItemUpload::Manifest()->GetIconAddToVTEXConfig( m_nIconType ); }
  602. bool SetTargetVTF( const char *pszFilename );
  603. protected:
  604. friend class CAsset;
  605. CTargetIcon( CAsset *pAsset, int nIconType );
  606. int m_nIconType;
  607. };
  608. //=============================================================================
  609. // Inputs OBJ, SMD, DMX -> Outputs DMX in proper place with proper name
  610. //=============================================================================
  611. class CTargetDMX : public CTargetBase
  612. {
  613. public:
  614. virtual ~CTargetDMX();
  615. // From CItemBase
  616. virtual bool IsOk( CUtlString &sMsg ) const;
  617. virtual const char *GetItemDirectory() const
  618. {
  619. return m_strQCITemplate.IsEmpty() ? CItemUpload::Manifest()->GetItemDirectory() : CItemUpload::Manifest()->GetAnimationDirectory();
  620. }
  621. virtual bool IsContent() const { return true; }
  622. virtual const char *GetTypeString() const { return "DMX"; }
  623. virtual bool Compile();
  624. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  625. virtual bool GetInputPaths( CUtlVector< CUtlString > &sInputPaths, bool bRelative = true, bool bRecurse = true, bool bExtension = true );
  626. // No CTargetBase inputs for this target
  627. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const { return true; }
  628. virtual void GetName( CUtlString &sName ) const;
  629. int GetPolyCount() const;
  630. int GetTriangleCount() const;
  631. int GetVertexCount() const;
  632. bool GetAnimationFrameInfo( float& flFrameRate, int& nFrameCount ) const;
  633. bool AreAllMeshesSkinned() const;
  634. const CUtlString &GetInputFile() const;
  635. void SetLod( int nLod ) { m_nLod = nLod; }
  636. int GetLod() const { return m_nLod; }
  637. void SetQCITemplate( const char *pszQCITemplate ) { m_strQCITemplate = pszQCITemplate; }
  638. virtual void UpdateManifest( KeyValues *pKV )
  639. {
  640. CFmtStr sTmp;
  641. sTmp.sprintf( "lod%d", GetLod() );
  642. KeyValues *pLodSubKey = new KeyValues( sTmp.Access() );
  643. pKV->AddSubKey( pLodSubKey );
  644. pLodSubKey->SetString( "filename", GetInputFile().Get() );
  645. CUtlString sOutName;
  646. if ( GetOutputPath( sOutName, 0, PATH_FLAG_PATH | PATH_FLAG_FILE | PATH_FLAG_PREFIX | PATH_FLAG_MODELS | PATH_FLAG_EXTENSION ) )
  647. {
  648. pLodSubKey->SetString( "out_filename", sOutName );
  649. }
  650. pLodSubKey->SetInt( "polyCount", GetPolyCount() );
  651. pLodSubKey->SetInt( "vertexCount", GetVertexCount() );
  652. }
  653. void SetSoundScriptFilePath( const char *pszSoundScriptFile ) { m_strSoundScriptFile = pszSoundScriptFile; }
  654. const char *GetSoundScriptFilePath() const { return m_strSoundScriptFile.String(); }
  655. bool WriteVCD( CUtlBuffer &vcdBuf );
  656. void SetAnimationLoopStartTime( float flStartTime ) { m_flAnimationLoopStartTime = flStartTime; }
  657. protected:
  658. friend class CAsset;
  659. friend class CTargetQC;
  660. CTargetDMX( CAsset *pAsset, const CTargetQC *pTargetQC );
  661. void Clear();
  662. // An input geometry file, SMD, OBJ or DMX
  663. bool SetInputFile( const char *pszFilename );
  664. // Reloads the existing file, called on compile in case user changed something
  665. bool ReloadFile();
  666. bool IsInputObj() const; // Simple test based on extension checking
  667. bool IsInputSmd() const; // Simple test based on extension checking
  668. bool IsInputDmx() const; // Simple test based on extension checking
  669. bool IsInputFbx() const; // Simple test based on extension checking
  670. CDmElement *LoadObj();
  671. CDmElement *LoadSmd();
  672. CDmElement *LoadDmx();
  673. CDmElement *LoadFbx();
  674. void ReplaceMaterials() const;
  675. void SkinToBipHead();
  676. void SkinToBipHead_R( CDmeModel *pDstModel, CDmeDag *pSrcDag, const Vector &vBipHead );
  677. bool OutputQCIFile();
  678. void OutputSounds( CUtlBuffer &buf, int nIndentLevel, CDmElement *pExportedSounds );
  679. // Dependencies/Inputs
  680. CUtlString m_sInputFile; // Arbitrary input file
  681. CUtlString m_sExtension; // Extension of m_sInputFile
  682. CDmElement *m_pDmRoot; // Root of loaded DMX file
  683. CUtlVector< CSmartPtr< CTargetVMT > > m_targetVmtList;
  684. int m_nLod; // The LOD index
  685. CUtlString m_strQCITemplate; // QCI Template for Animation DMX
  686. float m_flAnimationLoopStartTime;
  687. CUtlString m_strSoundScriptFile;
  688. };
  689. //=============================================================================
  690. //
  691. //=============================================================================
  692. class CTargetVCD : public CTargetBase
  693. {
  694. public:
  695. // From CTargetBase
  696. virtual bool IsOk( CUtlString &sMsg ) const { return true; }
  697. virtual bool IsContent() const { return false; }
  698. virtual const char *GetTypeString() const { return "VCD"; }
  699. virtual const char *GetPrefix() const { return "scenes"; }
  700. virtual bool IsModelPath() const { return false; }
  701. virtual bool Compile();
  702. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  703. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const { return true; }
  704. virtual void UpdateManifest( KeyValues *pKV ) {}
  705. void SetInputFile( const char *pszVCD ) { m_strVCDPath = pszVCD; }
  706. protected:
  707. friend class CAsset;
  708. CTargetVCD( CAsset *pAsset, const CTargetQC *pTargetQC );
  709. const CTargetQC *m_pTargetQC;
  710. CUtlString m_strVCDPath;
  711. };
  712. //=============================================================================
  713. //
  714. //=============================================================================
  715. class CTargetQC : public CTargetBase
  716. {
  717. public:
  718. // From CTargetBase
  719. virtual bool IsOk( CUtlString &sMsg ) const;
  720. virtual bool IsContent() const { return true; }
  721. virtual const char *GetTypeString() const { return "QC"; }
  722. virtual bool Compile();
  723. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  724. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const;
  725. void SetQCTemplate( const char *pszQCTemplate );
  726. const char *GetQCTemplate();
  727. void SetQCITemplate( const char *pszQCITemplate ) { m_strQCITemplate = pszQCITemplate; }
  728. const char *GetQCITemplate() { return m_strQCITemplate.IsEmpty() ? NULL : m_strQCITemplate.Get(); }
  729. // Add a DMX Target to a QC which is a pathname to a geometry file (SMD, OBJ or DMX) in some arbitrary location
  730. int TargetDMXCount() const;
  731. int AddTargetDMX( const char *pszGeometryFile );
  732. bool SetTargetDMX( int nLOD, const char *pszGeometryFile );
  733. bool RemoveTargetDMX( int nLOD );
  734. CSmartPtr< CTargetDMX > GetTargetDMX( int nLOD ) const;
  735. // VCDs
  736. CSmartPtr< CTargetVCD > GetTargetVCD();
  737. virtual void UpdateManifest( KeyValues *pKV )
  738. {
  739. for ( int i = 0; i < TargetDMXCount(); ++i )
  740. {
  741. GetTargetDMX( i )->UpdateManifest( pKV );
  742. }
  743. }
  744. protected:
  745. friend class CAsset;
  746. CTargetQC( CAsset *pAsset, const CTargetMDL *pTargetMDL );
  747. enum
  748. {
  749. kATexture, // i.e. Red
  750. kBTexture, // i.e. Blue
  751. kCTexture, // i.e. Green
  752. kDTexture, // i.e. Yellow
  753. kCommonTexture,
  754. kTextureCount
  755. };
  756. // Dependencies/Inputs
  757. CUtlVector< CSmartPtr< CTargetDMX > > m_TargetDMXs; // 0 = LOD0, 1 = LOD1
  758. CSmartPtr< CTargetVCD > m_TargetVCD;
  759. CUtlBuffer m_QCTemplate;
  760. CUtlString m_strQCITemplate;
  761. };
  762. //=============================================================================
  763. //
  764. //=============================================================================
  765. class CTargetMDL : public CTargetBase
  766. {
  767. public:
  768. // From CTargetBase
  769. virtual bool IsOk( CUtlString &sMsg ) const;
  770. virtual bool IsContent() const { return false; }
  771. virtual const char *GetTypeString() const { return "MDL"; }
  772. virtual bool Compile();
  773. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  774. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const;
  775. CSmartPtr< CTargetQC > GetTargetQC() const { return m_pTargetQC; }
  776. virtual void UpdateManifest( KeyValues *pKV )
  777. {
  778. GetTargetQC()->UpdateManifest( pKV );
  779. }
  780. protected:
  781. friend class CAsset;
  782. CTargetMDL( CAsset *pAsset, const CTargetBase *pTargetParent );
  783. // Dependencies/Inputs
  784. CSmartPtr< CTargetQC > m_pTargetQC;
  785. };
  786. //=============================================================================
  787. //
  788. //=============================================================================
  789. class CAsset : public CTargetBase
  790. {
  791. public:
  792. CAsset();
  793. CAsset( const char *pszName, bool *pbOk = NULL );
  794. virtual ~CAsset();
  795. // From CTargetBase
  796. virtual bool IsOk( CUtlString &sMsg ) const;
  797. virtual bool IsContent() const { return true; }
  798. virtual const char *GetTypeString() const { return "ZIP"; }
  799. // This compiles all the inputs but doesn't create the final archive
  800. bool CompilePreview();
  801. virtual bool PostCompilePreview();
  802. virtual bool Compile();
  803. virtual bool PostCompile();
  804. virtual bool GetInputs( CUtlVector< CTargetBase * > &inputs ) const;
  805. virtual const ExtensionList *GetExtensionsAndCount( void ) const;
  806. virtual const CUtlString &GetAssetName() const;
  807. // Returns the
  808. bool GetDirectory( CUtlString &sDirectory, const char *pszPrefix ) const;
  809. // Returns <class>/<steamid>/<name>, false if there's something wrong
  810. bool GetRelativeDir( CUtlString &sRelativeDir, const char *pszPrefix, const CTargetBase *pTarget ) const;
  811. // Returns GetSDKContentDir()/GetRelativeDir() or GetVProjectDir()/GetRelativeDir()
  812. bool GetAbsoluteDir( CUtlString &sAbsoluteDir, const char *pszPrefix, const CTargetBase *pTarget ) const;
  813. // Get the files that were built during the compile process
  814. const CUtlVector< CUtlString > &GetBuiltFiles() const { return m_sAbsPaths; }
  815. const CUtlVector< CUtlString > &GetRelativePathBuiltFiles() const { return m_sRelPaths; }
  816. const CUtlVector< CUtlString > &GetModFiles() const { return m_sModOutputs; }
  817. void AddModOutput( const char *pszCustomModOutput ) { m_sModOutputs.AddToTail( pszCustomModOutput ); }
  818. bool SetName( const char *pszName );
  819. bool IsNameValid() const;
  820. const char *GetSteamId() const;
  821. bool IsSteamIdValid() const;
  822. void SetSkinToBipHead( bool bSkinToBipHead ) { m_bSkinToBipHead = bSkinToBipHead; }
  823. bool SkinToBipHead() const { return m_bSkinToBipHead; }
  824. virtual const char *GetClass() const = 0;
  825. virtual KeyValues *GetAdditionalManifestData( void ) = 0;
  826. bool SetTargetIcon( int nIcon, const char *pszIconFile );
  827. CSmartPtr< CTargetIcon > GetTargetIcon( int nIcon ) const { return m_vecTargetIcons[ nIcon ]; }
  828. int AddModel();
  829. int GetNumModels() const { return m_vecModels.Count(); }
  830. int GetCurrentModel() const { return m_nCurrentModel; }
  831. bool SetCurrentModel( int nModel );
  832. void RemoveModels();
  833. int TargetDMXCount() const;
  834. int AddTargetDMX( const char *pszGeometryFile );
  835. bool SetTargetDMX( int nLOD, const char *pszGeometryFile );
  836. bool RemoveTargetDMX( int nLOD );
  837. CSmartPtr< CTargetDMX > GetTargetDMX( int nLOD );
  838. CSmartPtr< CTargetMDL > GetTargetMDL() const;
  839. CSmartPtr< CTargetQC > GetTargetQC() const;
  840. int GetTargetVMTCount() const;
  841. CTargetVMT *GetTargetVMT( int nIndex ) const;
  842. template < class T, class C > CSmartPtr< T > NewTarget( const C *pTargetParent )
  843. {
  844. return CSmartPtr< T >( new T( this, pTargetParent ) );
  845. }
  846. CSmartPtr< CTargetVMT > FindOrAddMaterial( const char *pszMaterial, int nMaterialType );
  847. CSmartPtr< CTargetVMT > FindMaterial( const char *pszMaterial );
  848. bool Mkdir( const char *pszPrefix, const CTargetBase *pTarget );
  849. void CreateManifest( CUtlBuffer &manifestBuf );
  850. virtual void UpdateManifest( KeyValues *pKV )
  851. {
  852. KeyValues *pkvAdditional = GetAdditionalManifestData();
  853. if ( pkvAdditional )
  854. {
  855. pkvAdditional->CopySubkeys( pKV );
  856. }
  857. pKV->SetString( "name", GetAssetName().Get() );
  858. pKV->SetString( "class", GetClass() );
  859. pKV->SetString( "steamId", GetSteamId() );
  860. for ( int i = 0; i < TargetDMXCount(); ++i )
  861. {
  862. GetTargetDMX( i )->UpdateManifest( pKV );
  863. }
  864. for ( int i = 0; i < GetTargetVMTCount(); ++i )
  865. {
  866. CFmtStr sTmp;
  867. sTmp.sprintf( "vmt%d", i );
  868. KeyValues *pSubKey = new KeyValues( sTmp.Access() );
  869. pKV->AddSubKey( pSubKey );
  870. GetTargetVMT( i )->UpdateManifest( pSubKey );
  871. }
  872. }
  873. void SetArchivePath( const char *pszArchivePath ) { m_sArchivePath = pszArchivePath; }
  874. const char *GetArchivePath() const { return m_sArchivePath; }
  875. const char* CheckRedundantOutputFilePath( const char* pszInputFilePath, const char* pszVTEXConfig, const char* pszOutputFilePath );
  876. void ExcludeFileExtension( const char *pszExtension ) { m_sExcludeFileExtensions.AddToTail( pszExtension ); }
  877. void SetBuildScenesImage( bool bShouldBuildScenesImage ) { m_bShouldBuildScenesImage = bShouldBuildScenesImage; }
  878. protected:
  879. CUtlString m_sSteamId;
  880. CUtlString m_sName;
  881. bool m_bSkinToBipHead;
  882. // build scenes.image
  883. bool BuildScenesImage();
  884. bool m_bShouldBuildScenesImage;
  885. // Called only by CTargetVMT destructor
  886. friend class CTargetVMT;
  887. bool RemoveMaterial( const char *pszMaterial );
  888. // This owns the pointers for all of the targets in the Asset
  889. CUtlVector< CSmartPtr< CTargetBase > > m_targetStore;
  890. // Dependencies/Inputs
  891. CUtlVector< CSmartPtr< CTargetMDL > > m_vecModels;
  892. int m_nCurrentModel;
  893. CUtlMap< CUtlString, CTargetVMT * > m_vmtMap;
  894. CUtlVector< CSmartPtr< CTargetIcon > > m_vecTargetIcons;
  895. // The path to the ZIP archive
  896. CUtlString m_sArchivePath;
  897. // Files that were built during the compile process
  898. CUtlVector< CUtlString > m_sAbsPaths;
  899. CUtlVector< CUtlString > m_sRelPaths;
  900. CUtlVector< CUtlString > m_sModOutputs;
  901. // Sometime we don't want to include some extensions in the zip file
  902. CUtlVector< CUtlString > m_sExcludeFileExtensions;
  903. struct CompileOutputFile_t
  904. {
  905. CUtlString m_strInputFilePath;
  906. CUtlString m_strVTEXConfig;
  907. CUtlString m_strOutputFilePath;
  908. };
  909. CUtlVector< CompileOutputFile_t > m_CompileOutputFiles;
  910. };
  911. //=============================================================================
  912. //
  913. // Instantiate a game specific asset class
  914. //
  915. // e.g.: typedef CAssetGame< CItemUploadTF > CAssetTF;
  916. //
  917. //=============================================================================
  918. template < typename T >
  919. class CAssetGame : public CAsset
  920. {
  921. typedef CAsset BaseClass;
  922. public:
  923. CAssetGame()
  924. : CAsset()
  925. {
  926. m_sClass = GetClassString( "" );
  927. m_pkvAdditionalManifestData = NULL;
  928. }
  929. CAssetGame( const char *pszClass, const char *pszName, bool *pbOk /* = NULL */ )
  930. : CAsset( pszName, pbOk )
  931. {
  932. const char *pszSanitizedClass = GetClassString( pszClass );
  933. if ( pszSanitizedClass )
  934. {
  935. m_sClass = pszSanitizedClass;
  936. }
  937. else
  938. {
  939. m_sClass = GetClassString( "" );
  940. }
  941. }
  942. bool SetClass( const char *pszClass )
  943. {
  944. const char *pszRealClass = GetClassString( pszClass );
  945. if ( pszRealClass )
  946. {
  947. m_sClass = pszRealClass;
  948. }
  949. else
  950. {
  951. m_sClass = pszClass;
  952. Assert( !IsClassValid() );
  953. }
  954. return IsClassValid();
  955. }
  956. virtual const char *GetClass() const { return m_sClass.Get(); }
  957. bool IsClassValid() const
  958. {
  959. if ( m_sClass.Length() <= 0 || GetClassString( m_sClass ) == NULL )
  960. return false;
  961. return true;
  962. }
  963. void SetAdditionalManifestData( KeyValues *pKV )
  964. {
  965. if ( m_pkvAdditionalManifestData )
  966. {
  967. m_pkvAdditionalManifestData->deleteThis();
  968. m_pkvAdditionalManifestData = NULL;
  969. }
  970. m_pkvAdditionalManifestData = pKV->MakeCopy();
  971. }
  972. KeyValues *GetAdditionalManifestData( void )
  973. {
  974. return m_pkvAdditionalManifestData;
  975. }
  976. virtual bool IsOk( CUtlString &sMsg ) const
  977. {
  978. if ( !IsClassValid() )
  979. {
  980. sMsg = "Invalid Class";
  981. return false;
  982. }
  983. return BaseClass::IsOk( sMsg );
  984. }
  985. const Vector &GetBipHead() const
  986. {
  987. const int nClassIndex = GetClassIndex( m_sClass );
  988. return CItemUploadGame< T >::GetBipHead( nClassIndex );
  989. }
  990. const RadianEuler &GetBipHeadRotation() const
  991. {
  992. const int nClassIndex = GetClassIndex( m_sClass );
  993. return CItemUploadGame< T >::GetBipHeadRotation( nClassIndex );
  994. }
  995. protected:
  996. CUtlString m_sClass;
  997. KeyValues *m_pkvAdditionalManifestData;
  998. };
  999. //-----------------------------------------------------------------------------
  1000. //
  1001. //-----------------------------------------------------------------------------
  1002. typedef CAssetGame< CItemUploadTF > CAssetTF;
  1003. //-----------------------------------------------------------------------------
  1004. // Get[Input|Output]Path(s) flag usage
  1005. //-----------------------------------------------------------------------------
  1006. //
  1007. // Get the name of the nth output file
  1008. // For example:
  1009. //
  1010. // FILE EXTEN PATH ABS MODELS PREFIX OutputName
  1011. // true true true true true true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo.vmt
  1012. // true true true true true false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo.vmt
  1013. // true true true true false true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo.vmt
  1014. // true true true true false false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo.vmt
  1015. //
  1016. // true true true false true true materials/models/player/items/pyro/0x00017714/foo/foo.vmt
  1017. // true true true false true false models/player/items/pyro/0x00017714/foo/foo.vmt
  1018. // true true true false false true player/items/pyro/0x00017714/foo/foo.vmt
  1019. // true true true false false false player/items/pyro/0x00017714/foo/foo.vmt
  1020. //
  1021. // true true false true true true foo.vmt
  1022. // true true false true true false foo.vmt
  1023. // true true false true false true foo.vmt
  1024. // true true false true false false foo.vmt
  1025. //
  1026. // true true false false true true foo.vmt
  1027. // true true false false true false foo.vmt
  1028. // true true false false false true foo.vmt
  1029. // true true false false false false foo.vmt
  1030. //
  1031. // true false true true true true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1032. // true false true true true false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1033. // true false true true false true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1034. // true false true true false false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1035. //
  1036. // true false true false true true materials/models/player/items/pyro/0x00017714/foo/foo
  1037. // true false true false true false models/player/items/pyro/0x00017714/foo/foo
  1038. // true false true false false true player/items/pyro/0x00017714/foo/foo
  1039. // true false true false false false player/items/pyro/0x00017714/foo/foo
  1040. //
  1041. // true false false true true true foo
  1042. // true false false true true false foo
  1043. // true false false true false true foo
  1044. // true false false true false false foo
  1045. //
  1046. // true false false false true true foo
  1047. // true false false false true false foo
  1048. // true false false false false true foo
  1049. // true false false false false false foo
  1050. //
  1051. // false true true true true true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo
  1052. // false true true true true false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo
  1053. // false true true true false true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo
  1054. // false true true true false false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo
  1055. //
  1056. // false true true false true true materials/models/player/items/pyro/0x00017714/foo
  1057. // false true true false true false models/player/items/pyro/0x00017714/foo
  1058. // false true true false false true player/items/pyro/0x00017714/foo
  1059. // false true true false false false player/items/pyro/0x00017714/foo
  1060. //
  1061. // false true false true true true - FAILURE -
  1062. // false true false true true false - FAILURE -
  1063. // false true false true false true - FAILURE -
  1064. // false true false true false false - FAILURE -
  1065. //
  1066. // false true false false true true - FAILURE -
  1067. // false true false false true false - FAILURE -
  1068. // false true false false false true - FAILURE -
  1069. // false true false false false false - FAILURE -
  1070. //
  1071. // false false true true true true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1072. // false false true true true false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1073. // false false true true false true d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1074. // false false true true false false d:/dev/main/game/tf/materials/models/player/items/pyro/0x00017714/foo/foo
  1075. //
  1076. // false false true false true true materials/models/player/items/pyro/0x00017714/foo/foo
  1077. // false false true false true false models/player/items/pyro/0x00017714/foo/foo
  1078. // false false true false false true player/items/pyro/0x00017714/foo/foo
  1079. // false false true false false false player/items/pyro/0x00017714/foo/foo
  1080. //
  1081. // false false false true true true - FAILURE -
  1082. // false false false true true false - FAILURE -
  1083. // false false false true false true - FAILURE -
  1084. // false false false true false false - FAILURE -
  1085. //
  1086. // false false false false true true - FAILURE -
  1087. // false false false false true false - FAILURE -
  1088. // false false false false false true - FAILURE -
  1089. // false false false false false false - FAILURE -
  1090. //
  1091. #endif // itemtest_H