llbvhloader.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

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