aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcharacter/llbvhloader.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcharacter/llbvhloader.h')
-rw-r--r--linden/indra/llcharacter/llbvhloader.h301
1 files changed, 301 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/llbvhloader.h b/linden/indra/llcharacter/llbvhloader.h
new file mode 100644
index 0000000..0ae31ef
--- /dev/null
+++ b/linden/indra/llcharacter/llbvhloader.h
@@ -0,0 +1,301 @@
1/**
2 * @file llbvhloader.h
3 * @brief Translates a BVH files to LindenLabAnimation format.
4 *
5 * Copyright (c) 2004-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLBVHLOADER_H
29#define LL_LLBVHLOADER_H
30
31#include <string>
32#include <vector>
33#include <map>
34#include <stdtypes.h>
35#include <stdio.h>
36#include "v3math.h"
37#include "m3math.h"
38#include "llmath.h"
39#include "llapr.h"
40
41const S32 BVH_PARSER_LINE_SIZE = 2048;
42const F32 MAX_ANIM_DURATION = 30.f;
43class LLDataPacker;
44
45//------------------------------------------------------------------------
46// FileCloser
47//------------------------------------------------------------------------
48class FileCloser
49{
50public:
51 FileCloser( apr_file_t *file )
52 {
53 mFile = file;
54 }
55
56 ~FileCloser()
57 {
58 apr_file_close(mFile);
59 }
60protected:
61 apr_file_t* mFile;
62};
63
64
65//------------------------------------------------------------------------
66// Key
67//------------------------------------------------------------------------
68struct Key
69{
70 Key()
71 {
72 mPos[0] = mPos[1] = mPos[2] = 0.0f;
73 mRot[0] = mRot[1] = mRot[2] = 0.0f;
74 mIgnorePos = false;
75 mIgnoreRot = false;
76 }
77
78 F32 mPos[3];
79 F32 mRot[3];
80 BOOL mIgnorePos;
81 BOOL mIgnoreRot;
82};
83
84
85//------------------------------------------------------------------------
86// KeyVector
87//------------------------------------------------------------------------
88typedef std::vector<Key> KeyVector;
89
90//------------------------------------------------------------------------
91// Joint
92//------------------------------------------------------------------------
93struct Joint
94{
95 Joint(const char *name)
96 {
97 mName = name;
98 mIgnore = FALSE;
99 mIgnorePositions = FALSE;
100 mRelativePositionKey = FALSE;
101 mRelativeRotationKey = FALSE;
102 mOutName = name;
103 mOrder[0] = 'X';
104 mOrder[1] = 'Y';
105 mOrder[2] = 'Z';
106 mOrder[3] = 0;
107 mNumPosKeys = 0;
108 mNumRotKeys = 0;
109 mChildTreeMaxDepth = 0;
110 mPriority = 0;
111 }
112
113 // Include aligned members first
114 LLMatrix3 mFrameMatrix;
115 LLMatrix3 mOffsetMatrix;
116 LLVector3 mRelativePosition;
117 //
118 std::string mName;
119 BOOL mIgnore;
120 BOOL mIgnorePositions;
121 BOOL mRelativePositionKey;
122 BOOL mRelativeRotationKey;
123 std::string mOutName;
124 std::string mMergeParentName;
125 std::string mMergeChildName;
126 char mOrder[4]; /* Flawfinder: ignore */
127 KeyVector mKeys;
128 S32 mNumPosKeys;
129 S32 mNumRotKeys;
130 S32 mChildTreeMaxDepth;
131 S32 mPriority;
132};
133
134
135typedef enum e_constraint_type
136{
137 CONSTRAINT_TYPE_POINT,
138 CONSTRAINT_TYPE_PLANE
139} EConstraintType;
140
141struct Constraint
142{
143 char mSourceJointName[16]; /* Flawfinder: ignore */
144 char mTargetJointName[16]; /* Flawfinder: ignore */
145 S32 mChainLength;
146 LLVector3 mSourceOffset;
147 LLVector3 mTargetOffset;
148 LLVector3 mTargetDir;
149 F32 mEaseInStart;
150 F32 mEaseInStop;
151 F32 mEaseOutStart;
152 F32 mEaseOutStop;
153 EConstraintType mConstraintType;
154};
155
156//------------------------------------------------------------------------
157// JointVector
158//------------------------------------------------------------------------
159typedef std::vector<Joint*> JointVector;
160
161//------------------------------------------------------------------------
162// ConstraintVector
163//------------------------------------------------------------------------
164typedef std::vector<Constraint> ConstraintVector;
165
166//------------------------------------------------------------------------
167// Translation
168//------------------------------------------------------------------------
169class Translation
170{
171public:
172 Translation()
173 {
174 mIgnore = FALSE;
175 mRelativePositionKey = FALSE;
176 mRelativeRotationKey = FALSE;
177 mPriorityModifier = 0;
178 }
179
180 std::string mOutName;
181 BOOL mIgnore;
182 BOOL mIgnorePositions;
183 BOOL mRelativePositionKey;
184 BOOL mRelativeRotationKey;
185 LLMatrix3 mFrameMatrix;
186 LLMatrix3 mOffsetMatrix;
187 LLVector3 mRelativePosition;
188 std::string mMergeParentName;
189 std::string mMergeChildName;
190 S32 mPriorityModifier;
191};
192
193//------------------------------------------------------------------------
194// TranslationMap
195//------------------------------------------------------------------------
196typedef std::map<std::string, Translation> TranslationMap;
197
198class LLBVHLoader
199{
200 friend class LLKeyframeMotion;
201public:
202 // Constructor
203 LLBVHLoader(const char* buffer);
204 ~LLBVHLoader();
205
206 // Status Codes
207 typedef char *Status;
208 static char *ST_OK;
209 static char *ST_EOF;
210 static char *ST_NO_CONSTRAINT;
211 static char *ST_NO_FILE;
212 static char *ST_NO_HIER;
213 static char *ST_NO_JOINT;
214 static char *ST_NO_NAME;
215 static char *ST_NO_OFFSET;
216 static char *ST_NO_CHANNELS;
217 static char *ST_NO_ROTATION;
218 static char *ST_NO_AXIS;
219 static char *ST_NO_MOTION;
220 static char *ST_NO_FRAMES;
221 static char *ST_NO_FRAME_TIME;
222 static char *ST_NO_POS;
223 static char *ST_NO_ROT;
224 static char *ST_NO_XLT_FILE;
225 static char *ST_NO_XLT_HEADER;
226 static char *ST_NO_XLT_NAME;
227 static char *ST_NO_XLT_IGNORE;
228 static char *ST_NO_XLT_RELATIVE;
229 static char *ST_NO_XLT_OUTNAME;
230 static char *ST_NO_XLT_MATRIX;
231 static char *ST_NO_XLT_MERGECHILD;
232 static char *ST_NO_XLT_MERGEPARENT;
233 static char *ST_NO_XLT_PRIORITY;
234 static char *ST_NO_XLT_LOOP;
235 static char *ST_NO_XLT_EASEIN;
236 static char *ST_NO_XLT_EASEOUT;
237 static char *ST_NO_XLT_HAND;
238 static char *ST_NO_XLT_EMOTE;
239
240 // Loads the specified translation table.
241 Status loadTranslationTable(const char *fileName);
242
243 // Load the specified BVH file.
244 // Returns status code.
245 Status loadBVHFile(const char *buffer, char *error_text, S32 &error_line);
246
247 // Applies translations to BVH data loaded.
248 void applyTranslations();
249
250 // Returns the number of lines scanned.
251 // Useful for error reporting.
252 S32 getLineNumber() { return mLineNumber; }
253
254 // returns required size of output buffer
255 U32 getOutputSize();
256
257 // writes contents to datapacker
258 BOOL serialize(LLDataPacker& dp);
259
260 // flags redundant keyframe data
261 void optimize();
262
263 void reset();
264
265 F32 getDuration() { return mDuration; }
266
267 BOOL isInitialized() { return mInitialized; }
268
269 Status getStatus() { return mStatus; }
270
271protected:
272 // Consumes one line of input from file.
273 BOOL getLine(apr_file_t *fp);
274
275 // parser state
276 char mLine[BVH_PARSER_LINE_SIZE]; /* Flawfinder: ignore */
277 S32 mLineNumber;
278
279 // parsed values
280 S32 mNumFrames;
281 F32 mFrameTime;
282 JointVector mJoints;
283 ConstraintVector mConstraints;
284 TranslationMap mTranslations;
285
286 S32 mPriority;
287 BOOL mLoop;
288 F32 mLoopInPoint;
289 F32 mLoopOutPoint;
290 F32 mEaseIn;
291 F32 mEaseOut;
292 S32 mHand;
293 std::string mEmoteName;
294
295 BOOL mInitialized;
296 Status mStatus;
297 // computed values
298 F32 mDuration;
299};
300
301#endif // LL_LLBVHLOADER_H