2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
33 // these can be changed by modmakers and licensees to be whatever they need.
34 const int ANIM_NumAnimChannels = 5;
35 const int ANIM_MaxAnimsPerChannel = 3;
36 const int ANIM_MaxSyncedAnims = 3;
39 // animation channels. make sure to change script/doom_defs.script if you add any channels, or change their order
41 const int ANIMCHANNEL_ALL = 0;
42 const int ANIMCHANNEL_TORSO = 1;
43 const int ANIMCHANNEL_LEGS = 2;
44 const int ANIMCHANNEL_HEAD = 3;
45 const int ANIMCHANNEL_EYELIDS = 4;
47 // for converting from 24 frames per second to milliseconds
48 ID_INLINE int FRAME2MS( int framenum ) {
49 return ( framenum * 1000 ) / 24;
61 int cycleCount; // how many times the anim has wrapped to the begining (0 for clamped anims)
77 jointHandle_t parentNum;
82 // joint modifier modes. make sure to change script/doom_defs.script if you add any, or change their order.
85 JOINTMOD_NONE, // no modification
86 JOINTMOD_LOCAL, // modifies the joint's position or orientation in joint local space
87 JOINTMOD_LOCAL_OVERRIDE, // sets the joint's position or orientation in joint local space
88 JOINTMOD_WORLD, // modifies joint's position or orientation in model space
89 JOINTMOD_WORLD_OVERRIDE // sets the joint's position or orientation in model space
90 } jointModTransform_t;
93 jointHandle_t jointnum;
96 jointModTransform_t transform_pos;
97 jointModTransform_t transform_axis;
100 #define ANIM_TX BIT( 0 )
101 #define ANIM_TY BIT( 1 )
102 #define ANIM_TZ BIT( 2 )
103 #define ANIM_QX BIT( 3 )
104 #define ANIM_QY BIT( 4 )
105 #define ANIM_QZ BIT( 5 )
109 FC_SCRIPTFUNCTIONOBJECT,
123 FC_TRIGGER_SMOKE_PARTICLE,
131 FC_FIREMISSILEATTARGET,
136 FC_DISABLE_EYE_FOCUS,
149 } frameCommandType_t;
157 frameCommandType_t type;
161 const idSoundShader *soundShader;
162 const function_t *function;
163 const idDeclSkin *skin;
169 bool prevent_idle_override : 1;
170 bool random_cycle_start : 1;
177 ==============================================================================================
181 ==============================================================================================
184 class idModelExport {
187 bool ParseOptions( idLexer &lex );
188 int ParseExportSection( idParser &parser );
190 static bool CheckMayaInstall( void );
191 static void LoadMayaDll( void );
193 bool ConvertMayaToMD5( void );
194 static bool initialized;
204 static void Shutdown( void );
206 int ExportDefFile( const char *filename );
207 bool ExportModel( const char *model );
208 bool ExportAnim( const char *anim );
209 int ExportModels( const char *pathname, const char *extension );
213 ==============================================================================================
217 ==============================================================================================
226 int numAnimatedComponents;
227 idList<idBounds> bounds;
228 idList<jointAnimInfo_t> jointInfo;
229 idList<idJointQuat> baseFrame;
230 idList<float> componentFrames;
233 mutable int ref_count;
241 size_t Allocated( void ) const;
242 size_t Size( void ) const { return sizeof( *this ) + Allocated(); };
243 bool LoadAnim( const char *filename );
245 void IncreaseRefs( void ) const;
246 void DecreaseRefs( void ) const;
247 int NumRefs( void ) const;
249 void CheckModelHierarchy( const idRenderModel *model ) const;
250 void GetInterpolatedFrame( frameBlend_t &frame, idJointQuat *joints, const int *index, int numIndexes ) const;
251 void GetSingleFrame( int framenum, idJointQuat *joints, const int *index, int numIndexes ) const;
252 int Length( void ) const;
253 int NumFrames( void ) const;
254 int NumJoints( void ) const;
255 const idVec3 &TotalMovementDelta( void ) const;
256 const char *Name( void ) const;
258 void GetFrameBlend( int framenum, frameBlend_t &frame ) const; // frame 1 is first frame
259 void ConvertTimeToFrame( int time, int cyclecount, frameBlend_t &frame ) const;
261 void GetOrigin( idVec3 &offset, int currentTime, int cyclecount ) const;
262 void GetOriginRotation( idQuat &rotation, int time, int cyclecount ) const;
263 void GetBounds( idBounds &bounds, int currentTime, int cyclecount ) const;
267 ==============================================================================================
271 ==============================================================================================
276 const class idDeclModelDef *modelDef;
277 const idMD5Anim *anims[ ANIM_MaxSyncedAnims ];
281 idList<frameLookup_t> frameLookup;
282 idList<frameCommand_t> frameCommands;
287 idAnim( const idDeclModelDef *modelDef, const idAnim *anim );
290 void SetAnim( const idDeclModelDef *modelDef, const char *sourcename, const char *animname, int num, const idMD5Anim *md5anims[ ANIM_MaxSyncedAnims ] );
291 const char *Name( void ) const;
292 const char *FullName( void ) const;
293 const idMD5Anim *MD5Anim( int num ) const;
294 const idDeclModelDef *ModelDef( void ) const;
295 int Length( void ) const;
296 int NumFrames( void ) const;
297 int NumAnims( void ) const;
298 const idVec3 &TotalMovementDelta( void ) const;
299 bool GetOrigin( idVec3 &offset, int animNum, int time, int cyclecount ) const;
300 bool GetOriginRotation( idQuat &rotation, int animNum, int currentTime, int cyclecount ) const;
301 bool GetBounds( idBounds &bounds, int animNum, int time, int cyclecount ) const;
302 const char *AddFrameCommand( const class idDeclModelDef *modelDef, int framenum, idLexer &src, const idDict *def );
303 void CallFrameCommands( idEntity *ent, int from, int to ) const;
304 bool HasFrameCommands( void ) const;
306 // returns first frame (zero based) that command occurs. returns -1 if not found.
307 int FindFrameForFrameCommand( frameCommandType_t framecommand, const frameCommand_t **command ) const;
308 void SetAnimFlags( const animFlags_t &animflags );
309 const animFlags_t &GetAnimFlags( void ) const;
313 ==============================================================================================
317 ==============================================================================================
320 class idDeclModelDef : public idDecl {
325 virtual size_t Size( void ) const;
326 virtual const char * DefaultDefinition( void ) const;
327 virtual bool Parse( const char *text, const int textLength );
328 virtual void FreeData( void );
330 void Touch( void ) const;
332 const idDeclSkin * GetDefaultSkin( void ) const;
333 const idJointQuat * GetDefaultPose( void ) const;
334 void SetupJoints( int *numJoints, idJointMat **jointList, idBounds &frameBounds, bool removeOriginOffset ) const;
335 idRenderModel * ModelHandle( void ) const;
336 void GetJointList( const char *jointnames, idList<jointHandle_t> &jointList ) const;
337 const jointInfo_t * FindJoint( const char *name ) const;
339 int NumAnims( void ) const;
340 const idAnim * GetAnim( int index ) const;
341 int GetSpecificAnim( const char *name ) const;
342 int GetAnim( const char *name ) const;
343 bool HasAnim( const char *name ) const;
344 const idDeclSkin * GetSkin( void ) const;
345 const char * GetModelName( void ) const;
346 const idList<jointInfo_t> & Joints( void ) const;
347 const int * JointParents( void ) const;
348 int NumJoints( void ) const;
349 const jointInfo_t * GetJoint( int jointHandle ) const;
350 const char * GetJointName( int jointHandle ) const;
351 int NumJointsOnChannel( int channel ) const;
352 const int * GetChannelJoints( int channel ) const;
354 const idVec3 & GetVisualOffset( void ) const;
357 void CopyDecl( const idDeclModelDef *decl );
358 bool ParseAnim( idLexer &src, int numDefaultAnims );
362 idList<jointInfo_t> joints;
363 idList<int> jointParents;
364 idList<int> channelJoints[ ANIM_NumAnimChannels ];
365 idRenderModel * modelHandle;
366 idList<idAnim *> anims;
367 const idDeclSkin * skin;
371 ==============================================================================================
375 ==============================================================================================
380 const class idDeclModelDef *modelDef;
388 float blendStartValue;
391 float animWeights[ ANIM_MaxSyncedAnims ];
396 bool allowFrameCommands;
398 friend class idAnimator;
400 void Reset( const idDeclModelDef *_modelDef );
401 void CallFrameCommands( idEntity *ent, int fromtime, int totime ) const;
402 void SetFrame( const idDeclModelDef *modelDef, int animnum, int frame, int currenttime, int blendtime );
403 void CycleAnim( const idDeclModelDef *modelDef, int animnum, int currenttime, int blendtime );
404 void PlayAnim( const idDeclModelDef *modelDef, int animnum, int currenttime, int blendtime );
405 bool BlendAnim( int currentTime, int channel, int numJoints, idJointQuat *blendFrame, float &blendWeight, bool removeOrigin, bool overrideBlend, bool printInfo ) const;
406 void BlendOrigin( int currentTime, idVec3 &blendPos, float &blendWeight, bool removeOriginOffset ) const;
407 void BlendDelta( int fromtime, int totime, idVec3 &blendDelta, float &blendWeight ) const;
408 void BlendDeltaRotation( int fromtime, int totime, idQuat &blendDelta, float &blendWeight ) const;
409 bool AddBounds( int currentTime, idBounds &bounds, bool removeOriginOffset ) const;
413 void Save( idSaveGame *savefile ) const;
414 void Restore( idRestoreGame *savefile, const idDeclModelDef *modelDef );
415 const char *AnimName( void ) const;
416 const char *AnimFullName( void ) const;
417 float GetWeight( int currenttime ) const;
418 float GetFinalWeight( void ) const;
419 void SetWeight( float newweight, int currenttime, int blendtime );
420 int NumSyncedAnims( void ) const;
421 bool SetSyncedAnimWeight( int num, float weight );
422 void Clear( int currentTime, int clearTime );
423 bool IsDone( int currentTime ) const;
424 bool FrameHasChanged( int currentTime ) const;
425 int GetCycleCount( void ) const;
426 void SetCycleCount( int count );
427 void SetPlaybackRate( int currentTime, float newRate );
428 float GetPlaybackRate( void ) const;
429 void SetStartTime( int startTime );
430 int GetStartTime( void ) const;
431 int GetEndTime( void ) const;
432 int GetFrameNumber( int currenttime ) const;
433 int AnimTime( int currenttime ) const;
434 int NumFrames( void ) const;
435 int Length( void ) const;
436 int PlayLength( void ) const;
437 void AllowMovement( bool allow );
438 void AllowFrameCommands( bool allow );
439 const idAnim *Anim( void ) const;
440 int AnimNum( void ) const;
444 ==============================================================================================
448 ==============================================================================================
457 class idAFPoseJointMod {
459 idAFPoseJointMod( void );
461 AFJointModType_t mod;
466 ID_INLINE idAFPoseJointMod::idAFPoseJointMod( void ) {
467 mod = AF_JOINTMOD_AXIS;
473 ==============================================================================================
477 ==============================================================================================
485 size_t Allocated( void ) const;
486 size_t Size( void ) const;
488 void Save( idSaveGame *savefile ) const; // archives object for save game file
489 void Restore( idRestoreGame *savefile ); // unarchives object from save game file
491 void SetEntity( idEntity *ent );
492 idEntity *GetEntity( void ) const ;
493 void RemoveOriginOffset( bool remove );
494 bool RemoveOrigin( void ) const;
496 void GetJointList( const char *jointnames, idList<jointHandle_t> &jointList ) const;
498 int NumAnims( void ) const;
499 const idAnim *GetAnim( int index ) const;
500 int GetAnim( const char *name ) const;
501 bool HasAnim( const char *name ) const;
503 void ServiceAnims( int fromtime, int totime );
504 bool IsAnimating( int currentTime ) const;
506 void GetJoints( int *numJoints, idJointMat **jointsPtr );
507 int NumJoints( void ) const;
508 jointHandle_t GetFirstChild( jointHandle_t jointnum ) const;
509 jointHandle_t GetFirstChild( const char *name ) const;
511 idRenderModel *SetModel( const char *modelname );
512 idRenderModel *ModelHandle( void ) const;
513 const idDeclModelDef *ModelDef( void ) const;
515 void ForceUpdate( void );
516 void ClearForceUpdate( void );
517 bool CreateFrame( int animtime, bool force );
518 bool FrameHasChanged( int animtime ) const;
519 void GetDelta( int fromtime, int totime, idVec3 &delta ) const;
520 bool GetDeltaRotation( int fromtime, int totime, idMat3 &delta ) const;
521 void GetOrigin( int currentTime, idVec3 &pos ) const;
522 bool GetBounds( int currentTime, idBounds &bounds );
524 idAnimBlend *CurrentAnim( int channelNum );
525 void Clear( int channelNum, int currentTime, int cleartime );
526 void SetFrame( int channelNum, int animnum, int frame, int currenttime, int blendtime );
527 void CycleAnim( int channelNum, int animnum, int currenttime, int blendtime );
528 void PlayAnim( int channelNum, int animnum, int currenttime, int blendTime );
530 // copies the current anim from fromChannelNum to channelNum.
531 // the copied anim will have frame commands disabled to avoid executing them twice.
532 void SyncAnimChannels( int channelNum, int fromChannelNum, int currenttime, int blendTime );
534 void SetJointPos( jointHandle_t jointnum, jointModTransform_t transform_type, const idVec3 &pos );
535 void SetJointAxis( jointHandle_t jointnum, jointModTransform_t transform_type, const idMat3 &mat );
536 void ClearJoint( jointHandle_t jointnum );
537 void ClearAllJoints( void );
539 void InitAFPose( void );
540 void SetAFPoseJointMod( const jointHandle_t jointNum, const AFJointModType_t mod, const idMat3 &axis, const idVec3 &origin );
541 void FinishAFPose( int animnum, const idBounds &bounds, const int time );
542 void SetAFPoseBlendWeight( float blendWeight );
543 bool BlendAFPose( idJointQuat *blendFrame ) const;
544 void ClearAFPose( void );
546 void ClearAllAnims( int currentTime, int cleartime );
548 jointHandle_t GetJointHandle( const char *name ) const;
549 const char * GetJointName( jointHandle_t handle ) const;
550 int GetChannelForJoint( jointHandle_t joint ) const;
551 bool GetJointTransform( jointHandle_t jointHandle, int currenttime, idVec3 &offset, idMat3 &axis );
552 bool GetJointLocalTransform( jointHandle_t jointHandle, int currentTime, idVec3 &offset, idMat3 &axis );
554 const animFlags_t GetAnimFlags( int animnum ) const;
555 int NumFrames( int animnum ) const;
556 int NumSyncedAnims( int animnum ) const;
557 const char *AnimName( int animnum ) const;
558 const char *AnimFullName( int animnum ) const;
559 int AnimLength( int animnum ) const;
560 const idVec3 &TotalMovementDelta( int animnum ) const;
563 void FreeData( void );
564 void PushAnims( int channel, int currentTime, int blendTime );
567 const idDeclModelDef * modelDef;
570 idAnimBlend channels[ ANIM_NumAnimChannels ][ ANIM_MaxAnimsPerChannel ];
571 idList<jointMod_t *> jointMods;
575 mutable int lastTransformTime; // mutable because the value is updated in CreateFrame
576 mutable bool stoppedAnimatingUpdate;
577 bool removeOriginOffset;
580 idBounds frameBounds;
582 float AFPoseBlendWeight;
583 idList<int> AFPoseJoints;
584 idList<idAFPoseJointMod> AFPoseJointMods;
585 idList<idJointQuat> AFPoseJointFrame;
586 idBounds AFPoseBounds;
591 ==============================================================================================
595 ==============================================================================================
598 class idAnimManager {
603 static bool forceExport;
605 void Shutdown( void );
606 idMD5Anim * GetAnim( const char *name );
607 void ReloadAnims( void );
608 void ListAnims( void ) const;
609 int JointIndex( const char *name );
610 const char * JointName( int index ) const;
612 void ClearAnimsInUse( void );
613 void FlushUnusedAnims( void );
616 idHashTable<idMD5Anim *> animations;
617 idStrList jointnames;
618 idHashIndex jointnamesHash;
621 #endif /* !__ANIM_H__ */