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.

190 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // Imports .fac files exported from the SFM into VCD files
  12. //
  13. //=============================================================================
  14. #include "tier0/dbg.h"
  15. #include "tier0/icommandline.h"
  16. #include "datamodel/idatamodel.h"
  17. #include "filesystem.h"
  18. #include "appframework/tier3app.h"
  19. #include "tier1/utlbuffer.h"
  20. #include "dmserializers/idmserializers.h"
  21. #include "tier1/utlstring.h"
  22. #include "datamodel/dmattribute.h"
  23. #include "datamodel/dmelement.h"
  24. #include "tier3/tier3.h"
  25. #include "movieobjects/importintovcd.h"
  26. #include "p4lib/ip4.h"
  27. #include "tier2/p4helpers.h"
  28. #include "interpolatortypes.h"
  29. #include "datacache/idatacache.h"
  30. #include "datacache/imdlcache.h"
  31. #include "vphysics_interface.h"
  32. #include "materialsystem/imaterialsystem.h"
  33. #include "istudiorender.h"
  34. #ifdef _DEBUG
  35. #include <windows.h>
  36. #endif
  37. class CDmElement;
  38. //-----------------------------------------------------------------------------
  39. // Standard spew functions
  40. //-----------------------------------------------------------------------------
  41. static SpewRetval_t VcdImportOutputFunc( SpewType_t spewType, const char *pMsg )
  42. {
  43. #ifdef _DEBUG
  44. OutputDebugString( pMsg );
  45. #endif
  46. printf( pMsg );
  47. fflush( stdout );
  48. if (spewType == SPEW_ERROR)
  49. return SPEW_ABORT;
  50. return (spewType == SPEW_ASSERT) ? SPEW_DEBUGGER : SPEW_CONTINUE;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // The application object
  54. //-----------------------------------------------------------------------------
  55. class CVcdImportApp : public CTier3DmSteamApp
  56. {
  57. typedef CTier3DmSteamApp BaseClass;
  58. public:
  59. // Methods of IApplication
  60. virtual bool Create();
  61. virtual bool PreInit( );
  62. virtual int Main();
  63. virtual void Destroy() {}
  64. };
  65. DEFINE_CONSOLE_STEAM_APPLICATION_OBJECT( CVcdImportApp );
  66. //-----------------------------------------------------------------------------
  67. // The application object
  68. //-----------------------------------------------------------------------------
  69. bool CVcdImportApp::Create()
  70. {
  71. SpewOutputFunc( VcdImportOutputFunc );
  72. AppSystemInfo_t appSystems[] =
  73. {
  74. { "p4lib.dll", P4_INTERFACE_VERSION },
  75. { "materialsystem.dll", MATERIAL_SYSTEM_INTERFACE_VERSION },
  76. { "datacache.dll", DATACACHE_INTERFACE_VERSION },
  77. { "datacache.dll", MDLCACHE_INTERFACE_VERSION },
  78. { "studiorender.dll", STUDIO_RENDER_INTERFACE_VERSION },
  79. { "vphysics.dll", VPHYSICS_INTERFACE_VERSION },
  80. { "", "" } // Required to terminate the list
  81. };
  82. AddSystems( appSystems );
  83. IMaterialSystem *pMaterialSystem = reinterpret_cast< IMaterialSystem * >( FindSystem( MATERIAL_SYSTEM_INTERFACE_VERSION ) );
  84. if ( !pMaterialSystem )
  85. {
  86. Error( "// ERROR: Unable to connect to material system interface!\n" );
  87. return false;
  88. }
  89. pMaterialSystem->SetShaderAPI( "shaderapiempty.dll" );
  90. return true;
  91. }
  92. bool CVcdImportApp::PreInit( )
  93. {
  94. if ( !BaseClass::PreInit() )
  95. return false;
  96. if ( !g_pFullFileSystem || !g_pDataModel || !g_pMDLCache )
  97. {
  98. Warning( "VCDImport is missing a required interface!\n" );
  99. return false;
  100. }
  101. // Add paths...
  102. if ( !SetupSearchPaths( NULL, false, true ) )
  103. return false;
  104. return true;
  105. }
  106. //-----------------------------------------------------------------------------
  107. // The application object
  108. //-----------------------------------------------------------------------------
  109. int CVcdImportApp::Main()
  110. {
  111. g_pDataModel->OnlyCreateUntypedElements( true );
  112. g_pDataModel->SetDefaultElementFactory( NULL );
  113. g_pDataModel->SetUndoEnabled( false );
  114. // This bit of hackery allows us to access files on the harddrive
  115. g_pFullFileSystem->AddSearchPath( "", "LOCAL", PATH_ADD_TO_HEAD );
  116. // Do Perforce Stuff
  117. if ( CommandLine()->FindParm( "-nop4" ) )
  118. {
  119. g_p4factory->SetDummyMode( true );
  120. }
  121. g_p4factory->SetOpenFileChangeList( "Automatically Generated VCD files" );
  122. ImportVCDInfo_t info;
  123. const char *pImportFileName = CommandLine()->ParmValue("-f" );
  124. const char *pInFileName = CommandLine()->ParmValue("-i" );
  125. const char *pOutFileName = CommandLine()->ParmValue("-o" );
  126. info.m_flSimplificationThreshhold = CommandLine()->ParmValue( "-s", 0.05f );
  127. info.m_nInterpolationType = Interpolator_InterpolatorForName( CommandLine()->ParmValue( "-c", "linear_interp" ) );
  128. info.m_bIgnorePhonemes = CommandLine()->FindParm( "-p" ) != 0;
  129. if ( !pImportFileName || !pInFileName )
  130. {
  131. Msg( "Usage: vcdimport -f <imported .fac file> -i <in .vcd file> [-o <out .vcd file>]\n" );
  132. Msg( "\t\t[-nop4] [-p] [-s <simplification_amount>] [-c <curve type>]\n" );
  133. Msg( "\t-f : .FAC file containing SFM-authored facial animation exported from the animation set editor in the SFM.\n" );
  134. Msg( "\t-i : Source .VCD file to import the facial animation into.\n" );
  135. Msg( "\t-o : If no output file is specified, vcdimport will overwrite the input .vcd file.\n" );
  136. Msg( "\t-p : Causes the generated .VCD file to not use phonemes in associated wav files to autogenerate animation.\n" );
  137. Msg( "\t-nop4 : Disables auto perforce checkout.\n" );
  138. Msg( "\t-s : Requires a second argument, the amount of error we're willing to accept in simplification. Ranges from 0.0 - 1.0 [default = 0.05]\n" );
  139. Msg( "\t-c : Specify interpolation type. Options are: [linear_interp is used if -c isn't specified]\n" );
  140. for ( int i = 0; i < NUM_INTERPOLATE_TYPES; ++i )
  141. {
  142. Msg( "\t\t%22s :\t%s\n", Interpolator_NameForInterpolator( i, false ), Interpolator_NameForInterpolator( i, true ) );
  143. }
  144. return -1;
  145. }
  146. if ( !pOutFileName )
  147. {
  148. pOutFileName = pInFileName;
  149. }
  150. bool bOk = ImportLogsIntoVCD( pImportFileName, pInFileName, pOutFileName, info );
  151. if ( bOk )
  152. {
  153. Msg( "Wrote file %s.\n", pOutFileName );
  154. }
  155. return bOk;
  156. }