summaryrefslogtreecommitdiff
path: root/public/movieobjects/dmeanimationset.h
blob: ad7678b14f8e174b8fb686c832d64cf3e9562cea (plain) (blame)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#ifndef DMEANIMATIONSET_H
#define DMEANIMATIONSET_H
#ifdef _WIN32
#pragma once
#endif

#include "datamodel/dmelement.h"
#include "datamodel/dmattribute.h"
#include "datamodel/dmattributevar.h"
#include "movieobjects/dmephonememapping.h"
#include "movieobjects/timeutils.h"
#include "movieobjects/proceduralpresets.h"

class CDmeBookmark;

//-----------------------------------------------------------------------------
// A preset is a list of values to be applied to named controls in the animation set
//-----------------------------------------------------------------------------
class CDmePreset : public CDmElement
{
	DEFINE_ELEMENT( CDmePreset, CDmElement );

public:
	CDmaElementArray< CDmElement > &GetControlValues();	
	const CDmaElementArray< CDmElement > &GetControlValues() const;

	CDmElement *FindControlValue( const char *pControlName );
	CDmElement *FindOrAddControlValue( const char *pControlName );
	void RemoveControlValue( const char *pControlName );
	bool IsReadOnly();
	void CopyControlValuesFrom( CDmePreset *pSource );

	// See the enumeration above
	void SetProceduralPresetType( int nType );
	bool IsProcedural() const;
	int GetProceduralPresetType() const;

private:
	int FindControlValueIndex( const char *pControlName );

	CDmaElementArray< CDmElement > m_ControlValues;
	CDmaVar< int > m_nProceduralType;
};


class CDmeProceduralPresetSettings : public CDmElement
{
	DEFINE_ELEMENT( CDmeProceduralPresetSettings, CDmElement );
public:
	
	CDmaVar< float > m_flJitterScale;
	CDmaVar< float > m_flSmoothScale;
	CDmaVar< float > m_flSharpenScale;
	CDmaVar< float > m_flSoftenScale;

	CDmaVar< int > m_nJitterIterations;
	CDmaVar< int > m_nSmoothIterations;
	CDmaVar< int > m_nSharpenIterations;
	CDmaVar< int > m_nSoftenIterations;

	CDmaVar< int > m_nStaggerInterval;
};

//-----------------------------------------------------------------------------
// A class used to copy preset values from one preset group to another
//-----------------------------------------------------------------------------
class CDmePresetRemap : public CDmElement
{
	DEFINE_ELEMENT( CDmePresetRemap, CDmElement );

public:
	CDmaString m_SourcePresetGroup;

	const char *FindSourcePreset( const char *pDestPresetName );
	int GetRemapCount();
	const char *GetRemapSource( int i );
	const char *GetRemapDest( int i );
	void AddRemap( const char *pSourcePresetName, const char *pDestPresetName );
	void RemoveAll();

private:
	CDmaStringArray m_SrcPresets;
	CDmaStringArray m_DestPresets;
};


class CDmeAnimationSet;
class CDmeCombinationOperator;

//-----------------------------------------------------------------------------
// A preset group is a list of presets, with shared visibility + readonly settings
//-----------------------------------------------------------------------------
class CDmePresetGroup : public CDmElement
{
	DEFINE_ELEMENT( CDmePresetGroup, CDmElement );

public:
	CDmaElementArray< CDmePreset > &GetPresets();			// raw access to the array
	const CDmaElementArray< CDmePreset > &GetPresets() const;
	CDmePreset *FindPreset( const char *pPresetName );
	CDmePreset *FindOrAddPreset( const char *pPresetName, int nProceduralType = PROCEDURAL_PRESET_NOT );
	bool RemovePreset( CDmePreset *pPreset );
	void MovePresetUp( CDmePreset *pPreset );
	void MovePresetDown( CDmePreset *pPreset );
	void MovePresetInFrontOf( CDmePreset *pPreset, CDmePreset *pInFrontOf );
	CDmePresetRemap *GetPresetRemap();
	CDmePresetRemap *GetOrAddPresetRemap();

	CDmaVar< bool > m_bIsVisible;
	CDmaVar< bool > m_bIsReadOnly;

	// Exports this preset group to a faceposer .txt expression file
	bool ExportToTXT( const char *pFilename, CDmeAnimationSet *pAnimationSet = NULL, CDmeCombinationOperator *pComboOp = NULL ) const;

	// Exports this preset group to a faceposer .vfe expression file
	bool ExportToVFE( const char *pFilename, CDmeAnimationSet *pAnimationSet = NULL, CDmeCombinationOperator *pComboOp = NULL ) const;

private:
	int FindPresetIndex( CDmePreset *pGroupName );

	CDmaElementArray< CDmePreset > m_Presets; // "presets"
};


//-----------------------------------------------------------------------------
// The main controlbox for controlling animation 
//-----------------------------------------------------------------------------
class CDmeAnimationSet : public CDmElement
{
	DEFINE_ELEMENT( CDmeAnimationSet, CDmElement );

public:
	CDmaElementArray< CDmElement > &GetControls();			// raw access to the array
	CDmaElementArray< CDmElement > &GetSelectionGroups();	// raw access to the array
	CDmaElementArray< CDmePresetGroup > &GetPresetGroups();	// raw access to the array
	CDmaElementArray< CDmePhonemeMapping > &GetPhonemeMap();		// raw access to the array
	CDmaElementArray< CDmeOperator > &GetOperators();		// raw access to the array

	void RestoreDefaultPhonemeMap();

	CDmePhonemeMapping *FindMapping( const char *pRawPhoneme );
	CDmElement *FindControl( const char *pControlName );
	CDmElement *FindOrAddControl( const char *pControlName );

	// Methods pertaining to preset groups
	CDmePresetGroup *FindPresetGroup( const char *pGroupName );
	CDmePresetGroup *FindOrAddPresetGroup( const char *pGroupName );
	bool RemovePresetGroup( CDmePresetGroup *pPresetGroup );
	void MovePresetGroupUp( CDmePresetGroup *pPresetGroup );
	void MovePresetGroupDown( CDmePresetGroup *pPresetGroup );
	void MovePresetGroupInFrontOf( CDmePresetGroup *pPresetGroup, CDmePresetGroup *pInFrontOf );

	CDmePreset *FindOrAddPreset( const char *pGroupName, const char *pPresetName, int nProceduralType = PROCEDURAL_PRESET_NOT );
	bool RemovePreset( CDmePreset *pPreset );

	const CDmaElementArray< CDmeBookmark > &GetBookmarks() const;
	CDmaElementArray< CDmeBookmark > &GetBookmarks();

	CDmElement *FindSelectionGroup( const char *pSelectionGroupName );
	CDmElement *FindOrAddSelectionGroup( const char *pSelectionGroupName );

	virtual void OnElementUnserialized();

	void CollectOperators( CUtlVector< DmElementHandle_t > &operators );
	void AddOperator( CDmeOperator *pOperator );
	void RemoveOperator( CDmeOperator *pOperator );

	void EnsureProceduralPresets();

private:
	int FindPresetGroupIndex( CDmePresetGroup *pGroup );
	int FindPresetGroupIndex( const char *pGroupName );

	CDmaElementArray< CDmElement >			m_Controls;			// "controls"
	CDmaElementArray< CDmElement >			m_SelectionGroups;	// "selectionGroups"
	CDmaElementArray< CDmePresetGroup >		m_PresetGroups;		// "presetGroups"
	CDmaElementArray< CDmePhonemeMapping >	m_PhonemeMap;		// "phonememap"
	CDmaElementArray< CDmeOperator >		m_Operators;		// "operators"
	CDmaElementArray< CDmeBookmark >		m_Bookmarks;		// "bookmarks"

	friend class CModelPresetGroupManager;
};


//-----------------------------------------------------------------------------
// Utility methods to convert between L/R and V/B
//-----------------------------------------------------------------------------
inline void ValueBalanceToLeftRight( float *pLeft, float *pRight, float flValue, float flBalance )
{
	*pLeft = ( flBalance <= 0.5f ) ? 1.0f : ( ( 1.0f - flBalance ) / 0.5f );
	*pLeft *= flValue;
	*pRight = ( flBalance >= 0.5f ) ? 1.0f : ( flBalance / 0.5f );
	*pRight *= flValue;
}

inline void LeftRightToValueBalance( float *pValue, float *pBalance, float flLeft, float flRight, float flDefaultBalance = 0.5f )
{
	*pValue = max( flRight, flLeft );
	if ( *pValue <= 1e-6 )
	{
		// Leave target balance at input value if target == 0 and on the dest side of blending
		*pBalance = flDefaultBalance;
		return;
	}

	if ( flRight < flLeft )
	{
		*pBalance = 0.5f * flRight / flLeft;
	}
	else
	{
		*pBalance = 1.0f - ( 0.5f * flLeft / flRight );
	}
}


//-----------------------------------------------------------------------------
// A cache of preset groups to be associated with specific models
//-----------------------------------------------------------------------------
abstract_class IModelPresetGroupManager
{
public:
	virtual void AssociatePresetsWithFile( DmFileId_t fileId ) = 0;
	virtual void ApplyModelPresets( const char *pModelName, CDmeAnimationSet *pAnimationSet ) = 0;
};


extern IModelPresetGroupManager *g_pModelPresetGroupMgr;


#endif // DMEANIMATIONSET_H