PageRenderTime 36ms CodeModel.GetById 16ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

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