mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2024-12-26 23:05:30 +03:00
Added VScript functions for bone attachments and transforming bone matrices
This commit is contained in:
parent
6392d9ab7c
commit
6f515a2d34
@ -294,6 +294,7 @@ END_SCRIPTDESC();
|
||||
|
||||
ScriptHook_t C_BaseAnimating::g_Hook_OnClientRagdoll;
|
||||
ScriptHook_t C_BaseAnimating::g_Hook_FireEvent;
|
||||
ScriptHook_t C_BaseAnimating::g_Hook_BuildTransformations;
|
||||
#endif
|
||||
|
||||
BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-side" )
|
||||
@ -310,6 +311,14 @@ BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-si
|
||||
|
||||
DEFINE_SCRIPTFUNC( LookupBone, "Get the named bone id" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoneTransform, "GetBoneTransform", "Get the transform for the specified bone" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetBoneTransform, "SetBoneTransform", "Set the transform for the specified bone" )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptAttachEntityToBone, "AttachEntityToBone", "Attaches this entity to the specified target and bone. Also allows for optional local position offset" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptRemoveBoneAttachment, "RemoveBoneAttachment", "Removes the specified bone attachment" )
|
||||
//DEFINE_SCRIPTFUNC( RemoveBoneAttachments, "Removes all bone attachments" )
|
||||
DEFINE_SCRIPTFUNC( DestroyBoneAttachments, "Destroys all bone attachments" )
|
||||
DEFINE_SCRIPTFUNC( GetNumBoneAttachments, "Gets the number of bone attachments" )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoneAttachment, "GetBoneAttachment", "Gets the specified bone attachment" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( SetBodygroup, "Sets a bodygroup")
|
||||
DEFINE_SCRIPTFUNC( GetBodygroup, "Gets a bodygroup" )
|
||||
@ -354,6 +363,9 @@ BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-si
|
||||
DEFINE_SCRIPTHOOK_PARAM( "event", FIELD_INTEGER )
|
||||
DEFINE_SCRIPTHOOK_PARAM( "options", FIELD_CSTRING )
|
||||
END_SCRIPTHOOK()
|
||||
|
||||
BEGIN_SCRIPTHOOK( C_BaseAnimating::g_Hook_BuildTransformations, "BuildTransformations", FIELD_VOID, "Called when building bone transformations. Allows VScript to read/write any bone with Get/SetBoneTransform." )
|
||||
END_SCRIPTHOOK()
|
||||
#endif
|
||||
END_SCRIPTDESC();
|
||||
|
||||
@ -1538,10 +1550,43 @@ HSCRIPT C_BaseAnimating::ScriptGetAttachmentMatrix( int iAttachment )
|
||||
|
||||
void C_BaseAnimating::ScriptGetBoneTransform( int iBone, HSCRIPT hTransform )
|
||||
{
|
||||
if (hTransform == NULL)
|
||||
matrix3x4_t *matTransform = HScriptToClass<matrix3x4_t>( hTransform );
|
||||
if (matTransform == NULL)
|
||||
return;
|
||||
|
||||
GetBoneTransform( iBone, *HScriptToClass<matrix3x4_t>( hTransform ) );
|
||||
GetBoneTransform( iBone, *matTransform );
|
||||
}
|
||||
|
||||
void C_BaseAnimating::ScriptSetBoneTransform( int iBone, HSCRIPT hTransform )
|
||||
{
|
||||
matrix3x4_t *matTransform = HScriptToClass<matrix3x4_t>( hTransform );
|
||||
if (matTransform == NULL)
|
||||
return;
|
||||
|
||||
MatrixCopy( *matTransform, GetBoneForWrite( iBone ) );
|
||||
}
|
||||
|
||||
void C_BaseAnimating::ScriptAttachEntityToBone( HSCRIPT attachTarget, int boneIndexAttached, const Vector &bonePosition, const QAngle &boneAngles )
|
||||
{
|
||||
C_BaseEntity *pTarget = ToEnt( attachTarget );
|
||||
if (pTarget == NULL)
|
||||
return;
|
||||
|
||||
AttachEntityToBone( pTarget->GetBaseAnimating(), boneIndexAttached, bonePosition, boneAngles );
|
||||
}
|
||||
|
||||
void C_BaseAnimating::ScriptRemoveBoneAttachment( HSCRIPT boneAttachment )
|
||||
{
|
||||
C_BaseEntity *pTarget = ToEnt( boneAttachment );
|
||||
if (pTarget == NULL)
|
||||
return;
|
||||
|
||||
RemoveBoneAttachment( pTarget->GetBaseAnimating() );
|
||||
}
|
||||
|
||||
HSCRIPT C_BaseAnimating::ScriptGetBoneAttachment( int i )
|
||||
{
|
||||
return ToHScript( GetBoneAttachment( i ) );
|
||||
}
|
||||
|
||||
HSCRIPT C_BaseAnimating::ScriptBecomeRagdollOnClient()
|
||||
@ -1719,7 +1764,23 @@ void C_BaseAnimating::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quater
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if (m_ScriptScope.IsInitialized() && g_Hook_BuildTransformations.CanRunInScope(m_ScriptScope))
|
||||
{
|
||||
int oldWritableBones = m_BoneAccessor.GetWritableBones();
|
||||
int oldReadableBones = m_BoneAccessor.GetReadableBones();
|
||||
m_BoneAccessor.SetWritableBones( BONE_USED_BY_ANYTHING );
|
||||
m_BoneAccessor.SetReadableBones( BONE_USED_BY_ANYTHING );
|
||||
|
||||
// No parameters
|
||||
//ScriptVariant_t args[] = {};
|
||||
//ScriptVariant_t returnValue;
|
||||
g_Hook_BuildTransformations.Call( m_ScriptScope, NULL, NULL /*&returnValue, args*/ );
|
||||
|
||||
m_BoneAccessor.SetWritableBones( oldWritableBones );
|
||||
m_BoneAccessor.SetReadableBones( oldReadableBones );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -468,6 +468,11 @@ public:
|
||||
HSCRIPT ScriptGetAttachmentMatrix(int iAttachment);
|
||||
|
||||
void ScriptGetBoneTransform( int iBone, HSCRIPT hTransform );
|
||||
void ScriptSetBoneTransform( int iBone, HSCRIPT hTransform );
|
||||
|
||||
void ScriptAttachEntityToBone( HSCRIPT attachTarget, int boneIndexAttached, const Vector &bonePosition, const QAngle &boneAngles );
|
||||
void ScriptRemoveBoneAttachment( HSCRIPT boneAttachment );
|
||||
HSCRIPT ScriptGetBoneAttachment( int i );
|
||||
|
||||
int ScriptGetSequenceActivity( int iSequence ) { return GetSequenceActivity( iSequence ); }
|
||||
float ScriptGetSequenceMoveDist( int iSequence ) { return GetSequenceMoveDist( GetModelPtr(), iSequence ); }
|
||||
@ -486,6 +491,7 @@ public:
|
||||
|
||||
static ScriptHook_t g_Hook_OnClientRagdoll;
|
||||
static ScriptHook_t g_Hook_FireEvent;
|
||||
static ScriptHook_t g_Hook_BuildTransformations;
|
||||
|
||||
float ScriptGetPoseParameter(const char* szName);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user