This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

View File

@@ -0,0 +1,484 @@
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
//
// Declaration of CDmeGraphEditorState, a data model element which stores
// the active state data for the graph editor.
//
//=============================================================================
#ifndef DMEGRAPHEDITORCURVE_H
#define DMEGRAPHEDITORCURVE_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/dmechannel.h"
#include "datamodel/dmelement.h"
#include "checksum_crc.h"
enum SelectionMode_t
{
SELECT_SET,
SELECT_ADD,
SELECT_REMOVE,
SELECT_TOGGLE,
};
enum AddKeyMode_t
{
ADD_KEYS_AUTO,
ADD_KEYS_INTERPOLATE,
ADD_KEYS_STEPPED,
};
enum TangentOperation_t
{
TANGENTS_FLAT, // Tangents are modified so the value of the end points are equal to the key value
TANGENTS_LINEAR, // Tangents are modified so the endpoints are on the line between the key values
TANGENTS_SPLINE, // Tangents are modified so the that they are parallel to the line from the proceeding key to the next key
TANGENTS_UNIFIED, // Tangents are modified so both sides of the tangent lie on the same line
TANGENTS_ISOMETRIC, // Tangents are modified so both sides of the tangent are of equal length
TANGENTS_STEP, // Set the key to step mode, out tangent is ignored and all values between the key and the next key are equal to the key value
TANGENTS_WEIGHTED, // Set the key to perform tangent calculations using the time of of the tangents
TANGENTS_UNWEIGHTED, // Set the key to perform tangent calculations such that the delta time of the tangents is ignored ( always 1/3 time to next key ).
};
enum KeyTangentMode_t
{
TANGENT_MODE_DEFAULT,
TANGENT_MODE_LINEAR,
TANGENT_MODE_SPLINE,
TANGENT_MODE_STEPPED
};
class CDmeGraphEditorCurve;
//-----------------------------------------------------------------------------
// The CDmeCurveKey class represents a single key on a curve an hold
// information about the position of the key and its tangents. The tangent
// values are stored as delta so they do not have to be updated when the value
// of the key changes.
//-----------------------------------------------------------------------------
class CDmeCurveKey : public CDmElement
{
DEFINE_ELEMENT( CDmeCurveKey, CDmElement );
enum KeyDirtyFlags_t
{
KEY_CLEAN = 0,
KEY_IN_DIRTY = 1,
KEY_OUT_DIRTY = 2
};
static const int UNWEIGHTED_DISPLAY_LENGTH = 60;
public:
// Initialize the key with the specified time and value
void Initialize( DmeTime_t time, float flValue, int nComponent );
// Get a pointer to the curve to which the key belongs
CDmeGraphEditorCurve *GetCurve() const;
// Return the sort value for the two keys based on their times
static int SortFunc( CDmeCurveKey * const *pKeyA, CDmeCurveKey * const *pKeyB );
// Clear the selection state of the key and its tangents
void ClearSelection();
// Set the key tangents to be flat
void SetTangentsFlat( const CDmeCurveKey *pPrevKey, const CDmeCurveKey *pNextKey, bool bSetIn, bool bSetOut );
// Set the key tangents to be linear
void SetTangentsLinear( const CDmeCurveKey *pPrevKey, const CDmeCurveKey *pNextKey, bool bSetIn, bool bSetOut );
// Set the key tangents using a spline method
void SetTangentsSpline( const CDmeCurveKey *pPrevKey, const CDmeCurveKey *pNextKey, bool bSetIn, bool bSetOut );
// Make both of the tangents of the key lie one the same line
void SetTangentsUnified( float flUnitsPerSecond, bool bSetIn, bool bSetOut );
// Make both of the tangents of the key be the same length
void SetTangentsIsometric( float flUnitsPerSecond, bool bSetIn, bool bSetOut );
// Set the key tangents as being broken (not unified)
void SetTangentsBroken();
// Set the key as being in stepped mode
void SetStepped( bool bStepped );
// Enable or disable weighted tangents
void SetWeighted( bool bWeighted, const CDmeCurveKey *pPrevKey, const CDmeCurveKey *pNextKey );
// Make the specified key match the unweighted form
void ConformUnweighted( const CDmeCurveKey *pPrevKey, const CDmeCurveKey *pNextKey );
void SetSelected( bool bSelect ) { m_Selected = bSelect; }
void SetInSelected( bool bSelect ) { m_InSelected = bSelect; }
void SetOutSelected( bool bSelect ) { m_OutSelected = bSelect; }
void SetKeyClean() { m_KeyDirtyFlags = KEY_CLEAN; }
void SetKeyInClean() { m_KeyDirtyFlags &= ~KEY_IN_DIRTY; }
void SetKeyOutClean() { m_KeyDirtyFlags &= ~KEY_OUT_DIRTY;}
void SetKeyInDirty() { m_KeyDirtyFlags |= KEY_IN_DIRTY; }
void SetKeyOutDirty() { m_KeyDirtyFlags |= KEY_OUT_DIRTY; }
// Tangent manipulation
void SetInTime( DmeTime_t dt ) { m_InTime = dt; }
void SetInDelta( float flDelta ) { m_InDelta = flDelta; }
void SetOutTime( DmeTime_t dt ) { m_OutTime = dt; }
void SetOutDelta( float flDelta ) { m_OutDelta = flDelta; }
// Accessors
bool IsSelected() const { return m_Selected; }
bool InTangentSelected() const { return m_InSelected; }
bool OutTangentSelected() const { return m_OutSelected; }
bool IsKeyWeighted() const { return m_Weighted; }
bool IsKeyUnified() const { return m_Unified; }
int GetComponent() const { return m_Component; }
DmeTime_t GetTime() const { return m_Time; }
float GetValue() const { return m_Value; }
DmeTime_t GetInTime() const { return m_InTime; }
float GetInDelta() const { return m_InDelta; }
DmeTime_t GetOutTime() const { return m_OutTime; }
float GetOutDelta() const { return m_OutDelta; }
bool IsKeyStepped() const { return m_OutMode == TANGENT_MODE_STEPPED; }
KeyTangentMode_t GetInMode() const { return ( KeyTangentMode_t )m_InMode.Get(); }
KeyTangentMode_t GetOutMode() const { return ( KeyTangentMode_t )m_OutMode.Get(); }
bool IsInTangentValid() const { return ( m_InTime != DMETIME_ZERO ); }
bool IsOutTangentValid() const { return ( m_OutTime != DMETIME_ZERO ); }
bool IsKeyDirty() const { return ( m_KeyDirtyFlags != KEY_CLEAN ); }
bool IsKeyInDirty() const { return ( m_KeyDirtyFlags & KEY_IN_DIRTY ) != 0; }
bool IsKeyOutDirty() const { return ( m_KeyDirtyFlags & KEY_OUT_DIRTY ) != 0; }
static int GetUnweightedDisplayLength() { return UNWEIGHTED_DISPLAY_LENGTH; }
private:
friend class CDmeGraphEditorCurve; // GraphEditorCurve is a friend so that it may manipulate the key values
friend class CUndoGraphEditorModifyKeys; // The modify keys undo element is also allowed to touch keys directly to restore state
// Key time and value manipulation, these functions are private as they are intended to be used
// only by the CDmeGraphEditorCurve to which the key belongs. This is because the curve needs
// to know when these values change, in particular the keys are stored ordered by time in the
// curve, so the change of key time may require re-ordering of the key list in the curve.
void SetTime( DmeTime_t time ) { m_Time = time; }
void SetValue( float value ) { m_Value = value; }
void SetInMode( KeyTangentMode_t mode ) { m_InMode = mode; }
void SetOutMode( KeyTangentMode_t mode ) { m_OutMode = mode; }
// Save all of the current values of the key internally.
void StoreCurrentValues();
// Mark the previous values as being invalid
void ClearPreviousValues() { m_bOldValuesValid = false; }
// The old values are copied from the current values of the key by calling StoreCurrentValues(). These
// are temporary values that are used to determine the delta values of operations. The following functions
// return the old values if they have been stored or the current values if the old values have not been stored.
bool GetPreviousStepped() const { return m_bOldValuesValid ? ( m_OldOutMode == TANGENT_MODE_STEPPED ) : ( m_OutMode == TANGENT_MODE_STEPPED ); }
DmeTime_t GetPreviousTime() const { return m_bOldValuesValid ? m_OldTime : m_Time; }
float GetPreviousValue() const { return m_bOldValuesValid ? m_OldValue : m_Value; }
DmeTime_t GetPreviousInTime() const { return m_bOldValuesValid ? m_OldInTime : m_InTime; }
float GetPreviousInDelta() const { return m_bOldValuesValid ? m_OldInDelta : m_InDelta; }
DmeTime_t GetPreviousOutTime() const { return m_bOldValuesValid ? m_OldOutTime : m_OutTime; }
float GetPreviousOutDelta() const { return m_bOldValuesValid ? m_OldOutDelta : m_OutDelta; }
// Multi-selected tangent state, these will return true if the specified tangent is selected or just the key is selected
bool InMultiSelected() const { return m_InSelected || ( m_Selected && !m_OutSelected ); }
bool OutMultiSelected() const { return m_OutSelected || ( m_Selected && !m_InSelected ); }
int m_Component; // Index of the component of the curve the key is associated with
int m_KeyDirtyFlags; // Flags indicating if the key has been changed and on which side
CDmaVar< bool > m_Selected; // "selected" : flag indicating if the key is currently selected
CDmaVar< bool > m_InSelected; // "inSelected" : flag indicating if the in tangent of the key is selected
CDmaVar< bool > m_OutSelected; // "outSelected" : flag indicating if the out tangent of the key is selected
CDmaVar< bool > m_Weighted; // "weighted" : flag indicating if the tangents of the keys are operating in weighted mode
CDmaVar< bool > m_Unified; // "unified" : flag indicating if the tangents of the key are to be manipulated together
CDmaVar< int > m_InMode; // "inMode" : mode in which the in tangent is currently operating
CDmaVar< int > m_OutMode; // "outMode" : mode in which the out tangent is currently operating
CDmaVar< DmeTime_t > m_Time; // "time" : The time the key is located at
CDmaVar< float > m_Value; // "value" : The value of the curve at the point of the key
CDmaVar< DmeTime_t > m_InTime; // "inTime" : The time length of the left tangent of the key
CDmaVar< float > m_InDelta; // "inDelta" : The delta value of the left tangent of the key
CDmaVar< DmeTime_t > m_OutTime; // "outTime" : The time length of the right tangent of the key
CDmaVar< float > m_OutDelta; // "outDelta" : The delta value of the right tangent of the key
bool m_bOldValuesValid; // Flag indicating if the set of old values have been stored and are valid
int m_OldInMode; // Previous in tangent operation mode
int m_OldOutMode; // Previous out tangent operation mode
DmeTime_t m_OldTime; // Previous time of the key
float m_OldValue; // Previous value of the key
DmeTime_t m_OldInTime; // Previous time length of the in tangent
float m_OldInDelta; // Previous delta value of the in tangent
DmeTime_t m_OldOutTime; // Previous time length of the out tangent
float m_OldOutDelta; // Previous delta value of the out tangent
};
//-----------------------------------------------------------------------------
// The CDmeEditCurve represents a channel which is being displayed for editing
// int the graph editor.
//-----------------------------------------------------------------------------
class CDmeGraphEditorCurve : public CDmElement
{
DEFINE_ELEMENT( CDmeGraphEditorCurve, CDmElement );
static const int MAX_COMPONENTS = LOG_MAX_COMPONENTS;
struct SamplePoint_t
{
DmeTime_t time;
float value;
};
public:
// Set the channel and components assigned to the curve and initialize the curve data.
void Initialize( CDmeChannel *pChannel, DmeFramerate_t framerate, bool bFrameSnap, const DmeClipStack_t &clipstack );
// Initialize the edit log.
void InitializeEditLog( DmeFramerate_t framerate, const DmeClipStack_t &clipstack );
// Make sure all results of curve editing are applied to the log
void Finalize();
// Determine if the CRC of the log is the same as the last time finalize was called on the curve
bool VerifyLogCRC() const;
// Compute the tangents of the specified key
void ComputeTangentsForKey( CDmeCurveKey *pKey, bool bStepped ) const;
// Set the tangents for the key to be the specified type
void SetKeyTangents( CDmeCurveKey *pKey, TangentOperation_t tangentType, bool bRespectSelection, float flUnitsPerSecond ) const;
// Add keys to the curve at the specified time for the specified components
void AddKeysAtTime( DmeTime_t time, LogComponents_t nComponentFlags, bool bComputeTangents, AddKeyMode_t addMode, bool bVisibleOnly );
// Remove all of keys at the specified time
bool RemoveKeysAtTime( DmeTime_t time );
// Add a key to the curve at the specified time on the specified component
void AddKeyAtTime( DmeTime_t time, int nComponent, bool bRecomputeNeigbors );
// Set the value of the key at the specified time or create a new key at the time with the specified value
CDmeCurveKey *SetKeyAtTime( DmeTime_t time, int nComponent, float flValue );
// Set the position value of the key at the specified time or create a new key at the time with the specified value
void SetKeyAtTime( DmeTime_t time, LogComponents_t nComponentFlags, const Vector &position );
// Set the position value of the key at the specified time or create a new key at the time with the specified value
void SetKeyAtTime( DmeTime_t time, LogComponents_t nComponentFlags, const Quaternion &orientation );
// Set the position value of the key at the specified time or create a new key at the time with the specified value
void SetKeyAtTime( DmeTime_t time, LogComponents_t nComponentFlags, const CDmAttribute *pAttr );
// Remove a key from the specified component of the curve at the specified time
bool RemoveKeyAtTime( DmeTime_t time, int nComponent );
// Find the keys within the specified time range
void FindKeysInTimeRange( CUtlVector< CDmeCurveKey * > &keyList, DmeTime_t startTime, DmeTime_t endTime, int nComponent );
// Offset the specified keys by the specified about of time
void OffsetKeyTimes( const CUtlVector< CDmeCurveKey * > &keyList, DmeTime_t timeDelta );
// Move the specified key by the specified amount
void MoveKeys( const CUtlVector< CDmeCurveKey * > &moveKeyList, DmeTime_t timeDelta, float flValueDelta,
const DmeClipStack_t &localTimeClipStack, DmeFramerate_t framerate, float flValueScale,
float timeScale, DmeTime_t cursorTime, bool bFrameSnap, bool bUnifiedTangents );
// Scale the specified keys about the specified
void ScaleKeys( const CUtlVector< CDmeCurveKey * > &keyList, float flTimeScaleFactor, float flValueScaleFactor,
DmeTime_t originTime, float flOriginValue, const DmeClipStack_t &localTimeClipStack, DmeFramerate_t framerate );
// Blend the specified keys toward the provided value using the specified blend factor
void BlendKeys( const CUtlVector< CDmeCurveKey * > &keyList, Vector4D targetValue, DmAttributeType_t targetValueType, float flBlendFactor );
// Blend the specified keys toward the value at the specified time using the specified blend factor
void BlendKeys( const CUtlVector< CDmeCurveKey * > &keyList, DmeTime_t targetValueTime, float flBlendFactor );
// Delete the specified keys from the curve
void DeleteKeys( const CUtlVector< CDmeCurveKey * > &keyList );
// Build the keys from the log bookmarks
void BuildKeysFromLog( DmeFramerate_t framerate, bool bFrameSnap, const DmeClipStack_t &graphClipStack );
// Update the edit layer for changes to the specified keys
void UpdateEditLayer( DmeFramerate_t framerate, const DmeClipStack_t &graphClipStack, bool bEditLayerUndoable, bool bOffsetMode );
// Flatten the layers of the edit log, overwriting the base log layer with the active edit layer
void FlattenEditLog();
// Get the range of values within the specified time range
bool GetValueRangeForTime( DmeTime_t minTime, DmeTime_t maxTime, float &minValue, float &maxValue ) const;
// Get the shot relative time of the specified key
DmeTime_t GetKeyShotTime( int nKeyIndex, int nComponent ) const;
// Get the shot relative time of the specified key
DmeTime_t GetKeyShotTime( CDmeCurveKey *pKey ) const;
// Get the shot relative time of the key and its tangents
void GetKeyShotTimes( CDmeCurveKey *pKey, DmeTime_t &keyTime, DmeTime_t &inTime, DmeTime_t &outTime ) const;
// Find the neighboring keys of the specified key
int FindKeyNeighbors( const CDmeCurveKey *pKey, CDmeCurveKey *&pPreviousKey, CDmeCurveKey *&pNextKey ) const;
// Build the clip stack for channel used by the the curve
bool BuildClipStack( DmeClipStack_t *pClipStack, CDmeClip *pRoot, CDmeClip *pShot ) const;
// Get the channels clip to which the channel of the curve belongs
CDmeChannelsClip *GetChannelsClip() const;
// Mark all components as not being visible
void ClearComponents();
// Add the specified components to the current set of components
void UpdateComponents( LogComponents_t nComponentFlags );
// Get the flag specifying which components of the log are to be displayed.
LogComponents_t GetComponentFlags() const;
// Get the number of components in the curve
int GetNumComponents() const;
// Determine if the component specified by index is visible
bool IsComponentVisible( int nComponentIndex ) const;
// Determine if the specified component is selected
bool IsComponentSelected( int nComponentIndex ) const;
// Set the selected state of the component
void SetComponentSelection( LogComponents_t nComponentIndex, SelectionMode_t selectionMode );
// Clear the component selection of the curve
void ClearComponentSelection();
// Get all of the keys for the components specified by the provided flags
void GetKeysForComponents( CUtlVector< CDmeCurveKey * > &keyList, LogComponents_t nComponentFlags ) const;
// Get the value of the specified component of the edit log at the specified time
float GetEditValue( DmeTime_t time, int nComponentIndex ) const;
// Return true if the specified channel is the one in use by the curve
bool IsCurveUsingChannel( const CDmeChannel *pChannel ) { return m_Channel == pChannel; }
// Accessors
CDmeChannel *GetChannel() const { return m_Channel; }
const CDmeLog *GetEditLog() const { return m_EditLog; }
const CDmeCurveKey *GetKey( int nIndex, int nComponent ) const { return m_KeyList[ nComponent ][ nIndex ]; }
CDmeCurveKey *GetKey( int nIndex, int nComponent ) { return m_KeyList[ nComponent ][ nIndex ]; }
int GetNumKeys( int nComponent ) const { return m_KeyList[ nComponent ].Count(); }
bool IsVisibleX() const { return GetValue< bool >( "xVisible", false ); }
bool IsVisibleY() const { return GetValue< bool >( "yVisible", false ); }
bool IsVisibleZ() const { return GetValue< bool >( "zVisible", false ); }
private:
// Find the key on the specified component at the specified time
int FindKeyAtLocalTime( DmeTime_t localTime, int nComponent ) const;
// Find the index of the specified key
int FindKeyIndex( const CDmeCurveKey *pKey ) const;
// Find the neighboring keys of the key with the specified index
void FindKeyNeighbors( int nKeyIndex, int nComponent, CDmeCurveKey *&pPreviousKey, CDmeCurveKey *&pNextKey ) const;
// Find the previous neighbors of the key using the stored key ordering list
bool FindOldKeyNeighbors( const CDmeCurveKey *pKey, CDmeCurveKey *&pPreviousKey, CDmeCurveKey *&pNextKey ) const;
// Find the key which was previously at the first key of the curve segment containing the specified time.
const CDmeCurveKey *FindOldSegmentForTime( DmeTime_t time, int nComponent ) const;
// Create a key at the specified time, with the specified value.
CDmeCurveKey *CreateKey( DmeTime_t time, float flValue, int nComponent, bool bRecomputeNeighbors );
// Remove the specified key from the curve
void RemoveKey( int nKeyIndex, int nComponent );
// Compute the tangents for the curve segment between the two keys
void ComputeKeyTangentsForSegment( CDmeCurveKey *pStartKey, CDmeCurveKey *pEndKey, bool bAllowStepped ) const;
// Update the tangent handles of keys based on the current mode
void UpdateTangentHandles();
// Update the key list so that all keys are valid and in order
void FixupKeyList( const CUtlVector< CDmeCurveKey * > &editKeyList );
// Make sure all of the keys are in order, but make no other changes to the keys
void SortKeyList();
// Make a copy of the current key list so that it may be used to compare the key ordering after changes have been made
void StoreCurrentKeyList();
// Clear the copy of the stored key list
void ClearCachedKeyList();
// Update the base log from the edit log.
void UpdateBaseLog( bool bUseEditLayer );
// Update the edit layer for changes to the specified keys
template < typename T >
void UpdateEditLayer( CDmeTypedLog< T > *pEditLog, DmeFramerate_t framerate, const DmeClipStack_t &graphClipstack, bool bEditLayerUndoable, bool bOffsetMode );
// Generate samples for the curve between two keys and write them into the edit layer
template < typename T >
void GenerateCurveSamples( const CDmeCurveKey *pKeyA, const CDmeCurveKey *pKeyB, CUtlVector< DmeTime_t > &sampleTimes, CUtlVector< T > &sampleValues, int nComponent,
const CDmeTypedLogLayer< T > *pBaseLayer, int &nLayerKeyIndex, DmeFramerate_t sampleRate, const DmeClipStack_t &clipstack, bool bOffsetMode ) const;
// Generate sample values for the specified component using the provided sample points
template < typename T >
void GenerateSampleValues( const CUtlVector< Vector2D > &points, const CUtlVector< DmeTime_t > &pointTimes, CUtlVector< DmeTime_t > &sampleTimes, CUtlVector< T > &sampleValues,
int nComponent, const CDmeTypedLogLayer< T > *pBaseLayer, int &nLayerKeyIndex, DmeFramerate_t sampleRate, const DmeClipStack_t &clipstack ) const;
// Generate sample values for the specified component using the provided previous curve points and the new curve points
template < typename T >
void GenerateOffsetSampleValues( const CUtlVector< Vector2D > &points, const CUtlVector< DmeTime_t > &pointTimes, const CUtlVector< Vector2D > &prevPoints,
const CUtlVector< DmeTime_t > &prevPointTimes, CUtlVector< DmeTime_t > &sampleTimes, CUtlVector< T > &sampleValues, int nComponent,
const CDmeTypedLogLayer< T > *pBaseLayer, int nLayerKeyIndex, DmeFramerate_t sampleRate, const DmeClipStack_t &clipstack, bool bRescaleTime ) const;
// Get the range of values within the specified time range for the specified log
template < typename T >
bool GetValueRangeForTime( CDmeTypedLog< T > *pEditLog, DmeTime_t minTime, DmeTime_t maxTime, float &minValue, float &maxValue ) const;
// Update the log bookmarks to match the keys
void UpdateLogBookmarks() const;
// Compute the crc of the log associated with channel
CRC32_t ComputeLogCRC() const;
// Re-scale the provided list of times from one time frame to another.
static void RescaleTimes( DmeTime_t prevStart, DmeTime_t prevEnd, DmeTime_t newStart, DmeTime_t newEnd, const CUtlVector< DmeTime_t > &oldTimes, CUtlVector< DmeTime_t > &newTimes );
// Interleave a set of times with times occurring at a regular global interval between the provided start and end time.
static void InterleaveGlobalSampleTimes( DmeTime_t startTime, DmeTime_t endTime, const CUtlVector< DmeTime_t > &existingSampleTimes, CUtlVector< DmeTime_t > &sampleTimes, DmeFramerate_t sampleRate, const DmeClipStack_t &clipstack );
private:
CDmaElement< CDmeChannel > m_Channel; // "channel" : The channel associated with the curve
CDmaElement< CDmeLog > m_EditLog; // "editLog" : Log that will be used for editing, for quaternions this is the log of Euler angles.
CDmaElementArray< CDmeCurveKey > m_KeyList[ MAX_COMPONENTS ]; // "keyList" : List of keys on the curve
CDmaVar< int > m_ComponentSelection; // "componentSelection" : Flags specifying which components are selected
CRC32_t m_logCRC; // CRC value of the log the last time Finalize() was called
CDmeLogLayer *m_pEditLayer; // Pointer to the log layer used to store the results of the curve manipulation
CUtlVector< CDmeCurveKey * > m_OldKeyList[ MAX_COMPONENTS ]; // A list of the ordering of keys before the current modification
friend class CUndoGraphEditorModifyKeys;
};
// Quaternion <==> Euler conversion utilities.
void QuaternionToEuler( const Quaternion &q, Vector &rotation, Vector &absRotation );
void EulerToQuaternion( const Vector &euler, Quaternion &quat );
bool ConvertLogEulerToQuaternion( const CDmeVector3LogLayer *pEulerLayer, CDmeQuaternionLogLayer *pQuatLayer );
bool ConvertLogQuaterionToEuler( const CDmeQuaternionLogLayer *pQuatLayer, CDmeVector3LogLayer *pEulerLayer, DmeFramerate_t sampleRate, const DmeClipStack_t &clipstack );
#endif // DMEGRAPHEDITORCURVE_H

View File

@@ -0,0 +1,128 @@
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
//
// Declaration of CDmeGraphEditorState, a data model element which stores
// the active state data for the graph editor.
//
//=============================================================================
#ifndef DMEGRAPHEDITORSTATE_H
#define DMEGRAPHEDITORSTATE_H
#ifdef _WIN32
#pragma once
#endif
#include "sfmobjects/dmegrapheditorcurve.h"
#include "movieobjects/dmechannel.h"
#include "movieobjects/dmebookmark.h"
#include "datamodel/dmelement.h"
// Function declaration for bookmark update callbacks.
typedef void (*FnUpdateBookmarks)( const CDmaElementArray< CDmeBookmark > &bookmarkSet, void *pData );
typedef void (*FnOnBookmarkTimeChange )( DmeTime_t oldTime, DmeTime_t newTime, void *pData );
//-----------------------------------------------------------------------------
// The CDmeGraphEditorState class is a data model element which represents the
// active state of the CGraphEditor class. It contains the visible curve set,
// selection, and curve handle data. It provides access to selection and
// handles, but does not perform any data manipulation.
//-----------------------------------------------------------------------------
class CDmeGraphEditorState : public CDmElement
{
DEFINE_ELEMENT( CDmeGraphEditorState, CDmElement );
public:
// Remove all curves from the list of active curves
void RemoveAllCurves();
// Add or update the specified channel for editing.
CDmeGraphEditorCurve *AddCurve( CDmeChannel *pChannel, DmeFramerate_t framerate, bool bFrameSnap, const DmeClipStack_t &clipstack );
// Find the graph editor curve for the specified channel
CDmeGraphEditorCurve *FindCurve( const CDmeChannel *pChannel ) const;
// Find the graph editor curve for the specified channel within the active set.
CDmeGraphEditorCurve *FindActiveCurve( const CDmeChannel *pChannel ) const;
// Find the graph editor curve with in the active set that is associated with a channel of the specified name.
CDmeGraphEditorCurve *FindActiveCurveByChannelName( const char *name ) const;
// Remove all curves from the list of active curves
void DeactiveateAllCurves();
// Remove and curves which do not remove to a valid channel
void RemoveInvalidCurves();
// Add the specified curve to the list of active curves
void MakeCurveActive( CDmeGraphEditorCurve *pCurve, LogComponents_t nComponents );
// Clear the current key selection
void ClearSelection();
// Select the specified keys according to the specified selection mode
void SelectKeys( const CUtlVector< CDmeCurveKey * > &keyList, SelectionMode_t selectionMode );
// Find the index of the the key in the selection set
int FindSelectedKey( const CDmeCurveKey *pKey ) const;
// Set the tangent selection for the specified keys
void SelectKeyTangents( const CUtlVector< CDmeCurveKey * > &keyList, const CUtlVector< bool > &inList,
const CUtlVector< bool > &outList, SelectionMode_t selectionMode );
// Select the specified component of the specified curve and all the keys on the component
void SelectCurveComponents( const CUtlVector< CDmeGraphEditorCurve * > &curveList, const CUtlVector < LogComponents_t > &nComponentFlagsList, SelectionMode_t selectionMode );
// Add a bookmark to the set at the specified time
CDmeBookmark *AddBookmark( DmeTime_t time, bool bAddToSet = true );
// Find a bookmark with the specified time
CDmeBookmark *FindBookmark( DmeTime_t time ) const;
// Remove all of the current bookmarks from the bookmark set
void ClearBookmarkSet();
// Rebuild the bookmark set from the specified list of times
void SetAllBookmarks( const CUtlVector< DmeTime_t > &times );
// Accessors
bool ShouldDisplayGrid() const { return m_bDisplayGrid; }
CDmaElementArray< CDmeBookmark > &GetBookmarkSet() { return m_BookmarkSet; }
const CDmaElementArray< CDmeBookmark > &GetBookmarkSet() const { return m_BookmarkSet; }
const CDmaElementArray< CDmeGraphEditorCurve > &GetFullCurveList() const { return m_CurveList; }
const CDmaElementArray< CDmeGraphEditorCurve > &GetActiveCurveList() const { return m_ActiveCurveList; }
const CDmaElementArray< CDmeCurveKey > &GetSelectedKeys() const { return m_SelectedKeys; }
private:
// Select the specified key according to the specified selection mode
void SelectKey( CDmeCurveKey *pKey, bool bInTangent, bool bOutTangent, SelectionMode_t selectionMode );
// Add the specified key to the selection
void AddKeyToSelection( CDmeCurveKey *pKey, bool bInSelection, bool bOutSelection );
// Remove the specified key from the selection
void RemoveKeyFromSelection( CDmeCurveKey *pKey, bool bInSelection, bool bOutSelection );
// Toggle the selection of the specified key
void ToggleKeySelection( CDmeCurveKey *pKey, bool bInSelection, bool bOutSelection );
// Remove the invalid curves from the specified array
static void RemoveInvalidCurves( CDmaElementArray< CDmeGraphEditorCurve > &curveList );
CDmaElementArray< CDmeGraphEditorCurve > m_CurveList; // "curveList" : Array of all curves currently available to the graph editor
CDmaElementArray< CDmeGraphEditorCurve > m_ActiveCurveList; // "activeCurveList" : Array of curves visible in the graph editor which will be modified by operations
CDmaElementArray< CDmeCurveKey > m_SelectedKeys; // "selectedKeys" : Array of curve keys that are currently selected
CDmaElementArray< CDmeBookmark > m_BookmarkSet; // "bookmarkSet" : Array of bookmark elements generated from the active log bookmarks
CDmaVar< bool > m_bDisplayGrid; // "displayGrid" : Flag indicating if the graph grid should be displayed
friend class CUndoGraphEditorSelectKeys;
};
#endif // DMEGRAPHEDITORSTATE_H

View File

@@ -0,0 +1,83 @@
//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =======
//
// A class representing a projected "light"
//
//=============================================================================
#ifndef DMEPROJECTEDLIGHT_H
#define DMEPROJECTEDLIGHT_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/dmelight.h"
//-----------------------------------------------------------------------------
// Forward declaration
//-----------------------------------------------------------------------------
struct LightDesc_t;
struct FlashlightState_t;
class CTextureReference;
//-----------------------------------------------------------------------------
// A spot light - includes shadow mapping parameters
//-----------------------------------------------------------------------------
class CDmeProjectedLight : public CDmePointLight
{
DEFINE_ELEMENT( CDmeProjectedLight, CDmePointLight );
public:
// Sets the spotlight direction
void SetFOV( float flHorizontalFOV, float flVerticalFOV );
float GetFOVx() const { return m_flHorizontalFOV; }
float GetFOVy() const { return m_flVerticalFOV; }
const char *GetFlashlightTexture() const { return m_Texture.Get(); }
void GetFlashlightState( FlashlightState_t &flashlightState, CTextureReference &texture ) const;
private:
CDmaVar< float > m_flMinDistance;
CDmaVar< float > m_flHorizontalFOV;
CDmaVar< float > m_flVerticalFOV;
CDmaVar< float > m_flAmbientIntensity;
CDmaString m_Texture;
CDmaVar< bool > m_bCastsShadows;
CDmaVar< float > m_flRadius;
CDmaVar< float > m_flShadowDepthBias;
CDmaVar< float > m_flShadowSlopeScaleDepthBias;
CDmaVar< float > m_flShadowFilterSize;
CDmaVar< float > m_flShadowJitterSeed;
CDmaVar< Vector2D > m_vPositionJitter;
CDmaTime m_AnimationTime;
CDmaVar< float > m_flFrameRate;
CDmaVar< float > m_flShadowAtten;
CDmaVar< bool > m_bDrawShadowFrustum;
CDmaVar< float > m_flFarZAtten;
CDmaVar< float > m_flAmbientOcclusion;
// Uberlight parameters
CDmaVar< bool > m_bUberlight;
CDmaVar< float > m_flNearEdge;
CDmaVar< float > m_flFarEdge;
CDmaVar< float > m_flCutOn;
CDmaVar< float > m_flCutOff;
CDmaVar< float > m_flWidth;
CDmaVar< float > m_flWedge;
CDmaVar< float > m_flHeight;
CDmaVar< float > m_flHedge;
CDmaVar< float > m_flRoundness;
CDmaVar< bool > m_bVolumetric;
CDmaVar< float > m_flNoiseStrength;
CDmaVar< float > m_flFlashlightTime;
CDmaVar< int > m_nNumPlanes;
CDmaVar< float > m_flPlaneOffset;
CDmaVar< float > m_flVolumetricIntensity;
};
#endif // DMEPROJECTEDLIGHT_H

View File

@@ -0,0 +1,149 @@
//====== Copyright © 1996-2004, 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 "tier1/utlvector.h"
#include "movieobjects/dmelog.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeAnimationSet;
class CDmeGameModel;
class CDmeFilmClip;
class CDmeChannelsClip;
class CDmElement;
class CDmeChannel;
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_MONO = 0,
CONTROL_RIGHT,
CONTROL_LEFT,
CONTROL_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;
CDmElement *m_pControl;
float m_flDefaultValue;
int m_pControllerIndex[CONTROL_FIELD_COUNT];
CDmeChannel *m_ppControlChannel[CONTROL_FIELD_COUNT];
ExistingLogInfo_t m_pExistingLog[CONTROL_FIELD_COUNT];
};
// Removes a channel from the channels clip referring to it.
void RemoveChannelFromClips( CDmeChannel *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 );
// Build list of existing flex controller logs
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 );
// 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 );
// 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

View File

@@ -0,0 +1,232 @@
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
//
// Declaration of the CGraphEditor class, which is used to perform direct
// manipulation of log data as if it were a curve.
//
//=============================================================================
#ifndef GRAPHEDITOR_H
#define GRAPHEDITOR_H
#ifdef _WIN32
#pragma once
#endif
#include "datamodel/dmelement.h"
#include "sfmobjects/dmegrapheditorstate.h"
class CDmeGraphEditorState;
//-----------------------------------------------------------------------------
// The CGraphEditor class performs direct manipulations of log data by fitting
// a cubic bezier curve to a segment of sample data and then manipulating the
// controls points of the curve.
//-----------------------------------------------------------------------------
class CGraphEditor
{
public:
enum PasteMode_t
{
PASTE_MERGE, // Keys are merged with other keys within the paste time range
PASTE_INSERT, // Keys after the paste location are offset in time by the paste time range
PASTE_OVERWRITE // Keys within the paste time range are removed
};
enum Operation_t
{
OPERATION_NONE,
OPERATION_MOVE_KEYS,
OPERATION_SCALE_KEYS,
OPERATION_SET_KEYS,
OPERATION_BLEND_KEYS,
OPERATION_COUNT,
};
// Constructor
CGraphEditor();
// Destructor
~CGraphEditor();
// Set the pointer to the current state element
void SetStateElement( CDmeGraphEditorState *pStateElement );
// Set the frame rate to be used by the graph editor when performing sampling operations
void SetFramerate( DmeFramerate_t framerate );
// Set the current clip stack, defining the local time frame in which the graph is operating
void SetClipstack( const DmeClipStack_t &clipStack );
// Get the pointer to the state element in use by the graph editor
CDmeGraphEditorState *GetStateElement();
// Start a new operation
void StartOperation();
// Finish the current operation and finalize the curve modifications
void FinishOperation();
// Cancel the current operation
void AbortOperation();
// Move the currently selected keys by the specified amount and time
void MoveSelectedKeys( DmeTime_t timeDelta, float valueDelta, float flValueScale, float timeScale, DmeTime_t cursorTime, bool bSnapToFrames, bool bUnifiedTangents, bool bEditLayerUndoable );
// Scale the currently selected keys by the specified amount using the provided origin
void ScaleSelectedKeys( float flTimeScaleFctor, float flValueScaleFactor, DmeTime_t originTime, float flOriginValue, bool bEditLayerUndoable );
// Delete the currently selected keys
bool DeleteSelectedKeys();
// Modify the tangents of the currently selected keys using the specified operation
bool ModifyTangents( TangentOperation_t operation, float flUnitsPerSecond, bool bUpdateLog );
// Remove all of the active curves from the graph editor
void RemoveAllCurves();
// Remove all of the curves from the list of active curves ( the ones visible in the graph editor )
void DeactivateAllCurves();
// Update the curves associated with the specified channels from their base log data
void UpdateActiveCurvesFromChannels( const CUtlVector< CDmeChannel * > &channelList );
// Set the active channels which are to be edited
void SetActiveChannels( CUtlVector< CDmeChannel * > &channelList, CUtlVector< LogComponents_t > &componentFlags, bool bFrameSnap );
// Set a key value for all active components of the curves associated with the specified channels
void SetKeysForChannels( const CUtlVector< CDmeChannel * > &channelList, DmeTime_t globalTime, bool bFinal );
// Set a key value for the specified components of the curve associated with the provided channel
void SetKeysForChannels( const CUtlVector< CDmAttribute * > &keyValueAttributes, const CUtlVector< CDmeChannel * > &channelList, const CUtlVector< LogComponents_t > &nComponentFlags, DmeTime_t globalTime, bool bFinal );
// Get the value of all of the components of the curve associated with the specified channel at the given time
int GetValuesForChannel( CDmeChannel *pChannel, DmeTime_t time, float *pValues, int nMaxValues ) const;
// Set the value of all of the components of the curve associated with the specified channel at the given time
bool SetValuesForChannel( CDmeChannel *pChannel, DmeTime_t time, const float *pValues, int nNumValues ) const;
// Blend the selected keys on each of the specified channels to the provided value for each channel
void BlendSelectedKeysForChannels( const CUtlVector< CDmeChannel * > &channelList, const CUtlVector< Vector4D > &valueList, float flBlendFactor, bool bFinal );
// Blend the selected keys on the curves associated with each of the specified channels to the value on the curve at the specified time.
void BlendSelectedKeysForChannels( const CUtlVector< CDmeChannel * > &channelList, DmeTime_t globalTargetTime, float flBlendFactor, bool bFinal );
// Select the specified set of keys according to the provided selection mode
void SelectKeys( CUtlVector< CDmeCurveKey * > &keyList, SelectionMode_t selectionMode );
// Select the specified keys and their tangents according to the specified selection mode
void SelectKeyTangents( CUtlVector< CDmeCurveKey * > &keyList, CUtlVector< bool > &inTangents, CUtlVector< bool > &outTangents, SelectionMode_t selectionMode );
// Select the specified component of the specified curve and all the keys on the component
void SelectCurveComponents( const CUtlVector< CDmeGraphEditorCurve * > &curveList, const CUtlVector < LogComponents_t > &nComponentFlagsList, SelectionMode_t selectionMode );
// Compute the tangent values of any selected keys that currently have invalid tangent values
void ComputeSelectedKeyTangents();
// Copy the currently selected keys to the clipboard
void CopySelectedKeys();
// Cut the currently selected keys and store them in the clipboard
void CutSelectedKeys();
// Paste the keys from the clipboard at the specified time
void PasteKeysFromClipboard( DmeTime_t pasteTime, PasteMode_t pasteMode, bool bConnect );
// Add a bookmark to the current curve set
void AddBookmark( CDmeBookmark *pBookmark );
// Remove a bookmark from the current curve set
void RemoveBookmark( CDmeBookmark *pBookmark );
// Update the time of the associated bookmark proxy if it no longer matches the bookmark.
void UpdateBookmarkTime( const CDmeBookmark *pBookmark, DmeTime_t oldTime );
// Get the composite set of bookmarks for all active curves
CDmaElementArray< CDmeBookmark > *GetBookmarkSet();
// Perform the required update when the time of a bookmark changes
void OnBookmarkTimeChange( DmeTime_t oldTime, DmeTime_t newTime );
// Get the number of selected keys
int GetNumSelectedKeys() const;
// Get the selected keys in arrays grouped by the curve to which the key belongs
int GetSelectedKeysByCurve( CUtlVector< CUtlVector< CDmeCurveKey * > > &curveKeyList, bool bIncludeNeighbors = false ) const;
// Get all of the keys on the active curves
int GetAllKeysByCurve( CUtlVector< CUtlVector< CDmeCurveKey * > > &curveKeyList ) const;
// Get all of the active curves
void GetActiveCurves( CUtlVector< CDmeGraphEditorCurve * > &curveList ) const;
// Get the current number of active curves
int GetNumActiveCurves() const;
// Compute the time selection for the currently selected keys
bool ComputeTimeSelction( DmeTime_t times[ TS_TIME_COUNT ] );
// Enable or disable offset mode
void EnableOffsetMode( bool bEnable );
// Determine if offset mode is enabled
bool IsOffsetModeEnabled() const;
// Enable or disable adding keys in stepped mode
void SetAddKeysStepped( bool bAddKeysStepped );
// Determine if add keys in stepped mode is enabled
bool IsAddingKeysStepped() const;
// Determine if the graph editor is currently performing a drag operation
bool IsDragging() const;
private:
struct OperationEntry_t
{
int mode; // Operation mode identifier
char name[ 32 ]; // Name of the operation (used for undo)
};
// Set the specified operation mode and perform initialization for that mode
void SetOperationMode( Operation_t mode );
// Finalize all of the modifications that have been made to the curves
void FinalizeChanges() const;
// Build the bookmark list from the current curve set
void BuildBookmarksFromCurves();
// Paste the keys from the provided curve data to the corresponding components of the destination curve
void PasteKeysToCurve( KeyValues *pCurveData, CDmeGraphEditorCurve *pDstCurve, DmeTime_t timeOffset, DmeTime_t timeSpan, PasteMode_t pasteMode, bool bConnect );
// Paste the keys from the provided component data to the corresponding destination curve component
void PasteKeysToComponent( KeyValues *pComponentData, CDmeGraphEditorCurve *pDstCurve, int nComponentIndex, DmeTime_t timeOffset, DmeTime_t timeSpan, PasteMode_t pasteMode, bool bConnect );
CDmeGraphEditorState *m_pState; // Pointer to the state element to be modified by the graph editor
DmeFramerate_t m_framerate; // Frame rate of the current document
DmeClipStack_t m_clipstack; // Clip stack from global time to the local time of the graph
bool m_bBuildingBookmarks; // Flag indicating if the building process is in progress
bool m_bStartOperation; // Flag specifying if the next call to set operation mode will start a new operation
bool m_bOffsetMode; // Flag indicating if the graph editor is operating in offset mode
bool m_bAddKeysStepped; // Flag indicating if new keys added should be created in stepped mode
Operation_t m_OperationMode; // The currently active operation mode
static const OperationEntry_t sm_OperationTable[];
static const OperationEntry_t sm_TangentOperationTable[];
};
#endif // GRAPHEDITOR_H

View File

@@ -0,0 +1,190 @@
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
//
// Declaration of CGraphEditorView class
//
//=============================================================================
#ifndef GRAPHEDITORVIEW_H
#define GRAPHEDITORVIEW_H
#ifdef _WIN32
#pragma once
#endif
#include "sfmobjects/grapheditor.h"
#include "loggraph.h"
// Forward declarations
class CDmeGraphEditorState;
// Function declarations for head time manipulation callbacks.
typedef void (*FnSetHeadTime )( DmeTime_t newTime, void *pData );
typedef void (*FnMoveHead )( int nPixels, void *pData );
typedef void (*FnScaleAboutHead )( float flScaleFactor, void *pData );
typedef void (*FnSetTimeSelection)( DmeTime_t times[ TS_TIME_COUNT ], void *pData );
// Enumeration for the major types of operations
// which can be performed within the graph editor view.
enum GraphOperationType_t
{
GRAPH_OPERATION_NONE,
GRAPH_OPERATION_SELECT,
GRAPH_OPERATION_ZOOM,
GRAPH_OPERATION_PAN,
GRAPH_OPERATION_DRAG_KEYS,
GRAPH_OPERATION_SCALE_KEYS,
};
//-----------------------------------------------------------------------------
// The CGraphEditorView provides a management and manipulation of the the graph
// editor and the graph display of the the curves and logs being edited.
//-----------------------------------------------------------------------------
class CGraphEditorView
{
public:
enum AxisMode_t
{
AXIS_MODE_XY,
AXIS_MODE_SELECT,
AXIS_MODE_X,
AXIS_MODE_Y
};
struct Point_t
{
Point_t() { x = 0; y = 0; }
Point_t( int xVal, int yVal ) { x = xVal; y = yVal; }
int x;
int y;
};
public:
// Constructor, sets the graph editor which is being viewed
CGraphEditorView( CGraphEditor &graphEditor );
// Set the head position and time manipulation callback functions
void SetCallbacks( FnSetHeadTime pfnSetHeadTime, FnMoveHead pfnSetMoveTime, FnScaleAboutHead pfnScaleAboutHead, FnSetTimeSelection pfnSetTimeSelection, void *pData );
// Set the area in which the curve graph may be drawn
void SetGraphDisplayBounds( int x, int y, int width, int height );
// Set the time range currently being displayed by the graph
void SetGraphTimeRange( DmeTime_t minTime, DmeTime_t maxTime );
// Set the active time range, this time range where the graph operations are effective, such as the time range of the current shot
void SetActiveTimeRange( DmeTime_t startTime, DmeTime_t endTime );
// Set the screen position
void SetScreenPosition( int x, int y );
// Draw the background of the graph
void DrawBackground( DmeFramerate_t frame, bool bDisplayFrames, bool bFrameSnap, const DmeClipStack_t &shotToRoot );
// Draw the graph elements
void Draw();
// Draw the selection preview of the keys
void DrawSelection() const;
// Start an operation of the specified type if an operation is not currently underway
bool StartOperation( GraphOperationType_t operationType );
// Complete the current active operation
void FinishOperation();
// Update the currently active operation
bool UpdateOperation( int nCursorPosX, int nCursorPosY, bool bCtrlDown, bool bAltDown, bool bShiftDown, bool bFrameSnap, DmeTime_t currentTime, SelectionMode_t selectionMode, bool bFinal );
// Apply the specified vertical scale to the the graph using the provided center location
void ApplyVerticalScale( int delta, int nCursorPosY );
// Set the vertical range of the graph
void SetVerticalRange( float minValue, float maxValue );
// Compute the bounding time and values of the current selection
bool ComputeSelectionBounds( DmeTime_t &minTime, DmeTime_t &maxTime, float &minValue, float &maxValue ) const;
// Determine if the cursor is currently within the graph display area
bool IsPointInGraphArea( int x, int y ) const;
// Find the curves at the specified location
void FindCurvesAtPosition( int nPosX, int nPosY, CUtlVector< CDmeGraphEditorCurve * > &curveList, CUtlVector< LogComponents_t > &componentFlags ) const;
// Accessors
GraphOperationType_t GetCurrentOperation() const { return m_CurrentOperation; }
AxisMode_t GetAxisMode() const { return m_AxisMode; }
const Rect_t &GetArea() const { return m_GraphArea; }
CLogGraph &GetLogGraph() { return m_LogGraph; }
private:
// Update the axis mode based on the mouse movement
bool UpdateAxisMode( bool bAxisLock );
// Update the panning operation
void UpdatePanning( bool bMoveHead, bool bAxisLock );
// Update the zoom operation
void UpdateZoom( bool bAxisLock );
// Update the current key manipulation operation
bool UpdateKeyManipulation( bool bAxisLock, bool bSnapToFrames, bool bUnifiedTangents, GraphOperationType_t operationType, bool bFinal );
// Update the selection operation
void UpdateSelection( SelectionMode_t selectionMode );
// Compute the selection rectangle base on the current cursor position and the pressed cursor position
void ComputeSelectionRectangle( const Point_t &startPoint, const Point_t &endPoint, Rect_t &rect ) const;
// Select the keys in the specified rectangle
void SelectKeysInRectangle( const Rect_t &rect, SelectionMode_t selectionMode );
// Get a list of the keys in the rectangle specified local to the panel
void FindKeysInRectangle( CDmeGraphEditorCurve *pCurve, const Rect_t &rect, CUtlVector< CDmeCurveKey * > &keyList ) const;
// Get a list of the tangents belonging to the provided keys that are in the specified rectangle
void FindKeyTangentsInRectangle( const Rect_t &rect, CUtlVector< CDmeCurveKey * > &keyList, CUtlVector< bool > &inTangents, CUtlVector< bool > &outTangents ) const;
// Get a list of the curves in the specified rectangle
void FindCurvesInRectangle( const Rect_t &rect, CUtlVector< CDmeGraphEditorCurve * > &curveList, CUtlVector< LogComponents_t > &componentFlags ) const;
// Determine which components of the specified curve intersect the specified rectangle
void FindCurveComponentsInRectangle( const Rect_t &rect, CDmeGraphEditorCurve *pCurve, LogComponents_t &nComponentFlags ) const;
// Determine if the specified log intersects the specified rectangle.
template < typename T >
void IsLogInRectangle( const Rect_t &rect, const CDmeTypedLog< T > *pLog, const DmeClipStack_t &curveClipStack, LogComponents_t &nComponentFlags ) const;
CGraphEditor &m_GraphEditor; // Graph editor instance used to manipulate the logs using curves
CLogGraph m_LogGraph; // Pointer to the log graph to be used to draw the logs
GraphOperationType_t m_CurrentOperation; // Current state of the panel, specifies what operations are currently happening
AxisMode_t m_AxisMode; // Current axis mode selected for panning
bool m_bUnifiedTangents; // Current unified tangent mode for tangent manipulations
SelectionMode_t m_SelectionMode; // Current selection mode ( add, remove, toggle )
Rect_t m_SelectionRect; // Current area selection rectangle
Rect_t m_GraphArea; // Graph area within the panel
float m_flVerticalScale; // Vertical scale (range) of the graph
DmeTime_t m_ActiveStartTime; // Start time of the active time range of the graph
DmeTime_t m_ActiveEndTime; // End time of the active time range of the graph
DmeTime_t m_StartDocTime; // Document time at the start of the current operation
DmeTime_t m_CurrentDocTime; // Current document time
Point_t m_CursorPos; // Position of the cursor when the last Think() occurred
Point_t m_CursorDelta; // Number of pixels the cursor moved during the last frame
Point_t m_StartCursorPos; // Cursor position at the start of the current operation
FnSetHeadTime m_pfnSetHeadTime; // Callback function for setting the head time
FnMoveHead m_pfnMoveHead; // Callback function for moving the head
FnScaleAboutHead m_pfnScaleAboutHead; // Callback function for scaling time about the head position
FnSetTimeSelection m_pfnSetTimeSelection; // Callback function for setting the current time selection
void *m_pCallbackData; // Pointer to be provided to the callback time
};
#endif // GRAPHEDITORPANEL_H

View File

@@ -0,0 +1,209 @@
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
//
// Declaration of CLogGraph, a utility for drawing logs in a graph with scale
// and offset.
//
//=============================================================================
#ifndef LOGGRAPH_H
#define LOGGRAPH_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui/VGUI.h"
#include "movieobjects/dmeclip.h"
#include "movieobjects/dmelog.h"
#include "materialsystem/materialsystemutil.h"
#include "mathlib/beziercurve.h"
#include "Color.h"
class CDmeGraphEditorCurve;
class CDmeCurveKey;
//-----------------------------------------------------------------------------
// The CLogGraph class provides functionality for drawing logs within a graph
// display. It stores the offset and scale of the graph and provides
// functionality to draw log data relative to graph.
//-----------------------------------------------------------------------------
class CLogGraph
{
public:
struct ColorSettings_t
{
Color m_BackgroundColor; // Color to fill the background area of the graph
Color m_TimeBoundsColor; // Color to draw the time range bounds overlay with
Color m_GridColor; // Color to draw the grid lines with
Color m_FontColor; // Color to draw the graph labels with
Color m_CurveColor; // Color to draw generic log curves with
Color m_SegmentColor; // Color to draw selected curve segments with
Color m_SelectionColor; // Color to draw the selection rectangle with
Color m_CrossHairColor; // Color to draw the cross hair with
Color m_KeyColor; // Color to draw keys with
Color m_KeySelectedColor; // Color to draw selected keys
Color m_KeyAddColor; // Color to draw keys being added to the selection
Color m_KeyRemoveColor; // Color to draw keys being removed from the selection
Color m_TangentColor; // Color to draw tangents with
Color m_BrokenTangentColor; // Color to draw the in tangent of broken tangent keys with
Color m_CurveColorX; // Color in which x components are to be displayed
Color m_CurveColorY; // Color in which y components are to be displayed
Color m_CurveColorZ; // Color in which z components are to be displayed
};
// Constructor
CLogGraph( float flMinScale, float flMaxScale );
// Set the screen space position of the graph area
void SetScreenPosition( int x, int y );
// Set the area in which the graph may be drawn
void SetGraphDisplayBounds( int x, int y, int width, int height );
// Set the time range being displayed by the graph
void SetGraphTimeRange( DmeTime_t minTime, DmeTime_t maxTime );
// Apply an offset to the graph range specified in pixels
void ApplyVerticalOffset( int nPixels );
// Get the current vertical scale ( total vertical value range )
float GetVerticalScale() const;
// Set the current vertical scale
void SetVerticalScale( float scale, float center );
// Set the vertical range of the graph
void SetVerticalRange( float minValue, float maxValue );
// Set the font with which the graph should display its text
void SetFont( vgui::HFont hFont );
// Set the colors with which the graph is to be displayed
void SetColors( const ColorSettings_t &colors );
// Draw the graph background
void DrawBackground( bool bDrawGrid, const DmeFramerate_t &frameRate, bool bDrawFrames, const DmeClipStack_t &shotToRoot ) const;
// Draw the bounds of the specified time range as rectangles extending to the edge of the graph area
void DrawTimeRangeBounds( DmeTime_t startTime, DmeTime_t endTime );
// Draw the specified rectangle to show the selection area
void DrawSelectionRect( const Rect_t &rect ) const;
// Draw a cross hair display across the graph at the specified location
void DrawCrosshair( int x, int y, const DmeFramerate_t &frameRate, bool bDrawFrames, bool bFrameSnap, const DmeClipStack_t &shotToRoot ) const;
// Draw the specified graph curve
void DrawGraphCurve( const CDmeGraphEditorCurve *pCurve, const DmeClipStack_t &channelToRoot ) const;
// Draw the specified set of keys
void DrawKeysSelectionPreview( const CUtlVector< CDmeCurveKey * > &keyList, const DmeClipStack_t &channelToRoot, int nSelectionMode ) const;
// Draw the specified log
void DrawLog( const CDmeLog *pLog, const DmeClipStack_t &channelToRoot, LogComponents_t componentFlags, DmeTime_t minTime = DMETIME_MINTIME, DmeTime_t maxTime = DMETIME_MAXTIME, const Color *pColor = NULL, IMesh *pMesh = NULL ) const;
// Get the pixel rectangle of a point at the specified location using the current rendering point size
void GetPointRect( float flValue, DmeTime_t time, Rect_t &rect ) const;
// Convert a panel coordinate into a graph pixel coordinate
void PanelPositionToPixel( int &x, int &y );
// Get the number of pixels per unit of time displayed on the graph
float GetPixelsPerSecond() const;
// Get the number of pixels per value unit
float GetPixelsPerUnit() const;
// Get the number of units per pixel
float GetUnitsPerPixel() const;
// Get the amount of time for single pixel in tenths of a ms
float GetTimePerPixel() const;
// Get the time for the specified pixel within the graph area
DmeTime_t GetTimeForPixel( int xPos ) const;
// Get the value for the specified pixel within the graph area
float GetValueForPixel( int yPos ) const;
// Get the x coordinate of the pixel representing the specified time within the graph
int GetPixelForTime( DmeTime_t time, RoundStyle_t roundStyle = ROUND_NEAREST ) const;
// Get the y coordinate of the pixel representing the specified time within the graph
int GetPixelForValue( float value, RoundStyle_t roundStyle = ROUND_NEAREST ) const;
// Compute the screen space position of the specified key
bool ComputeKeyPositionTangents( const CDmeCurveKey *pKey, const DmeClipStack_t &channelToRoot, Vector &vPos, Vector &vInPos, Vector &vOutPos, bool bScreenSpace ) const;
// Accessors
DmeTime_t GetMinTime() const { return m_MinTime; }
DmeTime_t GetMaxTime() const { return m_MaxTime; }
private:
// Get a temporary render mesh
IMesh *GetDynamicRenderMesh() const;
// Draw the keys for the specified curve
void DrawCurveKeys( const CDmeGraphEditorCurve *pCurve, const DmeClipStack_t &channelToRoot, IMesh *pMesh ) const;
// Draw the curve segments associated with the selected keys of the specified curve
void DrawSelectedCurveSegments( const CDmeGraphEditorCurve *pCurve, const DmeClipStack_t &channelToRoot, IMesh *pMesh ) const;
// Draw the curve segment between the two specified keys
void DrawCurveSegment( const CDmeCurveKey *pStartKey, const CDmeCurveKey *pEndKey, DmeTime_t channelMinTime, DmeTime_t channelMaxTime, IMesh *pMesh ) const;
// Draw the specified Bezier curve segment
void DrawCurveSegment( const CCubicBezierCurve< Vector > &curveSegment, IMesh *pMesh ) const;
// Draw a curve segment as a step
void DrawCurveStep( const Vector &vStart, const Vector &vEnd, IMesh *pMesh ) const;
// Draw the log of the specified type
template < typename T >
void DrawLog( const CDmeTypedLog< T > *pLog, const DmeClipStack_t &channelToRoot, LogComponents_t nComponentFlags, DmeTime_t minTime, DmeTime_t maxTime, const Color *pColor, IMesh *pMesh ) const;
// Draw the specified log layer
template < typename T >
void DrawLogLayer( const CDmeLog *pLog, const CDmeTypedLogLayer< T > *pLogLayer, const DmeClipStack_t &channelToRoot, LogComponents_t componentFlags, bool bSubLayer, DmeTime_t minTime, DmeTime_t maxTime, const Color *pColor, IMesh *pMesh ) const;
// Draw the specified set of keys from the provided log layer
template < typename T >
void DrawLogKeys( CUtlVector< LogKeyValue_t< T > > &displayKeys, LogComponents_t componentFlags, bool bSubLayer, DmeTime_t logMinTime, DmeTime_t logMaxTime, const Color *pColor, IMesh *pMesh ) const;
// Compute the screen space position of the specified key
bool ComputeKeyPosition( const CDmeCurveKey *pKey, DmeTime_t timeMin, DmeTime_t timeMax, Vector &vPos ) const;
// Compute the screen space position of the specified key
bool ComputeKeyPositionTangents( const CDmeCurveKey *pKey, DmeTime_t timeMin, DmeTime_t timeMax, Vector &vPos, Vector &vInPos, Vector &vOutPos, bool bScreenSpace, bool bNormalizeUnweighted, float flPointOffset = 0 ) const;
CMaterialReference m_pMaterial; // Material to be used to draw the logs
vgui::HFont m_hFont; // Font to be used to draw the value labels on the graph
int m_nPointSize; // Size to be used when rendering a point.
const float m_flMinScale; // Minimum range between the min value and the max value
const float m_flMaxScale; // Maximum range between the min value and the max value
float m_flMinValue; // Minimum value visible on the graph
float m_flMaxValue; // Maximum value visible on the graph
DmeTime_t m_MinTime; // Minimum time visible on the graph
DmeTime_t m_MaxTime; // Maximum time visible on the graph
int m_nScreenPosX; // Offset of the graph area in screen space
int m_nScreenPosY; // Offset of the graph area in screen space
int m_nAreaX; // X Coordinate of the upper left corner of the graph display area
int m_nAreaY; // Y Coordinate of the upper left corner of the graph display area
int m_nAreaWidth; // Width of the graph display area
int m_nAreaHeight; // Height of the graph display area
ColorSettings_t m_ColorSettings; // Structure containing the color settings to be used by the graph
};
DmeTime_t GetTimeForFrame( float frame, const DmeFramerate_t &framerate );
#endif // LOGGRAPH_H

View File

@@ -0,0 +1,231 @@
//====== Copyright © 1996-2004, 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
#include "tier1/UtlVector.h"
#include "tier1/UtlDict.h"
#include "tier1/UtlString.h"
#include "datamodel/dmattributevar.h"
#include "dme_controls/BaseAnimationSetEditorController.h"
//-----------------------------------------------------------------------------
// movieobjects
//-----------------------------------------------------------------------------
class CDmeCamera;
class CDmeFilmClip;
class CDmeGameModel;
class CDmeAnimationSet;
class CDmeGameModel;
class CDmeProjectedLight;
class CDmePresetGroup;
class CDmeChannelsClip;
class CDmeTransform;
class CDmeChannel;
class CDmeLog;
class CStudioHdr;
extern const char *g_pSuffix[];
extern DmAttributeType_t g_ChannelTypes[];
enum ControlType_t
{
CONTROL_TYPE_POSITION = 0,
CONTROL_TYPE_ORIENTATION = 1,
};
enum LogPreviewChannelType_t
{
LOG_PREVIEW_VALUE = 0,
LOG_PREVIEW_VALUE_RIGHT,
LOG_PREVIEW_VALUE_LEFT,
LOG_PREVIEW_FLEX_CHANNEL_COUNT,
LOG_PREVIEW_POSITION = 0,
LOG_PREVIEW_ORIENTATION,
LOG_PREVIEW_TRANSFORM_CHANNEL_COUNT,
LOG_PREVIEW_MAX_CHANNEL_COUNT = LOG_PREVIEW_FLEX_CHANNEL_COUNT,
};
struct LogPreview_t;
struct Context_t
{
DECLARE_FIXEDSIZE_ALLOCATOR( Context_t );
public:
Context_t() :
m_bHighlight( false ),
m_bValid( false ),
m_bHasAncestorsBeingManipulated( false )
{
SetIdentityMatrix( m_InitialBoneToWorld );
SetIdentityMatrix( m_InitialWorldToBone );
SetIdentityMatrix( m_InitialBoneMatrix );
m_CurrentWorldPosition.Init();
SetIdentityMatrix( m_InitialTranslationWorldToParent );
}
void InitContext( const LogPreview_t *lp );
void UpdatePosition( bool bInitialAndCurrent );
// from TxForm_t
CUtlString m_basename;
bool m_bHighlight : 1;
bool m_bValid : 1;
bool m_bHasAncestorsBeingManipulated : 1;
CDmeHandle< CDmeDag > m_hDrag;
// those originally used by DragContextList
matrix3x4_t m_InitialBoneToWorld;
matrix3x4_t m_InitialWorldToBone;
matrix3x4_t m_InitialBoneMatrix;
// those originally used by FullTransformList
Vector m_CurrentWorldPosition;
matrix3x4_t m_InitialTranslationWorldToParent;
};
struct LogPreview_t : public SelectionInfo_t
{
DECLARE_FIXEDSIZE_ALLOCATOR( LogPreview_t );
public:
LogPreview_t() : SelectionInfo_t(), m_pTransformContext( NULL ) {}
LogPreview_t( CDmeAnimationSet *pAnimSet, CDmElement *pControl, TransformComponent_t nComponentFlags );
bool IsEqual( const LogPreview_t& other ) const
{
if ( m_hControl != other.m_hControl )
return false;
for ( int i = 0; i < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++i )
{
if ( m_hChannels[ i ] != other.m_hChannels[ i ] )
return false;
}
if ( m_hOwner != other.m_hOwner )
return false;
if ( m_nComponentFlags != other.m_nComponentFlags )
return false;
return true;
}
bool operator==( const LogPreview_t& other ) const
{
return IsEqual( other );
}
LogComponents_t GetLogComponentFlagsForChannel( int nChannel )
{
// If the control is a transform control convert the flags from transform component flags to log component flags
if ( m_pTransformContext )
{
return ConvertTransformFlagsToLogFlags( m_nComponentFlags, ( nChannel == LOG_PREVIEW_ORIENTATION ) );
}
// For all other controls consider all components selected
return LOG_COMPONENTS_ALL;
}
CDmeChannel *GetSelectedChannel( int nChannel )
{
if ( nChannel >= LOG_PREVIEW_MAX_CHANNEL_COUNT )
return NULL;
// If the control is a transform control check the flags to determine if the specific channel is selected
if ( m_pTransformContext )
{
if ( ( nChannel == LOG_PREVIEW_POSITION ) && ( ( m_nComponentFlags & TRANSFORM_COMPONENT_POSITION ) == 0 ) )
return NULL;
if ( ( nChannel == LOG_PREVIEW_ORIENTATION ) && ( ( m_nComponentFlags & TRANSFORM_COMPONENT_ROTATION ) == 0 ) )
return NULL;
}
return m_hChannels[ nChannel ];
}
CDmeHandle< CDmeChannel > m_hChannels[ LOG_PREVIEW_MAX_CHANNEL_COUNT ];
CDmeHandle< CDmeChannelsClip > m_hOwner;
Context_t *m_pTransformContext;
};
struct MDLSquenceLayer_t;
//-----------------------------------------------------------------------------
// Creates an animation set
//-----------------------------------------------------------------------------
CDmeAnimationSet *CreateEmptyAnimationSet( CDmeFilmClip *pClip, const char *pSetName, CDmeChannelsClip **ppChannelsClip = NULL, CDmeControlGroup**ppControlGroup = NULL );
CDmeAnimationSet *CreateAnimationSetForDag( CDmeFilmClip *pClip, const char *pSetName, CDmeDag *pDag );
CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pClip, const char *pSetName, CDmeCamera *pCamera );
CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pClip, const char *pSetName, CDmeProjectedLight *pLight );
CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pMovie, CDmeFilmClip *pShot, CDmeGameModel *pGameModel, const char *pAnimationSetName, bool bAttachToGameRecording, CDmElement *pSharedPresetGroupSettings );
CDmeGameModel *CreateGameModel( CDmeFilmClip *pShot, const char *pRelativeName );
// building blocks for creating animationsets (don't contain undo scopes)
void AddFloatControlToAnimationSet( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeChannelsClip *pDstChannelsClip, CDmeControlGroup *pControlGroup, CDmAttribute *pSrcAttr, float flMin = 0.0f, float flMax = 1.0f, float flDefault = -FLT_MAX );
void AddColorControlToAnimationSet( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeChannelsClip *pDstChannelsClip, CDmeControlGroup *pControlGroup, CDmAttribute *pSrcAttr );
void AddTransformControlsToAnimationSet( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeChannelsClip *pDstChannelsClip, CDmeControlGroup *pControlGroup, CDmeTransform *pTransform, const char *pControlName );
void AddLocalViewTargetControl( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
void AddEyeConvergenceControl( CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
void AddViewTargetControl( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
void AddIllumPositionAttribute( CDmeGameModel *pGameModel );
void BuildGroupMappings( CDmeAnimationSet *pAnimationSet );
CDmeTrack *GetAnimationSetTrack( CDmeFilmClip *pFilmClip, bool bCreateIfMissing );
CDmeChannelsClip* CreateChannelsClip( CDmeAnimationSet *pAnimationSet, CDmeFilmClip *pOwnerClip );
CDmeChannelsClip *FindChannelsClip( CDmeDag *pDag );
CDmeChannelsClip *FindChannelsClip( CDmeAnimationSet *pAnimSet );
CDmeDag *GetAnimSetTargetDag( CDmeAnimationSet *pAnimSet );
CDmeChannel *FindChannelTargetingTransform( CDmeChannelsClip *pChannelsClip, CDmeTransform *pTransform, ControlType_t controlType );
void CreateTransformChannels( CDmeTransform *pTransform, const char *pBaseName, CDmeChannelsClip *pChannelsClip );
void CreateAnimationLogs( CDmeChannelsClip *channelsClip, CDmeGameModel *pModel, const CStudioHdr &hdr, int sequence, float flStartTime, float flDuration, float flTimeStep );
void ImportAnimationLogs( CUtlVector< KeyValues* > &importData, DmeTime_t &duration, DmeTime_t startTime, DmeFramerate_t framerate, CDmeFilmClip *pMovie, CDmeFilmClip *pShot, CUtlLinkedList< LogPreview_t* > &controls, CDmeGameModel *pModel, int sequence, const CUtlVector< float > *pPoseParameters = NULL, const CUtlVector< MDLSquenceLayer_t > *pLayers = NULL, bool bRootMotion = true );
void DestroyLayerData( CUtlVector< KeyValues* > &layerData );
void RetimeLogData( CDmeChannelsClip *pSrcChannelsClip, CDmeChannelsClip *pDstChannelsClip, CDmeLog *pLog );
void TransferRemainingChannels( CDmeFilmClip *shot, CDmeChannelsClip *destClip, CDmeChannelsClip *srcClip );
template < class T >
CDmeChannel *CreateConstantValuedLog( CDmeChannelsClip *channelsClip, const char *pName, CDmElement *pToElement, const char *pToAttr, const T &value );
CDmeTransformControl *CreateTransformControlAndChannels( const char *pName, CDmeTransform *pTransform, CDmeChannelsClip *pSrcChannelsClip, CDmeChannelsClip *pDstChannelsClip, CDmeAnimationSet *pAnimationSet, bool bUseExistingLogData );
void SetupBoneTransform( CDmeChannelsClip *pSrcChannelsClip, CDmeChannelsClip *pDstChannelsClip, CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, const CStudioHdr &hdr, int bonenum, bool bUseExistingLogData );
// Finds a channel in the animation set to overwrite with import data
CDmeChannel* FindImportChannel( CDmeChannel *pChannel, CDmeChannelsClip *pChannelsClip );
// Transforms an imported channel, if necessary
void TransformBoneChannel( CDmeChannel *pChannel, bool bImport );
bool ImportChannel( CDmeChannel *pChannel, CDmeChannelsClip *pChannelsClip );
void GetChannelsForControl( const CDmElement *control, CDmeChannel *channels[LOG_PREVIEW_MAX_CHANNEL_COUNT] );
void GetChannelsForControl( const CDmElement *pControl, CUtlVector< CDmeChannel* > &channels );
void GetControlChannelsForAnimSet( CDmeAnimationSet *pAnimSet, CUtlVector< CDmeChannel* > &channels );
void ImportAnimation( CDmeChannelsClip *pImportedChannelsClip, CDmeAnimationSet *pAnimSet, int *pNumMatchingChannels, int *pNumMissingChannels, int *pNumSkippedChannels );
#endif // SFMANIMATIONSETUTILS_H

View File

@@ -0,0 +1,108 @@
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
//
// Purpose:
//=============================================================================
#ifndef SFMANIMSETSCRIPTCONTEXT_H
#define SFMANIMSETSCRIPTCONTEXT_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/dmechannel.h"
#include "tier1/timeutils.h"
// Forward declarations
class CDmElement;
class CDmeClip;
class CDmeFilmClip;
class CDmeAnimationSet;
class CDmeGameModel;
class CDmeChannelsClip;
class CDmeDag;
class CDmeRigHandle;
class CDmeChannel;
class CDmeTransformControl;
class CDmeRigBaseConstraintOperator;
class CDmeConstraintTarget;
class CDmeRig;
class CStudioHdr;
//-------------------------------------------------------------------------------------------------
// CSFMAnimSetScriptContext
//
//-------------------------------------------------------------------------------------------------
class CSFMAnimSetScriptContext
{
public:
// Constructor
CSFMAnimSetScriptContext( CDmeAnimationSet *pAnimSet, CDmeFilmClip *pShot, CDmeClip *pMovie, DmeTime_t time, ChannelMode_t channelMode );
// Destructor
~CSFMAnimSetScriptContext();
// Add the specified dag node to the animation set
void AddDagNode( CDmeDag *pDagNode, CDmeRig *pRig, const char *pchControlGroupPath = 0, bool bPositionControl = true, bool bOrientationControl = true ) const;
// Remove the specified rig handle from the animation set
void RemoveRigHandle( CDmeRigHandle *pRigHandle ) const;
// Add the specified constraint to the animation set
void AddConstraint( CDmeRigBaseConstraintOperator *pConstraint, CDmeRig *pRig, const char *pchControlGroupPath = 0 ) const;
// Find any dag node within the animation set with the specified name
CDmeDag *FindDagNode( const char *pchName ) const;
// Find the dag node associated with the specified bone
CDmeDag *FindBoneDag( const char *pchBoneName ) const;
// Set the channel operation mode for all of the channels in the the clip associated with the animation set
void SetChannelMode( ChannelMode_t mode );
// Set the current time and update the time of the channels in the animation set.
void SetCurrentTime( DmeTime_t time );
// Get the animation set associated with the context
CDmeAnimationSet *GetAnimationSet() const { return m_pAnimSet; }
// Get the gameModel associated with the context
CDmeGameModel *GetGameModel() const { return m_pGameModel; }
private:
// Create the position and rotation channels for the specified dag node.
//void CreateTransformChannels( CDmeDag *pDag, CDmeChannel *channels[ 2 ], bool bPosition, bool bRotation ) const;
// Create a transform control of the specified type for the provided dag node and attach it to the specified channel.
CDmeTransformControl *CreateTransformControl( CDmeDag *pDag ) const;
// Create the weight channels for the specified constraint
void CreateWeightChannels( CDmeRigBaseConstraintOperator *pConstraint, CDmeRig *pRig ) const;
// Create a control for the specified weight channel and add it to the animation set
CDmElement *CreateWeightControl( const char *pBaseName, CDmeConstraintTarget *pTarget, CDmeChannel *pDagChannel, bool rig ) const;
// Add a control with the specified name at the specified location to the animation set
void AddControl( CDmElement *pControl, const char *pchGroupPath ) const;
private:
bool m_bValid; // Flag indicating if the context is ready to perform operations
DmeTime_t m_CurrentTime; // Current time at which the script is operating
ChannelMode_t m_ChannelMode; // Current channel operation mode
CDmeClip *m_pMovie; // Current movie in which the script is operating
CDmeFilmClip *m_pShot; // Current shot in which the script is operating
CDmeAnimationSet *m_pAnimSet; // Animation set on which the script is operating
CDmeChannelsClip *m_pChannelsClip; // Channels clip for the animation set
CDmeGameModel *m_pGameModel; // Game model associated with the animation set
CStudioHdr *m_pStudioHdr; // Pointer to a studio model header interface instance
};
//-------------------------------------------------------------------------------------------------
#endif // SFMANIMSETSCRIPTCONTEXT_H

View File

@@ -0,0 +1,12 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose: See notes below
//
//=============================================================================
#include "sfmobjects/sfmobjects.h"
#include "datamodel/dmelementfactoryhelper.h"
// This hack causes the class factories for the element types to be imported into the compiled code...
USING_ELEMENT_FACTORY( DmeGraphEditorState );

View File

@@ -0,0 +1,15 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef SFMOBJECTS_H
#define SFMOBJECTS_H
#ifdef _WIN32
#pragma once
#endif
#include "sfmobjects/dmegrapheditorstate.h"
#endif // SFMOBJECTS_H

View File

@@ -0,0 +1,164 @@
//====== Copyright © 1996-2005, 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"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeSoundClip;
class CDmeGameSound;
class CDmeAnimationSet;
class CDmeFilmClip;
struct LogPreview_t;
//-----------------------------------------------------------------------------
// 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;
bool m_bFullPathInSoundName;
// 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_bFullPathInSoundName( 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_bFullPathInSoundName = src.m_bFullPathInSoundName;
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

View File

@@ -0,0 +1,122 @@
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef SFMRIGBUILDCONTEXT_H
#define SFMRIGBUILDCONTEXT_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/dmerigconstraintoperators.h"
#include "movieobjects/dmelog.h"
#include "studio.h"
#include "tier1/utldict.h"
class CDmeAnimationSet;
class CDmeFilmClip;
class CDmeClip;
class CDmeRigHandle;
class CDmeChannelsClip;
class CDmeGameModel;
class CRigBuildContext
{
public:
enum
{
DESC_SKELETON = (1<<0),
DESC_RIG = (1<<1),
DESC_CONSTRAINTS = (1<<2),
DESC_ALL = DESC_SKELETON | DESC_RIG | DESC_CONSTRAINTS,
};
enum eRigBuildContextType
{
RBC_ATTACH = 0,
RBC_DETACH,
};
explicit CRigBuildContext( eRigBuildContextType type, CDmeAnimationSet *pAnimSet, CDmeFilmClip *pShot, CDmeClip *pMovie );
~CRigBuildContext();
bool IsValid();
CDmeRigHandle *FindRigHandle( char const *pchHandleName );
CDmeRigHandle *CreateRigHandle( char const *pchHandleName, char const *pchRigSubGroup, const Vector &p, const Quaternion &q );
CDmeRigBaseConstraintOperator *FindOrAddConstraintTypeForObject( bool *pbUpdatingHandles, EConstraintType eType, char const *pchObjectName, char const *pchConstraintName, const DmFileId_t &fileId );
void CreateWeightChannels( CDmeRigBaseConstraintOperator *pConstraint, int nCount, CDmeDag *const pRigHandles[] );
Vector GetBonePosition( char const *pchBoneName ) const;
CDmeDag *FindBone( const char *pchBoneName ) const;
void SetRigName( char const *pchRigName );
void Describe( int flags );
void DisconnectBoneChannel( CUtlVector< CDmeChannel * > &list, int boneIndex, CDmeDag *pBone, EConstraintType eType );
void AttachHandleToBone( CDmeRigHandle *pRigHandle, CDmeDag *pBone ) const;
// Creates a new set of bone channels for the "detached" bone
void PerformDetach();
void FinishAttach();
protected:
CDmeRigBaseConstraintOperator *InstanceConstraint( EConstraintType eType, char const *pchName, const DmFileId_t &fileId );
void CreateRigHandleChannels( CDmeChannel *list[ 2 ], CDmeChannelsClip *pChannelsClip, CDmeRigHandle *pHandle );
CDmElement *CreateRigAnimationSetControl( CDmeAnimationSet *pAnimSet, CDmeDag *pDag, CDmeChannel *pDagChannel, int controlType );
void AddControlToAnimationSetRig( CDmeAnimationSet *pAnimSet, char const *pchGroupName, char const *pchControlGroupName, char const *pchControlName );
CDmeChannelsClip* CreateChannelsClip();
void CreateTransformChannels( CDmeDag *pDag, const char* baseName, CDmeChannelsClip *pChannelsClip );
void DescribeSkeleton();
void DescribeRig();
void DescribeConstraints();
void DescribeSkeleton_R( int depth, CDmeDag *bone );
void DescribeOperatorsForDag( int depth, CDmeDag *pDag );
CDmeChannel *DisconnectBoneChannel( CDmeDag *pBone, char const *pchTargetAttribute );
void DetachAddBoneChannelsToChannelsClip( CUtlVector< CDmeChannel * > &boneChannels );
void DetachCreateBoneChannels( CStudioHdr &hdr, CUtlVector< CDmeChannel * > &boneChannels );
void DetachGatherAllOperators( CUtlRBTree< CDmeOperator * > &operators );
void AttachInit();
void DetachInit();
CDmeDag *FindSceneRoot();
void InsertSubHandles_R( CDmeRigHandle *pRoot );
void FindChannelsForDag( CDmeDag* pDagNode, CUtlRBTree< CDmeOperator * > &operators );
void FindBoneChannels_R( CDmeDag *bone, CUtlRBTree< CDmeOperator * > &operators );
void FindBoneChannels( CUtlRBTree< CDmeOperator * > &operators );
void FindRigHandleChannels( CUtlRBTree< CDmeOperator * > &operators );
public:
bool m_bValid;
int m_nRigNumber;
DmeLog_TimeSelection_t m_timeSelection;
CDmeHandle< CDmeAnimationSet > m_hAnimationSet;
CDmeHandle< CDmeFilmClip > m_hShot;
CDmeHandle< CDmeClip > m_hMovie;
CDmeHandle< CDmeGameModel > m_hGameModel;
CDmeHandle< CDmeDag > m_hRigSceneRoot;
CDmeHandle< CDmeChannelsClip > m_hDstChannelsClip;
const CStudioHdr *m_pStudioHdr;
matrix3x4_t m_ReferencePoseBoneToWorld[ MAXSTUDIOBONES ];
CUtlVector< CDmeChannel * > m_DetachChannels;
CUtlDict< CDmeHandle< CDmeRigHandle >, short > m_RigHandles;
CUtlVector< CDmeHandle< CDmeRigBaseConstraintOperator > > m_Constraints;
};
#endif // SFMRIGBUILDCONTEXT_H

View File

@@ -0,0 +1,54 @@
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef SFMRIGUTILS_H
#define SFMRIGUTILS_H
#ifdef _WIN32
#pragma once
#endif
#include "movieobjects/dmerigconstraintoperators.h"
#include "movieobjects/dmechannel.h"
#include "dmeutils/dmanimutils.h"
class CDmeAnimationSet;
class CDmeFilmClip;
class CDmeClip;
class CDmeChannelsClip;
class CDmeRigHandle;
class CDmeRig;
class CDmeTransformControl;
class CSFMAnimSetScriptContext;
class CStudioHdr;
void SpewChannel( CDmeChannel *ch );
int FindBoneIndex( CStudioHdr const* pStudioHdr, const char* pName );
class CSFMRigUtils
{
public:
// Create a rig handle with the specified name with the specified position and orientation
static CDmeRigHandle *CreateRigHandle( const char *pchName, const Vector &position, const Quaternion &orientation, CDmeFilmClip *pShot );
// Destroy the specified rig handle and remove it from the animation set.
static void DestroyRigHandle( CDmeRigHandle *pRigHandle, CDmeFilmClip *pShot, CSFMAnimSetScriptContext *pAnimSetContext = NULL );
// Generate logs of all dag nodes controlled by the rig and then destroy all elements of the rig.
static void DetachRig( CDmeRig *pRig, CDmeFilmClip *pShot );
// Detach all rigs and constraints from the animation set
static void DetachAllRigs( CDmeAnimationSet *pAnimSet );
// Determine if the specified animation set has any rig components (rig handles, constraints, display sets)
static bool HasRigComponents( CDmeAnimationSet *pAnimSet );
};
#endif // SFMRIGUTILS_H

View File

@@ -0,0 +1,304 @@
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
//
// Purpose: CSFMScriptMgr declaration, defines the interface of the sfm script
// manager class which is used to run scripts and provides and interface for
// script commands to perform operations.
//
//=============================================================================
#ifndef SFMSCRIPTMGR_H
#define SFMSCRIPTMGR_H
#ifdef _WIN32
#pragma once
#endif
#include "sfmobjects/sfmrigutils.h"
#include "movieobjects/dmechannel.h"
#include "tier1/UtlBuffer.h"
#include "tier1/UtlStack.h"
#include "tier1/fmtstr.h"
// Forward declarations
class CDmeDag;
class CDmeClip;
class CDmeFilmClip;
class CDmeAnimationSet;
class CDmeRigHandle;
class CDmeRigBaseConstraintOperator;
class CDmeRig;
class CDmeGameModel;
class CSFMAnimSetScriptContext;
class CDmePresetGroupInfo;
//-------------------------------------------------------------------------------------------------
// CSFMScriptContext -- The script context class is a storage container which provides information
// to the script manager about the current state, including dag node and time selection.
//
//-------------------------------------------------------------------------------------------------
class CSFMScriptContext
{
public:
enum SelectMode_t
{
SELECT_ADD,
SELECT_REMOVE,
SELECT_TOGGLE,
};
public:
// Constructor
CSFMScriptContext( CDmeClip *pMovie, CDmeFilmClip *pShot, DmeTime_t time, DmeFramerate_t framerate, CDmeAnimationSet *pActiveAnimSet = NULL, const CUtlVector< CDmeDag * > *pSelectedDagList = NULL, CDmElement *pSharedPresetGroupSettings = NULL );
// Destructor, destroys the animation set context if created
~CSFMScriptContext();
// Get dag node the primary selection
CDmeDag *PrimaryDagSelection() const;
// Clear the current selection.
void ClearSelection();
// Add the specified node to the current selection.
void AddToSelection( CDmeDag *pDagNode, SelectMode_t mode );
// Remove the specified dag node from the current selection
bool RemoveFromSelection( CDmeDag *pDagNode, bool preserveOrder = true );
// Add the list of dag nodes to the current selection
void AddListSelection( const CUtlVector< CDmeDag* > &selection );
// Push the current selection on to the stack
void PushSelection();
// Pop the last selection from the stack
void PopSelection();
// Make the time selection include the entire shot
void TimeSelectAll( DmeTime_t handleTime = DMETIME_ZERO );
// Select time relative to the shot
void TimeSelectShot( float leftFalloff, float leftHold, float rightHold, float rightFalloff, int leftFalloffType, int rightFalloffType );
// Select time specified with in frames
void TimeSelectFrames( int leftFalloff, int leftHold, int rightHold, int rightFalloff, int leftFalloffType, int rightFalloffType );
// Set the channel operating mode
void SetChannelMode( ChannelMode_t mode );
// Get the current time a frame relative to the start of the shot
void SetCurrentFrame( int frame );
// Get the current frame relative to the start of the shot
int GetCurrentFrame() const;
// Set the current ( global ) time
void SetCurrentTime( DmeTime_t globalTime );
// Set the active animation set
void SetActiveAnimationSet( CDmeAnimationSet *pAnimationSet );
// Get the specified animation set context
CSFMAnimSetScriptContext *GetAnimSetContext( int index ) const;
// Find the animation set context for the specified animation set.
CSFMAnimSetScriptContext *FindAnimationSetContext( CDmeAnimationSet *pAnimationSet ) const;
// Get the first selected dag node in the selection list and initialize the iterator
CDmeDag *GetFirstSelectedDag();
// Get the next selected dag node in the selection list
CDmeDag *GetNextSelectedDag();
// Start a new rig or continue an existing one if a rig with the specified name already exists
CDmeRig *BeginRig( const char *pchRigName, bool bAllowAppend );
// End the current rig
void EndRig();
// Add an element to the currently active rig
void AddElementToRig( CDmElement *pElement, CDmeAnimationSet *pAnimSet );
// Accessors
CDmeClip *Movie() const { return m_pMovie; }
CDmeFilmClip *Shot() const { return m_pShot; }
CDmeAnimationSet *ActiveAnimationSet() const { return m_pActiveAnimSet; }
CDmeRig *CurrentRig() const { return m_pCurrentRig; }
const DmeLog_TimeSelection_t &TimeSelection() const { return m_TimeSelection; }
const CUtlVector< CDmeDag * > &Selection() const { return m_Selection; }
DmeTime_t CurrentTime() const { return m_CurrentTime; }
ChannelMode_t ChannelMode() const { return m_ChannelMode; }
int NumAnimationSets() const { return m_AnimSetContextList.Count(); }
CDmElement *SharedPresetGroupSettings() const { return m_pSharedPresetGroupSettings; }
private:
// Initialize the context.
void InititalizeContext();
// Destroy all of the animation set contexts
void DestroyAnimSetContexts();
private:
bool m_bPythonInitalized; // Flag indicating if python is initalized
CDmeClip *m_pMovie; // Current movie in which the script is operating
CDmeFilmClip *m_pShot; // Current shot in which the script is operating
CDmeAnimationSet *m_pActiveAnimSet; // Currently selected animation set, used as a default
CDmeRig *m_pCurrentRig; // Currently active rig
ChannelMode_t m_ChannelMode; // Mode in which channels will be operated
DmeTime_t m_CurrentTime; // Time at which the script is being run
DmeFramerate_t m_Framerate; // The framerate setting of the current session
DmeLog_TimeSelection_t m_TimeSelection; // Time selection to be used with any time dependent operations
CUtlVector< CDmeDag * > m_Selection; // Set of selected dag nodes for script operation
CUtlStack< CUtlVector< CDmeDag * > > m_SelectionStack; // Stack of selection sets used to store and restore selections
CUtlVector< CSFMAnimSetScriptContext* > m_AnimSetContextList; // List of the animation set contexts, one for each animation set in the group
int m_CurrentControlIndex; // Index used by the control iteration functions
int m_CurrentDagIndex; // Index used by the dag iteration functions
CDmElement *m_pSharedPresetGroupSettings; // Session's shared preset group settings
};
//-------------------------------------------------------------------------------------------------
// CSFMScriptMgr
//
//-------------------------------------------------------------------------------------------------
class CSFMScriptMgr
{
public:
// Constructor
CSFMScriptMgr( CSFMScriptContext &scriptContext );
// Destructor
~CSFMScriptMgr();
static void SetInterfaceFactory( CreateInterfaceFn factory );
// Initialize the python script interface and register the sfm module.
static void InitializeScriptInterface();
// Shutdown the python script interface
static void ShutdownScriptInterface();
// Run the script provided in the buffer.
static bool RunScript( const CUtlBuffer &scriptBuffer, CSFMScriptContext &scriptContext, CUtlString *pErrorMsg = NULL );
// Find an animation set using the provided path
CDmeAnimationSet *FindAnimationSet( const char *pchName, CDmeAnimationSet *pDefaultAnimSet = NULL ) const;
// Set the currently active animation set that will be used when an animation set is not explicitly specified
bool SetActiveAnimationSet( const char *pchAnimSetPath ) const;
// Create an animation set for the specified element
CDmeAnimationSet *CreateDagAnimationSet( CDmeDag *pElement, const char *pName ) const;
// Create a game model referencing the specified mdl
CDmeGameModel *CreateGameModel( const char *pRelativeModelName ) const;
// Find a dag by name and animation set path
CDmeDag *FindDag( const char *pchAnimSetDagPath, CDmeAnimationSet **pAnimationSet = NULL, const char **pDagName = NULL ) const;
// Add all of the dag nodes of the animation set to the current selection
bool SelectAnimSet( const char *pchAnimSetPath = NULL ) const;
// Add the controls and dag nodes within the specified selection group to the current selection set
bool Select( const char *pchName, CSFMScriptContext::SelectMode_t mode = CSFMScriptContext::SELECT_ADD ) const;
// Make the primary selection dag node the parent of all other selected dag nodes
bool ParentDags( bool bMaintainWorldPos, bool bParentToWorld, ReParentLogMode_t logMode ) const;
// Create a rig handle with the specified name, add it to the active rig if any.
CDmeRigHandle *CreateRigHandle( char const *pchHandleName, char const *pchRigSubGroup, const Vector &p, const Quaternion &q, bool bPositionControl, bool bRotationControl ) const;
// Create a dag and associated control for the specified attachment position.
CDmeDag *CreateAttachmentHandle( const char *pchAttachmentName ) const;
// Create a dag node and add controls for it to the specified animation set
CDmeDag *CreateDag( const char *pName, const Vector &pos, const Quaternion &orient, CDmeAnimationSet *pAnimSet = NULL, CDmeDag *pParent = NULL ) const;
// Create a constraint of the specified type using the current selection.
CDmeConstraintTarget *CreateConstraint( char const *pchConstraintName, char const *pchRigSubGroup, int constrainType, bool bPreserveOffset, float weight, bool bCreateControls, bool bOperate ) const;
// Create an aim constraint using the current selection.
CDmeConstraintTarget *CreateAimConstraint( char const *pchConstraintName, char const *pchRigSubGroup, bool bPreserveOffset, float weight, bool bCreateControls, const Vector &upVector, TransformSpace_t upSpace, const CDmeDag *pRefDag ) const;
// Create an IK constraint using he current selection
CDmeConstraintTarget *CreateIKConstraint( char const *pchConstraintName, char const *pchRigSubGroup, bool bPreserveOffset, bool bCreateControls, const Vector &poleVector, CDmeDag *pPoleVectorTarget ) const;
// Remove all constraints from the currently selected dag nodes.
void RemoveConstraints() const;
// Generate position and orientation logs for the currently selected dag nodes.
bool GenerateLogSamples( CDmeDag *pParent, bool bPosition, bool bOrientation, bool bWorld ) const;
// Get the averaged position of the selected dag nodes
void GetDagPosition( Vector &position, TransformSpace_t space, const CDmeDag *pReferenceSpaceDag = NULL) const;
// Get the average orientation of the selected dag nodes
void GetDagRotation( Vector &rotation, TransformSpace_t space, const CDmeDag *pReferenceSpaceDag = NULL ) const;
// Move the selected dag nodes to the specified position or by specified amount
void MoveDags( const Vector &offset, TransformSpace_t space, bool bRelative, bool bOffsetMode, CDmeDag *pReferenceDag );
// Rotate the selected dag nodes to the specified position or by specified amount
void RotateDags( const Vector &offset, TransformSpace_t space, bool bRelative, bool bOffsetMode, CDmeDag *pReferenceDag );
// Set the current position and rotation as the default for the transforms of the selected dag nodes
void SetDagTransformDefaults( bool bPosition, bool bOrientation ) const;
// Set the currently selected dag nodes to their reference pose position.
void SetReferencePose() const;
// Clear the error message buffer
void ClearErrorMessage();
// Append the provided string to the current error message
void AppendErrorMessage( const char *errorString );
// Get the current error message string
const char *GetErrorMessage() const;
// Get the script context
const CSFMScriptContext &Context() const { return m_Context; }
CSFMScriptContext &Context() { return m_Context; }
private:
// Execute the specified script
bool ExecuteScript( const CUtlBuffer &scriptBuffer );
// Separate the target name from the path of a animation set / dag name path.
static const char *SeparatePath( const char *pchAnimSetDagPath, char *pchAnimSetPath, int maxLength );
// Construct a name for constraint on the specified dag
void ConstructNameForConstraint( EConstraintType constraintType, CDmeDag *pDag, const char *pchConstraintName, CFmtStr &name ) const;
// Perform processing which is done on all newly created constraints
CDmeConstraintTarget *ProcessNewConstraint( CDmeDag *pSalveDag, CDmeRigBaseConstraintOperator* pConstraint, const char *pchRigSubGroup, bool bCreateControls ) const;
private:
CSFMScriptContext &m_Context;
CUtlString m_ErrorBuffer;
static CreateInterfaceFn sm_pToolsFactory;
};
//-------------------------------------------------------------------------------------------------
// Global pointer to the active script manager, created and destroyed by RunScript()
extern CSFMScriptMgr *g_pScriptMgr;
#endif // SFMSCRIPTMGR_H

View File

@@ -0,0 +1,177 @@
//====== Copyright © 1996-2004, 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
CDmElement * GetSettings() const;
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 );
private:
void CreateRenderSettings( CDmElement *pSettings );
void CreateProgressiveRefinementSettings( CDmElement *pRenderSettings );
void CreatePosterSettings( CDmElement *pRenderSettings );
void CreateMovieSettings( CDmElement *pRenderSettings );
void CreateSharedPresetGroupSettings( 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
//-----------------------------------------------------------------------------
inline CDmElement *CSFMSession::GetSettings() const
{
return m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL;
}
template< class T >
inline const T& CSFMSession::GetSettings( const char *pSettingName ) const
{
CDmElement *pSettings = GetSettings();
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 = GetSettings();
if ( pSettings )
return pSettings->GetAttribute( pSettingName, type );
return NULL;
}
template< class T >
inline void CSFMSession::SetSettings( const char *pSettingName, const T& value )
{
CDmElement *pSettings = GetSettings();
if ( pSettings )
{
pSettings->SetValue( pSettingName, value );
}
}
template< class E >
inline E* CSFMSession::GetSettingsElement( const char *pSettingName ) const
{
CDmElement *pSettings = GetSettings();
return pSettings ? pSettings->GetValueElement< E >( pSettingName ) : NULL;
}
#endif // SFMSESSION_H