hmorphanim.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/hmorphanim.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Jani_p $*
  29. * *
  30. * $Modtime:: 6/27/01 7:41p $*
  31. * *
  32. * $Revision:: 4 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef HMORPHANIM_H
  41. #define HMORPHANIM_H
  42. #include "always.h"
  43. #include "hanim.h"
  44. #include "simplevec.h"
  45. class TimeCodedMorphKeysClass;
  46. class ChunkLoadClass;
  47. class ChunkSaveClass;
  48. class TextFileClass;
  49. /**********************************************************************************
  50. HMorphAnimClass
  51. This is an animation format designed for facial animation. It basically morphs the
  52. htree between a set of poses. These animations are created by exporting an
  53. HRawAnimClass which contains the poses, using Magpie to create a text file
  54. describing which pose to use on each frame, and finally using W3dView to combine
  55. the data into an HMorphAnimClass.
  56. There can be multiple channels for the morphing. For example, some of the
  57. bones can be controlled by the "phoneme" poses (e.g. mouth) while other bones are
  58. controlled by the "expression" poses (e.g. eyebrows)
  59. **********************************************************************************/
  60. class HMorphAnimClass : public HAnimClass
  61. {
  62. public:
  63. enum
  64. {
  65. OK,
  66. LOAD_ERROR
  67. };
  68. HMorphAnimClass(void);
  69. ~HMorphAnimClass(void);
  70. void Free_Morph(void);
  71. int Create_New_Morph(const int channels, HAnimClass *anim[]);
  72. int Load_W3D(ChunkLoadClass & cload);
  73. int Save_W3D(ChunkSaveClass & csave);
  74. const char * Get_Name(void) const { return Name; }
  75. const char * Get_HName(void) const { return HierarchyName; }
  76. int Get_Num_Frames(void) { return FrameCount; }
  77. float Get_Frame_Rate() { return FrameRate; }
  78. float Get_Total_Time() { return (float)FrameCount / FrameRate; }
  79. // Vector3 Get_Translation(int pividx,float frame);
  80. // Quaternion Get_Orientation(int pividx,float frame);
  81. void Get_Translation(Vector3& translation, int pividx,float frame) const;
  82. void Get_Orientation(Quaternion& orientation, int pividx,float frame) const;
  83. void Get_Transform(Matrix3D& transform, int pividx,float frame) const;
  84. bool Get_Visibility(int pividx,float frame) { return true; }
  85. void Insert_Morph_Key (const int channel, uint32 morph_frame, uint32 pose_frame);
  86. void Release_Keys (void);
  87. bool Is_Node_Motion_Present(int pividx) { return true; }
  88. int Get_Num_Pivots(void) const { return NumNodes; }
  89. void Set_Name(const char * name);
  90. void Set_HName(const char * hname);
  91. bool Import(const char *hierarchy_name, TextFileClass &text_desc);
  92. protected:
  93. void Free(void);
  94. void read_channel(ChunkLoadClass & cload,int channel);
  95. void write_channel(ChunkSaveClass & csave,int channel);
  96. void Resolve_Pivot_Channels(void);
  97. char Name[2*W3D_NAME_LEN];
  98. char AnimName[W3D_NAME_LEN];
  99. char HierarchyName[W3D_NAME_LEN];
  100. int FrameCount; // number of frames in the animation
  101. float FrameRate; // framerate for playback
  102. int ChannelCount; // number of independent morphing channels
  103. int NumNodes;
  104. HAnimClass ** PoseData; // pointer to pose for each morph channel
  105. TimeCodedMorphKeysClass * MorphKeyData; // morph keys for each channel
  106. uint32 * PivotChannel; // controlling channel for each pivot/bone
  107. };
  108. /*********************************************************************************************
  109. **
  110. ** TimeCodedMorphKeysClass
  111. ** This class basically stores a vector of morph keys. An HMorphAnimClass contains
  112. ** one of these for each independent morphing channel. For example, the facial animation
  113. ** stuff generates HMorphAnims which contain 2 channels, one which specifies what the
  114. ** "phoneme" bones are doing and one which specifies what the "expression" bones are doing.
  115. **
  116. *********************************************************************************************/
  117. class TimeCodedMorphKeysClass
  118. {
  119. public:
  120. TimeCodedMorphKeysClass(void);
  121. ~TimeCodedMorphKeysClass(void);
  122. bool Load_W3D(ChunkLoadClass & cload);
  123. bool Save_W3D(ChunkSaveClass & csave);
  124. void Get_Morph_Info(float morph_frame,int * pose_frame0,int * pose_frame1,float * fraction);
  125. void Add_Key (uint32 morph_frame, uint32 pose_frame);
  126. private:
  127. struct MorphKeyStruct
  128. {
  129. MorphKeyStruct (void)
  130. : MorphFrame (0),
  131. PoseFrame (0) {}
  132. MorphKeyStruct (uint32 _morph, uint32 _pose)
  133. : MorphFrame (_morph),
  134. PoseFrame (_pose) {}
  135. uint32 MorphFrame; // morph animation frame index
  136. uint32 PoseFrame; // which pose frame to use at this time
  137. };
  138. SimpleDynVecClass<MorphKeyStruct> Keys; // morph key data
  139. uint32 CachedIdx; // last accessed index
  140. void Free(void);
  141. uint32 get_index(float time);
  142. uint32 binary_search_index(float time);
  143. friend class HMorphAnimClass;
  144. };
  145. #endif