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