29 #include "../../idlib/precompiled.h"
32 #include "../Game_local.h"
165 if ( !parser.
LoadFile( filename ) ) {
176 parser.
Error(
"Invalid version %d. Should be version %d\n", version,
MD5_VERSION );
223 parser.
Error(
"Invalid parent num: %d",
jointInfo[ i ].parentNum );
226 if ( ( i != 0 ) && (
jointInfo[ i ].parentNum < 0 ) ) {
227 parser.
Error(
"Animations may have only one root joint" );
239 parser.
Error(
"Invalid first component: %d",
jointInfo[ i ].firstComponent );
278 parser.
Error(
"Expected frame number %d", i );
294 if ( jointInfo[ 0 ].animBits &
ANIM_TX ) {
303 if ( jointInfo[ 0 ].animBits &
ANIM_TY ) {
312 if ( jointInfo[ 0 ].animBits &
ANIM_TZ ) {
369 if ( framenum < 0 ) {
407 frameNum = frameTime / 1000;
410 if ( ( cyclecount > 0 ) && ( frame.
cycleCount >= cyclecount ) ) {
425 frame.
backlerp = ( frameTime % 1000 ) * 0.001
f;
510 q1.
x = jointframe1[0];
511 q2.
x = jointframe2[0];
520 q1.
y = jointframe1[0];
521 q2.
y = jointframe2[0];
530 q1.
z = jointframe1[0];
531 q2.
z = jointframe2[0];
540 q1.
x = jointframe1[0];
541 q1.
y = jointframe1[1];
542 q2.
x = jointframe2[0];
543 q2.
y = jointframe2[1];
550 q1.
x = jointframe1[0];
551 q1.
z = jointframe1[1];
552 q2.
x = jointframe2[0];
553 q2.
z = jointframe2[1];
560 q1.
y = jointframe1[0];
561 q1.
z = jointframe1[1];
562 q2.
y = jointframe2[0];
563 q2.
z = jointframe2[1];
570 q1.
x = jointframe1[0];
571 q1.
y = jointframe1[1];
572 q1.
z = jointframe1[2];
573 q2.
x = jointframe2[0];
574 q2.
y = jointframe2[1];
575 q2.
z = jointframe2[2];
631 int i, numLerpJoints;
634 const float *jointframe1;
635 const float *jointframe2;
652 lerpIndex = (
int *)_alloca16(
baseFrame.
Num() *
sizeof( lerpIndex[ 0 ] ) );
658 for ( i = 0; i < numIndexes; i++ ) {
660 jointPtr = &joints[
j];
661 blendPtr = &blendJoints[
j];
667 lerpIndex[numLerpJoints++] =
j;
674 blendPtr->
t = jointPtr->
t;
677 jointPtr->
t.
x = jointframe1[0];
678 blendPtr->
t.
x = jointframe2[0];
679 blendPtr->
t.
y = jointPtr->
t.
y;
680 blendPtr->
t.
z = jointPtr->
t.
z;
685 jointPtr->
t.
y = jointframe1[0];
686 blendPtr->
t.
y = jointframe2[0];
687 blendPtr->
t.
x = jointPtr->
t.
x;
688 blendPtr->
t.
z = jointPtr->
t.
z;
693 jointPtr->
t.
z = jointframe1[0];
694 blendPtr->
t.
z = jointframe2[0];
695 blendPtr->
t.
x = jointPtr->
t.
x;
696 blendPtr->
t.
y = jointPtr->
t.
y;
701 jointPtr->
t.
x = jointframe1[0];
702 jointPtr->
t.
y = jointframe1[1];
703 blendPtr->
t.
x = jointframe2[0];
704 blendPtr->
t.
y = jointframe2[1];
705 blendPtr->
t.
z = jointPtr->
t.
z;
710 jointPtr->
t.
x = jointframe1[0];
711 jointPtr->
t.
z = jointframe1[1];
712 blendPtr->
t.
x = jointframe2[0];
713 blendPtr->
t.
z = jointframe2[1];
714 blendPtr->
t.
y = jointPtr->
t.
y;
719 jointPtr->
t.
y = jointframe1[0];
720 jointPtr->
t.
z = jointframe1[1];
721 blendPtr->
t.
y = jointframe2[0];
722 blendPtr->
t.
z = jointframe2[1];
723 blendPtr->
t.
x = jointPtr->
t.
x;
728 jointPtr->
t.
x = jointframe1[0];
729 jointPtr->
t.
y = jointframe1[1];
730 jointPtr->
t.
z = jointframe1[2];
731 blendPtr->
t.
x = jointframe2[0];
732 blendPtr->
t.
y = jointframe2[1];
733 blendPtr->
t.
z = jointframe2[2];
741 blendPtr->
q = jointPtr->
q;
744 jointPtr->
q.
x = jointframe1[0];
745 blendPtr->
q.
x = jointframe2[0];
746 blendPtr->
q.
y = jointPtr->
q.
y;
747 blendPtr->
q.
z = jointPtr->
q.
z;
748 jointPtr->
q.
w = jointPtr->
q.
CalcW();
749 blendPtr->
q.
w = blendPtr->
q.
CalcW();
752 jointPtr->
q.
y = jointframe1[0];
753 blendPtr->
q.
y = jointframe2[0];
754 blendPtr->
q.
x = jointPtr->
q.
x;
755 blendPtr->
q.
z = jointPtr->
q.
z;
756 jointPtr->
q.
w = jointPtr->
q.
CalcW();
757 blendPtr->
q.
w = blendPtr->
q.
CalcW();
760 jointPtr->
q.
z = jointframe1[0];
761 blendPtr->
q.
z = jointframe2[0];
762 blendPtr->
q.
x = jointPtr->
q.
x;
763 blendPtr->
q.
y = jointPtr->
q.
y;
764 jointPtr->
q.
w = jointPtr->
q.
CalcW();
765 blendPtr->
q.
w = blendPtr->
q.
CalcW();
768 jointPtr->
q.
x = jointframe1[0];
769 jointPtr->
q.
y = jointframe1[1];
770 blendPtr->
q.
x = jointframe2[0];
771 blendPtr->
q.
y = jointframe2[1];
772 blendPtr->
q.
z = jointPtr->
q.
z;
773 jointPtr->
q.
w = jointPtr->
q.
CalcW();
774 blendPtr->
q.
w = blendPtr->
q.
CalcW();
777 jointPtr->
q.
x = jointframe1[0];
778 jointPtr->
q.
z = jointframe1[1];
779 blendPtr->
q.
x = jointframe2[0];
780 blendPtr->
q.
z = jointframe2[1];
781 blendPtr->
q.
y = jointPtr->
q.
y;
782 jointPtr->
q.
w = jointPtr->
q.
CalcW();
783 blendPtr->
q.
w = blendPtr->
q.
CalcW();
786 jointPtr->
q.
y = jointframe1[0];
787 jointPtr->
q.
z = jointframe1[1];
788 blendPtr->
q.
y = jointframe2[0];
789 blendPtr->
q.
z = jointframe2[1];
790 blendPtr->
q.
x = jointPtr->
q.
x;
791 jointPtr->
q.
w = jointPtr->
q.
CalcW();
792 blendPtr->
q.
w = blendPtr->
q.
CalcW();
795 jointPtr->
q.
x = jointframe1[0];
796 jointPtr->
q.
y = jointframe1[1];
797 jointPtr->
q.
z = jointframe1[2];
798 blendPtr->
q.
x = jointframe2[0];
799 blendPtr->
q.
y = jointframe2[1];
800 blendPtr->
q.
z = jointframe2[2];
801 jointPtr->
q.
w = jointPtr->
q.
CalcW();
802 blendPtr->
q.
w = blendPtr->
q.
CalcW();
823 const float *jointframe;
838 for ( i = 0; i < numIndexes; i++ ) {
840 jointPtr = &joints[
j];
851 jointPtr->
t.
x = *jointframe++;
855 jointPtr->
t.
y = *jointframe++;
859 jointPtr->
t.
z = *jointframe++;
866 jointPtr->
q.
x = *jointframe++;
870 jointPtr->
q.
y = *jointframe++;
874 jointPtr->
q.
z = *jointframe;
877 jointPtr->
q.
w = jointPtr->
q.
CalcW();
903 if ( modelJoints[ i ].parent ) {
904 parent = modelJoints[
i ].
parent - modelJoints;
908 if ( parent !=
jointInfo[ i ].parentNum ) {
909 gameLocal.
Error(
"Model '%s' has different joint hierarchy than anim '%s'", model->
Name(),
name.c_str() );
971 if ( !anim->
LoadAnim( filename ) ) {
993 if ( animptr && *animptr ) {
1046 if ( animptr && *animptr ) {
1076 if ( animptr && *animptr ) {
1077 if ( ( *animptr )->NumRefs() <= 0 ) {
1078 removeAnims.
Append( *animptr );
1083 for( i = 0; i < removeAnims.
Num(); i++ ) {
1085 delete removeAnims[
i ];
int JointIndex(const char *name)
GLdouble GLdouble GLdouble GLdouble q
bool AddBounds(const idBounds &a)
const float * ToFloatPtr(void) const
int Next(const int index) const
void Printf(const char *fmt,...) const id_attribute((format(printf
void ListAnims(void) const
void SetNum(int newnum, bool resize=true)
void void void void void Error(const char *fmt,...) const id_attribute((format(printf
void GetBounds(idBounds &bounds, int currentTime, int cyclecount) const
int Parse1DMatrix(int x, float *m)
idHashIndex jointnamesHash
void SetGranularity(int newgranularity)
#define MD5_VERSION_STRING
Type * GetIndex(int index) const
virtual const char * Name() const =0
idList< idBounds > bounds
void GetOrigin(idVec3 &offset, int currentTime, int cyclecount) const
float ParseFloat(bool *errorFlag=NULL)
void IncreaseRefs(void) const
idQuat & Slerp(const idQuat &from, const idQuat &to, float t)
void CheckModelHierarchy(const idRenderModel *model) const
int First(const int key) const
void DeleteContents(void)
void void void Warning(const char *fmt,...) const id_attribute((format(printf
virtual const idMD5Joint * GetJoints(void) const =0
void Set(const char *key, Type &value)
idList< float > componentFrames
void Error(const char *str,...) id_attribute((format(printf
idMD5Anim * GetAnim(const char *name)
virtual void VPCALL BlendJoints(idJointQuat *joints, const idJointQuat *blendJoints, const float lerp, const int *index, const int numJoints)=0
const idMD5Joint * parent
void GetFrameBlend(int framenum, frameBlend_t &frame) const
const char * JointName(int index) const
void GetInterpolatedFrame(frameBlend_t &frame, idJointQuat *joints, const int *index, int numIndexes) const
const char * Name(void) const
size_t Allocated(void) const
idList< jointAnimInfo_t > jointInfo
bool Remove(const char *key)
idHashTable< idMD5Anim * > animations
void FlushUnusedAnims(void)
int NumJoints(void) const
virtual void VPCALL Memcpy(void *dst, const void *src, const int count)=0
int GenerateKey(const char *string, bool caseSensitive=true) const
idList< idJointQuat > baseFrame
bool Get(const char *key, Type **value=NULL) const
int ExpectTokenString(const char *string)
int Append(const type &obj)
void DecreaseRefs(void) const
int numAnimatedComponents
idQuat ToQuat(void) const
const idVec3 & TotalMovementDelta(void) const
idAnimManager animationLib
const char * c_str(void) const
virtual int NumJoints(void) const =0
void Add(const int key, const int index)
void GetSingleFrame(int framenum, idJointQuat *joints, const int *index, int numIndexes) const
size_t Allocated(void) const
void GetOriginRotation(idQuat &rotation, int time, int cyclecount) const
void ExtractFileExtension(idStr &dest) const
int ReadToken(idToken *token)
bool LoadAnim(const char *filename)
void ConvertTimeToFrame(int time, int cyclecount, frameBlend_t &frame) const
int LoadFile(const char *filename, bool OSPath=false)
int NumFrames(void) const
idSIMDProcessor * SIMDProcessor