diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /public/sfmobjects | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'public/sfmobjects')
| -rw-r--r-- | public/sfmobjects/exportfacialanimation.h | 27 | ||||
| -rw-r--r-- | public/sfmobjects/flexcontrolbuilder.h | 179 | ||||
| -rw-r--r-- | public/sfmobjects/sfmanimationsetutils.h | 32 | ||||
| -rw-r--r-- | public/sfmobjects/sfmphonemeextractor.h | 161 | ||||
| -rw-r--r-- | public/sfmobjects/sfmsession.h | 170 |
5 files changed, 569 insertions, 0 deletions
diff --git a/public/sfmobjects/exportfacialanimation.h b/public/sfmobjects/exportfacialanimation.h new file mode 100644 index 0000000..fffafb0 --- /dev/null +++ b/public/sfmobjects/exportfacialanimation.h @@ -0,0 +1,27 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef EXPORTFACIALANIMATION_H +#define EXPORTFACIALANIMATION_H +#ifdef _WIN32 +#pragma once +#endif + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CDmeFilmClip; +class CDmeAnimationSet; + + +//----------------------------------------------------------------------------- +// Exports an .fac file +//----------------------------------------------------------------------------- +bool ExportFacialAnimation( const char *pFileName, CDmeFilmClip *pMovie, CDmeFilmClip *pShot, CDmeAnimationSet *pAnimationSet ); + + +#endif // EXPORTFACIALANIMATION_H diff --git a/public/sfmobjects/flexcontrolbuilder.h b/public/sfmobjects/flexcontrolbuilder.h new file mode 100644 index 0000000..0ac6446 --- /dev/null +++ b/public/sfmobjects/flexcontrolbuilder.h @@ -0,0 +1,179 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// A class used to build flex animation controls for an animation set +// +//============================================================================= + +#ifndef FLEXCONTROLBUILDER_H +#define FLEXCONTROLBUILDER_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "movieobjects/timeutils.h" +#include "tier1/utlvector.h" +#include "movieobjects/dmelog.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CDmeAnimationSet; +class CDmeGameModel; +class CDmeFilmClip; +class CDmeChannelsClip; +class CDmElement; +class CDmeChannel; +class CDmeBalanceToStereoCalculatorOperator; +class CDmeGlobalFlexControllerOperator; + + +//----------------------------------------------------------------------------- +// +// Utility class for dealing with the complex task of building flex controls +// +//----------------------------------------------------------------------------- +class CFlexControlBuilder +{ +public: + // Main entry point for creating flex animation set controls + void CreateAnimationSetControls( CDmeFilmClip *pMovie, CDmeAnimationSet *pAnimationSet, + CDmeGameModel *pGameModel, CDmeFilmClip *pSourceClip, CDmeChannelsClip *pDestClip, bool bUseExistingLogs ); + +private: + enum ControlField_t + { + CONTROL_VALUE = 0, + CONTROL_BALANCE, + CONTROL_MULTILEVEL, + + CONTROL_FIELD_COUNT, + }; + + enum OutputField_t + { + OUTPUT_MONO = 0, + OUTPUT_RIGHT = 0, + OUTPUT_LEFT, + OUTPUT_MULTILEVEL, + + OUTPUT_FIELD_COUNT, + }; + + struct FlexControllerInfo_t + { + char m_pFlexControlName[256]; + float m_flDefaultValue; + int m_nGlobalIndex; + }; + + struct ExistingLogInfo_t + { + CDmeFloatLog *m_pLog; + DmeTime_t m_GlobalOffset; + double m_flGlobalScale; + }; + + struct ControlInfo_t + { + char m_pControlName[256]; + bool m_bIsStereo : 1; + bool m_bIsMulti : 1; + CDmElement *m_pControl; + + int m_pControllerIndex[OUTPUT_FIELD_COUNT]; + + CDmeChannel *m_ppControlChannel[CONTROL_FIELD_COUNT]; + float m_pDefaultValue[CONTROL_FIELD_COUNT]; + ExistingLogInfo_t m_pExistingLog[CONTROL_FIELD_COUNT]; + }; + + // Removes a channel from the channels clip referring to it. + void RemoveChannelFromClips( CDmeChannel *pChannel ); + + // Removes a stereo operator from the animation set referring to it + void RemoveStereoOpFromSet( CDmeBalanceToStereoCalculatorOperator *pChannel ); + + // Builds the list of flex controls (outputs) in the current game model + void BuildDesiredFlexControlList( CDmeGameModel *pGameModel ); + + // This builds a list of the desired input controls we need to have controls for + // by the time we're all done with this enormous process. + void BuildDesiredControlList( CDmeGameModel *pGameModel ); + + // finds controls whose channels don't point to anything anymore, and deletes both the channels and the control + void RemoveUnusedControlsAndChannels( CDmeAnimationSet *pAnimationSet, CDmeChannelsClip *pChannelsClip ); + + // I'll bet you can guess what this does + void RemoveUnusedExistingFlexControllers( CDmeGameModel *pGameModel ); + + // Fixup list of existing flex controller logs + // - reattach flex controls that were removed from the gamemodel's list + void FixupExistingFlexControlLogList( CDmeFilmClip *pCurrentClip, CDmeGameModel *pGameModel ); + + // Converts existing logs to balance/value if necessary while building the list + // Also deletes existing infrastructure (balance ops, channels, flex controller ops). + void BuildExistingFlexControlLogList( CDmeFilmClip *pCurrentClip, CDmeGameModel *pGameModel ); + + // Finds a desired flex controller index in the m_FlexControllerInfo array + int FindDesiredFlexController( const char *pFlexControllerName ) const; + + // Blows away the various elements trying to control a flex controller op + void CleanupExistingFlexController( CDmeGameModel *pGameModel, CDmeGlobalFlexControllerOperator *pOp ); + + // Finds a channels clip containing a particular channel + CDmeChannelsClip* FindChannelsClipContainingChannel( CDmeFilmClip *pClip, CDmeChannel *pSearch ); + + // Returns an existing mono log + void GetExistingMonoLog( ExistingLogInfo_t *pLog, CDmeFilmClip *pClip, CDmeGlobalFlexControllerOperator *pMonoOp ); + + // Returns an existing stereo log, performing conversion if necessary + void GetExistingStereoLog( ExistingLogInfo_t *pLogs, CDmeFilmClip *pClip, + CDmeGlobalFlexControllerOperator *pRightOp, CDmeGlobalFlexControllerOperator *pLeftOp ); + + // Returns an existing value/balance log + void GetExistingVBLog( ExistingLogInfo_t *pLogs, CDmeFilmClip *pClip, CDmeBalanceToStereoCalculatorOperator *pStereoOp ); + + // Converts an existing left/right log into a value/balance log + void ConvertExistingLRLogs( ExistingLogInfo_t *pLogs, CDmeFilmClip *pClip, CDmeChannel *pLeftChannel, CDmeChannel *pRightChannel ); + + // Computes a global offset and scale to convert from log time to global time + void ComputeChannelTimeTransform( DmeTime_t *pOffset, double *pScale, CDmeChannelsClip *pChannelsClip ); + bool ComputeChannelTimeTransform( DmeTime_t *pOffset, double *pScale, CDmeFilmClip* pClip, CDmeChannel* pChannel ); + + // Initializes the fields of a flex control + void InitializeFlexControl( ControlInfo_t &info ); + + // Creates all controls for flexes + void CreateFlexControls( CDmeAnimationSet *pAnimationSet ); + + // Build the infrastructure of the ops that connect that control to the dmegamemodel + void AttachControlsToGameModel( CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip ); + + // Connects a mono control to a single flex controller op + void BuildFlexControllerOps( CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip, ControlInfo_t &info, ControlField_t field ); + + // Connects a stereo control to a two flex controller ops + void BuildStereoFlexControllerOps( CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip, ControlInfo_t &info ); + + // Attaches existing logs and sets default values for logs + void SetupLogs( CDmeChannelsClip *pChannelsClip, bool bUseExistingLogs ); + + // Destination flex controllers + CUtlVector< FlexControllerInfo_t > m_FlexControllerInfo; + + // Destination controls + CUtlVector< ControlInfo_t > m_ControlInfo; + + CDmeFilmClip *m_pMovie; +}; + + +//----------------------------------------------------------------------------- +// Initialize default global flex controller +//----------------------------------------------------------------------------- +void SetupDefaultFlexController(); + + +#endif // FLEXCONTROLBUILDER_H diff --git a/public/sfmobjects/sfmanimationsetutils.h b/public/sfmobjects/sfmanimationsetutils.h new file mode 100644 index 0000000..a93438d --- /dev/null +++ b/public/sfmobjects/sfmanimationsetutils.h @@ -0,0 +1,32 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// NOTE: This is a cut-and-paste hack job to get animation set construction +// working from a commandline tool. It came from tools/ifm/createsfmanimation.cpp +// This file needs to die almost immediately + be replaced with a better solution +// that can be used both by the sfm + sfmgen. +// +//============================================================================= + +#ifndef SFMANIMATIONSETUTILS_H +#define SFMANIMATIONSETUTILS_H +#ifdef _WIN32 +#pragma once +#endif + + +//----------------------------------------------------------------------------- +// movieobjects +//----------------------------------------------------------------------------- +class CDmeFilmClip; +class CDmeGameModel; +class CDmeAnimationSet; + + +//----------------------------------------------------------------------------- +// Creates an animation set +//----------------------------------------------------------------------------- +CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pMovie, CDmeFilmClip *pShot, + CDmeGameModel *pGameModel, const char *pAnimationSetName, int nSequenceToUse, bool bAttachToGameRecording ); + + +#endif // SFMANIMATIONSETUTILS_H diff --git a/public/sfmobjects/sfmphonemeextractor.h b/public/sfmobjects/sfmphonemeextractor.h new file mode 100644 index 0000000..1a1383b --- /dev/null +++ b/public/sfmobjects/sfmphonemeextractor.h @@ -0,0 +1,161 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef SFMPHONEMEEXTRACTOR_H +#define SFMPHONEMEEXTRACTOR_H +#ifdef _WIN32 +#pragma once +#endif + +#include "phonemeextractor/PhonemeExtractor.h" +#include "tier1/UtlString.h" +#include "sentence.h" +#include "dme_controls/logpreview.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CDmeSoundClip; +class CDmeGameSound; +class CDmeAnimationSet; + + +//----------------------------------------------------------------------------- +// Info about a particular phoneme to extract +//----------------------------------------------------------------------------- +class CExtractInfo +{ +public: + CExtractInfo(); + CExtractInfo( const CExtractInfo& src ); + ~CExtractInfo(); + + void ClearTags(); + + // Filled in by caller + CDmeSoundClip *m_pClip; + CDmeGameSound *m_pSound; + CUtlString m_sHintText; + bool m_bUseSentence; + + // Filled in by Extract() + CSentence m_Sentence; + float m_flDuration; + bool m_bSentenceValid; + + // Must be passed in when calling for Apply, will be created and passed back for Extract + CUtlVector< CBasePhonemeTag * > m_ApplyTags; +}; + + +//----------------------------------------------------------------------------- +// Extraction type +//----------------------------------------------------------------------------- +enum SFMPhonemeExtractType_t +{ + EXTRACT_WIPE_RANGE = 0, // Wipe logs from start of first selected clip to end of last selected clip + EXTRACT_WIPE_CLIP, // Wipe all log entries (for facial controls) over entire clip + EXTRACT_WIPE_SOUNDS, // Leave logs untouched, except underneath each selected .wav file + + NUM_EXTRACT_WIPE_TYPES, +}; + +//----------------------------------------------------------------------------- +// Filter type +//----------------------------------------------------------------------------- +enum SFMPhonemeFilterType_t +{ + EXTRACT_FILTER_HOLD, // hold for phoneme duration + EXTRACT_FILTER_LINEAR, // linearly blend from phoneme start to next phoneme + EXTRACT_FILTER_FIXED_WIDTH, // hold and linearly falloff before and after + + NUM_EXTRACT_FILTER_TYPES, +}; + +//----------------------------------------------------------------------------- +// Extraction information +//----------------------------------------------------------------------------- +struct ExtractDesc_t +{ + SFMPhonemeExtractType_t m_nExtractType; + SFMPhonemeFilterType_t m_nFilterType; + bool m_bCreateBookmarks; + CUtlVector< CExtractInfo > m_WorkList; // One or more .wavs to extract from + CUtlVector< LogPreview_t > m_ControlList; // List of facial controls + CDmeFilmClip *m_pMovie; + CDmeFilmClip *m_pShot; + CDmeAnimationSet *m_pSet; + float m_flSampleRateHz; + float m_flSampleFilterSize; +}; + + +//----------------------------------------------------------------------------- +// Main interface for phoneme extraction +//----------------------------------------------------------------------------- +class ISFMPhonemeExtractor +{ +public: + virtual ~ISFMPhonemeExtractor() {}; + + virtual bool Init() = 0; + virtual void Shutdown() = 0; + + virtual int GetAPICount() = 0; + virtual void GetAPIInfo( int nIndex, CUtlString* pPrintName, PE_APITYPE *pAPIType ) = 0; + + virtual void Extract( const PE_APITYPE& apiType, ExtractDesc_t& info, bool bWritePhonemesToWavFiles = false ) = 0; + virtual void ReApply( ExtractDesc_t& info ) = 0; + virtual bool GetSentence( CDmeGameSound *pGameSound, CSentence& sentence ) = 0; +}; + +extern ISFMPhonemeExtractor *sfm_phonemeextractor; + + +//----------------------------------------------------------------------------- +// inline methods of CExtractInfo +//----------------------------------------------------------------------------- +inline CExtractInfo::CExtractInfo() : m_pClip( 0 ), m_pSound( 0 ), + m_bSentenceValid( false ), m_bUseSentence( false ), m_flDuration( 0.0f ) +{ +} + +inline CExtractInfo::CExtractInfo( const CExtractInfo& src ) +{ + m_pClip = src.m_pClip; + m_pSound = src.m_pSound; + m_sHintText = src.m_sHintText; + m_Sentence = src.m_Sentence; + m_bSentenceValid = src.m_bSentenceValid; + m_bUseSentence = src.m_bUseSentence; + m_flDuration = src.m_flDuration; + + ClearTags(); + + for ( int i = 0; i < src.m_ApplyTags.Count(); ++i ) + { + CBasePhonemeTag *newTag = new CBasePhonemeTag( *src.m_ApplyTags[ i ] ); + m_ApplyTags.AddToTail( newTag ); + } +} + +inline CExtractInfo::~CExtractInfo() +{ + ClearTags(); +} + +inline void CExtractInfo::ClearTags() +{ + for ( int i = 0; i < m_ApplyTags.Count(); ++i ) + { + delete m_ApplyTags[ i ]; + } + m_ApplyTags.RemoveAll(); +} + + +#endif // PHONEMEEXTRACTOR_H diff --git a/public/sfmobjects/sfmsession.h b/public/sfmobjects/sfmsession.h new file mode 100644 index 0000000..bf0d240 --- /dev/null +++ b/public/sfmobjects/sfmsession.h @@ -0,0 +1,170 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// A class representing session state for the SFM +// +//============================================================================= + +#ifndef SFMSESSION_H +#define SFMSESSION_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "datamodel/dmehandle.h" +#include "datamodel/dmelement.h" +#include "tier1/utlvector.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CDmElement; +class CDmeFilmClip; +class CDmeClip; +struct studiohdr_t; +class Vector; +class Quaternion; +class CDmeGameModel; +class CDmeCamera; +class CDmeDag; +class CDmeAnimationSet; + + +//----------------------------------------------------------------------------- +// Camera creation paramaters +//----------------------------------------------------------------------------- +struct DmeCameraParams_t +{ + DmeCameraParams_t() : fov( 90.0f ) + { + name[ 0 ] = 0; + origin.Init(); + angles.Init(); + } + + DmeCameraParams_t( const char *pszName ) : fov( 90.0f ) + { + Q_strncpy( name, pszName ? pszName : "", sizeof( name ) ); + origin.Init(); + angles.Init(); + } + + DmeCameraParams_t( const char *pszName, const Vector &org, const QAngle &ang ) : + fov( 90.0f ), origin( org ), angles( ang ) + { + Q_strncpy( name, pszName ? pszName : "", sizeof( name ) ); + } + + char name[ 128 ]; + + Vector origin; + QAngle angles; + + float fov; +}; + + +//----------------------------------------------------------------------------- +// A class representing the SFM Session +// FIXME: Should this be a dmelement? Maybe! +//----------------------------------------------------------------------------- +class CSFMSession +{ +public: + CSFMSession(); + + // Creates a new (empty) session + void Init(); + void Shutdown(); + + // Creates session settings + void CreateSessionSettings(); + + // Gets/sets the root + CDmElement *Root(); + const CDmElement *Root() const; + void SetRoot( CDmElement *pRoot ); + + // Methods to get at session settings + template< class T > const T& GetSettings( const char *pSettingName ) const; + CDmAttribute * GetSettingsAttribute( const char *pSettingName, DmAttributeType_t type ); + template< class E > E* GetSettingsElement( const char *pSettingName ) const; + template< class T > void SetSettings( const char *pSettingName, const T& value ); + + // Creates a game model + CDmeGameModel *CreateEditorGameModel( studiohdr_t *hdr, const Vector &vecOrigin, Quaternion &qOrientation ); + + // Creates a camera + CDmeCamera *CreateCamera( const DmeCameraParams_t& params ); + + // Finds or creates a scene + CDmeDag *FindOrCreateScene( CDmeFilmClip *pShot, const char *pSceneName ); + +private: + void CreateRenderSettings( CDmElement *pSettings, float flLegacyFramerate ); + void CreateProgressiveRefinementSettings( CDmElement *pRenderSettings ); + + CDmeHandle< CDmElement > m_hRoot; +// CDmeHandle< CDmeFilmClip > m_hCurrentMovie; +// CUtlVector< CDmeHandle< CDmeClip > > m_hClipStack; +// CUtlVector< CDmeHandle< CDmeClip > > m_hSelectedClip[ NUM_SELECTION_TYPES ]; +}; + + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +inline CDmElement *CSFMSession::Root() +{ + return m_hRoot; +} + +inline const CDmElement *CSFMSession::Root() const +{ + return m_hRoot; +} + + +//----------------------------------------------------------------------------- +// Method to get at various settings +//----------------------------------------------------------------------------- +template< class T > +inline const T& CSFMSession::GetSettings( const char *pSettingName ) const +{ + CDmElement *pSettings = m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL; + if ( pSettings ) + return pSettings->GetValue< T >( pSettingName ); + + static T defaultVal; + CDmAttributeInfo<T>::SetDefaultValue( defaultVal ); + return defaultVal; +} + +inline CDmAttribute *CSFMSession::GetSettingsAttribute( const char *pSettingName, DmAttributeType_t type ) +{ + CDmElement *pSettings = m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL; + if ( pSettings ) + return pSettings->GetAttribute( pSettingName, type ); + return NULL; +} + +template< class T > +inline void CSFMSession::SetSettings( const char *pSettingName, const T& value ) +{ + CDmElement *pSettings = m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL; + if ( pSettings ) + { + pSettings->SetValue( pSettingName, value ); + } +} + +template< class E > +inline E* CSFMSession::GetSettingsElement( const char *pSettingName ) const +{ + CDmElement *pSettings = m_hRoot->GetValueElement< CDmElement >( "settings" ); + return pSettings ? pSettings->GetValueElement< E >( pSettingName ) : NULL; +} + + +#endif // SFMSESSION_H |