PageRenderTime 23ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcharacter/llbvhloader.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 330 lines | 189 code | 39 blank | 102 comment | 0 complexity | 1c0e367b1bdacadae493c5f3d85ff480 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llbvhloader.h
  3. * @brief Translates a BVH files to LindenLabAnimation format.
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library 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 GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLBVHLOADER_H
  27. #define LL_LLBVHLOADER_H
  28. #include "v3math.h"
  29. #include "m3math.h"
  30. #include "llmath.h"
  31. #include "llapr.h"
  32. #include "llbvhconsts.h"
  33. const S32 BVH_PARSER_LINE_SIZE = 2048;
  34. class LLDataPacker;
  35. //------------------------------------------------------------------------
  36. // FileCloser
  37. //------------------------------------------------------------------------
  38. class FileCloser
  39. {
  40. public:
  41. FileCloser( apr_file_t *file )
  42. {
  43. mFile = file;
  44. }
  45. ~FileCloser()
  46. {
  47. apr_file_close(mFile);
  48. }
  49. protected:
  50. apr_file_t* mFile;
  51. };
  52. //------------------------------------------------------------------------
  53. // Key
  54. //------------------------------------------------------------------------
  55. struct Key
  56. {
  57. Key()
  58. {
  59. mPos[0] = mPos[1] = mPos[2] = 0.0f;
  60. mRot[0] = mRot[1] = mRot[2] = 0.0f;
  61. mIgnorePos = false;
  62. mIgnoreRot = false;
  63. }
  64. F32 mPos[3];
  65. F32 mRot[3];
  66. BOOL mIgnorePos;
  67. BOOL mIgnoreRot;
  68. };
  69. //------------------------------------------------------------------------
  70. // KeyVector
  71. //------------------------------------------------------------------------
  72. typedef std::vector<Key> KeyVector;
  73. //------------------------------------------------------------------------
  74. // Joint
  75. //------------------------------------------------------------------------
  76. struct Joint
  77. {
  78. Joint(const char *name)
  79. {
  80. mName = name;
  81. mIgnore = FALSE;
  82. mIgnorePositions = FALSE;
  83. mRelativePositionKey = FALSE;
  84. mRelativeRotationKey = FALSE;
  85. mOutName = name;
  86. mOrder[0] = 'X';
  87. mOrder[1] = 'Y';
  88. mOrder[2] = 'Z';
  89. mOrder[3] = 0;
  90. mNumPosKeys = 0;
  91. mNumRotKeys = 0;
  92. mChildTreeMaxDepth = 0;
  93. mPriority = 0;
  94. }
  95. // Include aligned members first
  96. LLMatrix3 mFrameMatrix;
  97. LLMatrix3 mOffsetMatrix;
  98. LLVector3 mRelativePosition;
  99. //
  100. std::string mName;
  101. BOOL mIgnore;
  102. BOOL mIgnorePositions;
  103. BOOL mRelativePositionKey;
  104. BOOL mRelativeRotationKey;
  105. std::string mOutName;
  106. std::string mMergeParentName;
  107. std::string mMergeChildName;
  108. char mOrder[4]; /* Flawfinder: ignore */
  109. KeyVector mKeys;
  110. S32 mNumPosKeys;
  111. S32 mNumRotKeys;
  112. S32 mChildTreeMaxDepth;
  113. S32 mPriority;
  114. };
  115. struct Constraint
  116. {
  117. char mSourceJointName[16]; /* Flawfinder: ignore */
  118. char mTargetJointName[16]; /* Flawfinder: ignore */
  119. S32 mChainLength;
  120. LLVector3 mSourceOffset;
  121. LLVector3 mTargetOffset;
  122. LLVector3 mTargetDir;
  123. F32 mEaseInStart;
  124. F32 mEaseInStop;
  125. F32 mEaseOutStart;
  126. F32 mEaseOutStop;
  127. EConstraintType mConstraintType;
  128. };
  129. //------------------------------------------------------------------------
  130. // JointVector
  131. //------------------------------------------------------------------------
  132. typedef std::vector<Joint*> JointVector;
  133. //------------------------------------------------------------------------
  134. // ConstraintVector
  135. //------------------------------------------------------------------------
  136. typedef std::vector<Constraint> ConstraintVector;
  137. //------------------------------------------------------------------------
  138. // Translation
  139. //------------------------------------------------------------------------
  140. class Translation
  141. {
  142. public:
  143. Translation()
  144. {
  145. mIgnore = FALSE;
  146. mIgnorePositions = FALSE;
  147. mRelativePositionKey = FALSE;
  148. mRelativeRotationKey = FALSE;
  149. mPriorityModifier = 0;
  150. }
  151. std::string mOutName;
  152. BOOL mIgnore;
  153. BOOL mIgnorePositions;
  154. BOOL mRelativePositionKey;
  155. BOOL mRelativeRotationKey;
  156. LLMatrix3 mFrameMatrix;
  157. LLMatrix3 mOffsetMatrix;
  158. LLVector3 mRelativePosition;
  159. std::string mMergeParentName;
  160. std::string mMergeChildName;
  161. S32 mPriorityModifier;
  162. };
  163. typedef enum e_load_status
  164. {
  165. E_ST_OK,
  166. E_ST_EOF,
  167. E_ST_NO_CONSTRAINT,
  168. E_ST_NO_FILE,
  169. E_ST_NO_HIER,
  170. E_ST_NO_JOINT,
  171. E_ST_NO_NAME,
  172. E_ST_NO_OFFSET,
  173. E_ST_NO_CHANNELS,
  174. E_ST_NO_ROTATION,
  175. E_ST_NO_AXIS,
  176. E_ST_NO_MOTION,
  177. E_ST_NO_FRAMES,
  178. E_ST_NO_FRAME_TIME,
  179. E_ST_NO_POS,
  180. E_ST_NO_ROT,
  181. E_ST_NO_XLT_FILE,
  182. E_ST_NO_XLT_HEADER,
  183. E_ST_NO_XLT_NAME,
  184. E_ST_NO_XLT_IGNORE,
  185. E_ST_NO_XLT_RELATIVE,
  186. E_ST_NO_XLT_OUTNAME,
  187. E_ST_NO_XLT_MATRIX,
  188. E_ST_NO_XLT_MERGECHILD,
  189. E_ST_NO_XLT_MERGEPARENT,
  190. E_ST_NO_XLT_PRIORITY,
  191. E_ST_NO_XLT_LOOP,
  192. E_ST_NO_XLT_EASEIN,
  193. E_ST_NO_XLT_EASEOUT,
  194. E_ST_NO_XLT_HAND,
  195. E_ST_NO_XLT_EMOTE,
  196. E_ST_BAD_ROOT
  197. } ELoadStatus;
  198. //------------------------------------------------------------------------
  199. // TranslationMap
  200. //------------------------------------------------------------------------
  201. typedef std::map<std::string, Translation> TranslationMap;
  202. class LLBVHLoader
  203. {
  204. friend class LLKeyframeMotion;
  205. public:
  206. // Constructor
  207. // LLBVHLoader(const char* buffer);
  208. LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine);
  209. ~LLBVHLoader();
  210. /*
  211. // Status Codes
  212. typedef const char *status_t;
  213. static const char *ST_OK;
  214. static const char *ST_EOF;
  215. static const char *ST_NO_CONSTRAINT;
  216. static const char *ST_NO_FILE;
  217. static const char *ST_NO_HIER;
  218. static const char *ST_NO_JOINT;
  219. static const char *ST_NO_NAME;
  220. static const char *ST_NO_OFFSET;
  221. static const char *ST_NO_CHANNELS;
  222. static const char *ST_NO_ROTATION;
  223. static const char *ST_NO_AXIS;
  224. static const char *ST_NO_MOTION;
  225. static const char *ST_NO_FRAMES;
  226. static const char *ST_NO_FRAME_TIME;
  227. static const char *ST_NO_POS;
  228. static const char *ST_NO_ROT;
  229. static const char *ST_NO_XLT_FILE;
  230. static const char *ST_NO_XLT_HEADER;
  231. static const char *ST_NO_XLT_NAME;
  232. static const char *ST_NO_XLT_IGNORE;
  233. static const char *ST_NO_XLT_RELATIVE;
  234. static const char *ST_NO_XLT_OUTNAME;
  235. static const char *ST_NO_XLT_MATRIX;
  236. static const char *ST_NO_XLT_MERGECHILD;
  237. static const char *ST_NO_XLT_MERGEPARENT;
  238. static const char *ST_NO_XLT_PRIORITY;
  239. static const char *ST_NO_XLT_LOOP;
  240. static const char *ST_NO_XLT_EASEIN;
  241. static const char *ST_NO_XLT_EASEOUT;
  242. static const char *ST_NO_XLT_HAND;
  243. static const char *ST_NO_XLT_EMOTE;
  244. static const char *ST_BAD_ROOT;
  245. */
  246. // Loads the specified translation table.
  247. ELoadStatus loadTranslationTable(const char *fileName);
  248. // Load the specified BVH file.
  249. // Returns status code.
  250. ELoadStatus loadBVHFile(const char *buffer, char *error_text, S32 &error_line);
  251. // Applies translations to BVH data loaded.
  252. void applyTranslations();
  253. // Returns the number of lines scanned.
  254. // Useful for error reporting.
  255. S32 getLineNumber() { return mLineNumber; }
  256. // returns required size of output buffer
  257. U32 getOutputSize();
  258. // writes contents to datapacker
  259. BOOL serialize(LLDataPacker& dp);
  260. // flags redundant keyframe data
  261. void optimize();
  262. void reset();
  263. F32 getDuration() { return mDuration; }
  264. BOOL isInitialized() { return mInitialized; }
  265. ELoadStatus getStatus() { return mStatus; }
  266. protected:
  267. // Consumes one line of input from file.
  268. BOOL getLine(apr_file_t *fp);
  269. // parser state
  270. char mLine[BVH_PARSER_LINE_SIZE]; /* Flawfinder: ignore */
  271. S32 mLineNumber;
  272. // parsed values
  273. S32 mNumFrames;
  274. F32 mFrameTime;
  275. JointVector mJoints;
  276. ConstraintVector mConstraints;
  277. TranslationMap mTranslations;
  278. S32 mPriority;
  279. BOOL mLoop;
  280. F32 mLoopInPoint;
  281. F32 mLoopOutPoint;
  282. F32 mEaseIn;
  283. F32 mEaseOut;
  284. S32 mHand;
  285. std::string mEmoteName;
  286. BOOL mInitialized;
  287. ELoadStatus mStatus;
  288. // computed values
  289. F32 mDuration;
  290. };
  291. #endif // LL_LLBVHLOADER_H