llbvhloader.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /**
  2. * @file llbvhloader.h
  3. * @brief Translates a BVH files to LindenLabAnimation format.
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLBVHLOADER_H
  33. #define LL_LLBVHLOADER_H
  34. #include "llbvhconsts.h"
  35. #include "llfile.h"
  36. #include "llmath.h"
  37. #include "llpreprocessor.h"
  38. #include "llmatrix3.h"
  39. #include "llvector3.h"
  40. class LLDataPacker;
  41. constexpr S32 BVH_PARSER_LINE_SIZE = 2048;
  42. struct Key
  43. {
  44. Key()
  45. {
  46. mPos[0] = mPos[1] = mPos[2] = 0.f;
  47. mRot[0] = mRot[1] = mRot[2] = 0.f;
  48. mIgnorePos = false;
  49. mIgnoreRot = false;
  50. }
  51. F32 mPos[3];
  52. F32 mRot[3];
  53. bool mIgnorePos;
  54. bool mIgnoreRot;
  55. };
  56. typedef std::vector<Key> KeyVector;
  57. struct Joint
  58. {
  59. Joint(const char* name)
  60. {
  61. mName = name;
  62. mIgnore = false;
  63. mIgnorePositions = false;
  64. mRelativePositionKey = false;
  65. mRelativeRotationKey = false;
  66. mOutName = name;
  67. mOrder[0] = 'X';
  68. mOrder[1] = 'Y';
  69. mOrder[2] = 'Z';
  70. mOrder[3] = 0;
  71. mNumPosKeys = 0;
  72. mNumRotKeys = 0;
  73. mChildTreeMaxDepth = 0;
  74. mPriority = 0;
  75. mNumChannels = 3;
  76. }
  77. // Include aligned members first
  78. LLMatrix3 mFrameMatrix;
  79. LLMatrix3 mOffsetMatrix;
  80. LLVector3 mRelativePosition;
  81. //
  82. std::string mName;
  83. bool mIgnore;
  84. bool mIgnorePositions;
  85. bool mRelativePositionKey;
  86. bool mRelativeRotationKey;
  87. std::string mOutName;
  88. std::string mMergeParentName;
  89. std::string mMergeChildName;
  90. char mOrder[4];
  91. KeyVector mKeys;
  92. S32 mNumPosKeys;
  93. S32 mNumRotKeys;
  94. S32 mChildTreeMaxDepth;
  95. S32 mPriority;
  96. S32 mNumChannels;
  97. };
  98. struct Constraint
  99. {
  100. char mSourceJointName[16];
  101. char mTargetJointName[16];
  102. S32 mChainLength;
  103. LLVector3 mSourceOffset;
  104. LLVector3 mTargetOffset;
  105. LLVector3 mTargetDir;
  106. F32 mEaseInStart;
  107. F32 mEaseInStop;
  108. F32 mEaseOutStart;
  109. F32 mEaseOutStop;
  110. EConstraintType mConstraintType;
  111. };
  112. typedef std::vector<Joint*> JointVector;
  113. typedef std::vector<Constraint> ConstraintVector;
  114. class Translation
  115. {
  116. public:
  117. Translation()
  118. {
  119. mIgnore = false;
  120. mIgnorePositions = false;
  121. mRelativePositionKey = false;
  122. mRelativeRotationKey = false;
  123. mPriorityModifier = 0;
  124. }
  125. public:
  126. LLMatrix3 mFrameMatrix;
  127. LLMatrix3 mOffsetMatrix;
  128. LLVector3 mRelativePosition;
  129. S32 mPriorityModifier;
  130. bool mIgnore;
  131. bool mIgnorePositions;
  132. bool mRelativePositionKey;
  133. bool mRelativeRotationKey;
  134. std::string mOutName;
  135. std::string mMergeParentName;
  136. std::string mMergeChildName;
  137. };
  138. typedef enum e_load_status
  139. {
  140. E_ST_OK,
  141. E_ST_EOF,
  142. E_ST_NO_CONSTRAINT,
  143. E_ST_NO_FILE,
  144. E_ST_NO_HIER,
  145. E_ST_NO_JOINT,
  146. E_ST_NO_NAME,
  147. E_ST_NO_OFFSET,
  148. E_ST_NO_CHANNELS,
  149. E_ST_NO_ROTATION,
  150. E_ST_NO_AXIS,
  151. E_ST_NO_MOTION,
  152. E_ST_NO_FRAMES,
  153. E_ST_NO_FRAME_TIME,
  154. E_ST_NO_POS,
  155. E_ST_NO_ROT,
  156. E_ST_NO_XLT_FILE,
  157. E_ST_NO_XLT_HEADER,
  158. E_ST_NO_XLT_NAME,
  159. E_ST_NO_XLT_IGNORE,
  160. E_ST_NO_XLT_RELATIVE,
  161. E_ST_NO_XLT_OUTNAME,
  162. E_ST_NO_XLT_MATRIX,
  163. E_ST_NO_XLT_MERGECHILD,
  164. E_ST_NO_XLT_MERGEPARENT,
  165. E_ST_NO_XLT_PRIORITY,
  166. E_ST_NO_XLT_LOOP,
  167. E_ST_NO_XLT_EASEIN,
  168. E_ST_NO_XLT_EASEOUT,
  169. E_ST_NO_XLT_HAND,
  170. E_ST_NO_XLT_EMOTE,
  171. E_ST_BAD_ROOT
  172. } ELoadStatus;
  173. typedef std::map<std::string, Translation> TranslationMap;
  174. class LLBVHLoader
  175. {
  176. friend class LLKeyframeMotion;
  177. protected:
  178. LOG_CLASS(LLBVHLoader);
  179. public:
  180. LLBVHLoader(const char* buffer, ELoadStatus& load_status, S32& error_line,
  181. std::map<std::string, std::string>& joint_alias_map);
  182. ~LLBVHLoader();
  183. // Loads the specified translation table.
  184. ELoadStatus loadTranslationTable(const char* fileName);
  185. // Creates a new joint alias.
  186. void makeTranslation(const std::string& key, const std::string& value);
  187. #if 0 // Not used
  188. // Loads joint aliases from XML file.
  189. ELoadStatus loadAliases(const char* filename);
  190. #endif
  191. // Loads the specified BVH file and returns a status code.
  192. ELoadStatus loadBVHFile(const char* buffer, char* err_text, S32& err_line);
  193. // For debug log level info
  194. void dumpBVHInfo();
  195. // Applies translations to BVH data loaded.
  196. void applyTranslations();
  197. // Returns the number of lines scanned.
  198. // Useful for error reporting.
  199. LL_INLINE S32 getLineNumber() { return mLineNumber; }
  200. // Returns required size of output buffer
  201. U32 getOutputSize();
  202. // Writes contents to datapacker
  203. bool serialize(LLDataPacker& dp);
  204. // Flags redundant keyframe data
  205. void optimize();
  206. void reset();
  207. LL_INLINE F32 getDuration() { return mDuration; }
  208. LL_INLINE bool isInitialized() { return mInitialized; }
  209. LL_INLINE ELoadStatus getStatus() { return mStatus; }
  210. protected:
  211. // Consumes one line of input from file.
  212. bool getLine(LLFILE* fp);
  213. protected:
  214. // Parsed values
  215. JointVector mJoints;
  216. ConstraintVector mConstraints;
  217. TranslationMap mTranslations;
  218. S32 mNumFrames;
  219. F32 mFrameTime;
  220. S32 mPriority;
  221. F32 mLoopInPoint;
  222. F32 mLoopOutPoint;
  223. F32 mEaseIn;
  224. F32 mEaseOut;
  225. S32 mHand;
  226. std::string mEmoteName;
  227. ELoadStatus mStatus;
  228. // Computed values
  229. F32 mDuration;
  230. // Parser state
  231. S32 mLineNumber;
  232. char mLine[BVH_PARSER_LINE_SIZE];
  233. bool mInitialized;
  234. bool mLoop;
  235. };
  236. #endif // LL_LLBVHLOADER_H