llbvhloader.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLBVHLOADER_H
00033 #define LL_LLBVHLOADER_H
00034 
00035 #include "v3math.h"
00036 #include "m3math.h"
00037 #include "llmath.h"
00038 #include "llapr.h"
00039 
00040 const S32 BVH_PARSER_LINE_SIZE = 2048;
00041 const F32 MAX_ANIM_DURATION = 30.f;
00042 class LLDataPacker;
00043 
00044 //------------------------------------------------------------------------
00045 // FileCloser
00046 //------------------------------------------------------------------------
00047 class FileCloser
00048 {
00049 public:
00050         FileCloser( apr_file_t *file )
00051         {
00052                 mFile = file;
00053         }
00054 
00055         ~FileCloser()
00056         {
00057                 apr_file_close(mFile);
00058         }
00059 protected:
00060         apr_file_t* mFile;
00061 };
00062 
00063 
00064 //------------------------------------------------------------------------
00065 // Key
00066 //------------------------------------------------------------------------
00067 struct Key
00068 {
00069         Key()
00070         {
00071                 mPos[0] = mPos[1] = mPos[2] = 0.0f;
00072                 mRot[0] = mRot[1] = mRot[2] = 0.0f;
00073                 mIgnorePos = false;
00074                 mIgnoreRot = false;
00075         }
00076 
00077         F32     mPos[3];
00078         F32     mRot[3];
00079         BOOL    mIgnorePos;
00080         BOOL    mIgnoreRot;
00081 };
00082 
00083 
00084 //------------------------------------------------------------------------
00085 // KeyVector
00086 //------------------------------------------------------------------------
00087 typedef  std::vector<Key> KeyVector;
00088 
00089 //------------------------------------------------------------------------
00090 // Joint
00091 //------------------------------------------------------------------------
00092 struct Joint
00093 {
00094         Joint(const char *name)
00095         {
00096                 mName = name;
00097                 mIgnore = FALSE;
00098                 mIgnorePositions = FALSE;
00099                 mRelativePositionKey = FALSE;
00100                 mRelativeRotationKey = FALSE;
00101                 mOutName = name;
00102                 mOrder[0] = 'X';
00103                 mOrder[1] = 'Y';
00104                 mOrder[2] = 'Z';
00105                 mOrder[3] = 0;
00106                 mNumPosKeys = 0;
00107                 mNumRotKeys = 0;
00108                 mChildTreeMaxDepth = 0;
00109                 mPriority = 0;
00110         }
00111 
00112         // Include aligned members first
00113         LLMatrix3               mFrameMatrix;
00114         LLMatrix3               mOffsetMatrix;
00115         LLVector3               mRelativePosition;
00116         //
00117         std::string             mName;
00118         BOOL                    mIgnore;
00119         BOOL                    mIgnorePositions;
00120         BOOL                    mRelativePositionKey;
00121         BOOL                    mRelativeRotationKey;
00122         std::string             mOutName;
00123         std::string             mMergeParentName;
00124         std::string             mMergeChildName;
00125         char                    mOrder[4];                      /* Flawfinder: ignore */
00126         KeyVector               mKeys;
00127         S32                             mNumPosKeys;
00128         S32                             mNumRotKeys;
00129         S32                             mChildTreeMaxDepth;
00130         S32                             mPriority;
00131 };
00132 
00133 
00134 typedef enum e_constraint_type
00135 {
00136         CONSTRAINT_TYPE_POINT,
00137         CONSTRAINT_TYPE_PLANE
00138 } EConstraintType;
00139 
00140 struct Constraint
00141 {
00142         char                    mSourceJointName[16];           /* Flawfinder: ignore */
00143         char                    mTargetJointName[16];           /* Flawfinder: ignore */
00144         S32                             mChainLength;
00145         LLVector3               mSourceOffset;
00146         LLVector3               mTargetOffset;
00147         LLVector3               mTargetDir;
00148         F32                             mEaseInStart;
00149         F32                             mEaseInStop;
00150         F32                             mEaseOutStart;
00151         F32                             mEaseOutStop;
00152         EConstraintType mConstraintType;
00153 };
00154 
00155 //------------------------------------------------------------------------
00156 // JointVector
00157 //------------------------------------------------------------------------
00158 typedef std::vector<Joint*> JointVector;
00159 
00160 //------------------------------------------------------------------------
00161 // ConstraintVector
00162 //------------------------------------------------------------------------
00163 typedef std::vector<Constraint> ConstraintVector;
00164 
00165 //------------------------------------------------------------------------
00166 // Translation
00167 //------------------------------------------------------------------------
00168 class Translation
00169 {
00170 public:
00171         Translation()
00172         {
00173                 mIgnore = FALSE;
00174                 mRelativePositionKey = FALSE;
00175                 mRelativeRotationKey = FALSE;
00176                 mPriorityModifier = 0;
00177         }
00178 
00179         std::string     mOutName;
00180         BOOL            mIgnore;
00181         BOOL            mIgnorePositions;
00182         BOOL            mRelativePositionKey;
00183         BOOL            mRelativeRotationKey;
00184         LLMatrix3       mFrameMatrix;
00185         LLMatrix3       mOffsetMatrix;
00186         LLVector3       mRelativePosition;
00187         std::string     mMergeParentName;
00188         std::string     mMergeChildName;
00189         S32                     mPriorityModifier;
00190 };
00191 
00192 //------------------------------------------------------------------------
00193 // TranslationMap
00194 //------------------------------------------------------------------------
00195 typedef std::map<std::string, Translation> TranslationMap;
00196 
00197 class LLBVHLoader
00198 {
00199         friend class LLKeyframeMotion;
00200 public:
00201         // Constructor
00202         LLBVHLoader(const char* buffer);
00203         ~LLBVHLoader();
00204         
00205         // Status Codes
00206         typedef char *Status;
00207         static char *ST_OK;
00208         static char *ST_EOF;
00209         static char *ST_NO_CONSTRAINT;
00210         static char *ST_NO_FILE;
00211         static char *ST_NO_HIER;
00212         static char *ST_NO_JOINT;
00213         static char *ST_NO_NAME;
00214         static char *ST_NO_OFFSET;
00215         static char *ST_NO_CHANNELS;
00216         static char *ST_NO_ROTATION;
00217         static char *ST_NO_AXIS;
00218         static char *ST_NO_MOTION;
00219         static char *ST_NO_FRAMES;
00220         static char *ST_NO_FRAME_TIME;
00221         static char *ST_NO_POS;
00222         static char *ST_NO_ROT;
00223         static char *ST_NO_XLT_FILE;
00224         static char *ST_NO_XLT_HEADER;
00225         static char *ST_NO_XLT_NAME;
00226         static char *ST_NO_XLT_IGNORE;
00227         static char *ST_NO_XLT_RELATIVE;
00228         static char *ST_NO_XLT_OUTNAME;
00229         static char *ST_NO_XLT_MATRIX;
00230         static char *ST_NO_XLT_MERGECHILD;
00231         static char *ST_NO_XLT_MERGEPARENT;
00232         static char *ST_NO_XLT_PRIORITY;
00233         static char *ST_NO_XLT_LOOP;
00234         static char *ST_NO_XLT_EASEIN;
00235         static char *ST_NO_XLT_EASEOUT;
00236         static char *ST_NO_XLT_HAND;
00237         static char *ST_NO_XLT_EMOTE;
00238 
00239         // Loads the specified translation table.
00240         Status loadTranslationTable(const char *fileName);
00241 
00242         // Load the specified BVH file.
00243         // Returns status code.
00244         Status loadBVHFile(const char *buffer, char *error_text, S32 &error_line);
00245 
00246         // Applies translations to BVH data loaded.
00247         void applyTranslations();
00248 
00249         // Returns the number of lines scanned.
00250         // Useful for error reporting.
00251         S32 getLineNumber() { return mLineNumber; }
00252 
00253         // returns required size of output buffer
00254         U32 getOutputSize();
00255 
00256         // writes contents to datapacker
00257         BOOL serialize(LLDataPacker& dp);
00258 
00259         // flags redundant keyframe data
00260         void optimize();
00261 
00262         void reset();
00263 
00264         F32 getDuration() { return mDuration; }
00265 
00266         BOOL isInitialized() { return mInitialized; }
00267 
00268         Status getStatus() { return mStatus; }
00269 
00270 protected:
00271         // Consumes one line of input from file.
00272         BOOL getLine(apr_file_t *fp);
00273 
00274         // parser state
00275         char            mLine[BVH_PARSER_LINE_SIZE];            /* Flawfinder: ignore */
00276         S32                     mLineNumber;
00277 
00278         // parsed values
00279         S32                                     mNumFrames;
00280         F32                                     mFrameTime;
00281         JointVector                     mJoints;
00282         ConstraintVector        mConstraints;
00283         TranslationMap          mTranslations;
00284 
00285         S32                                     mPriority;
00286         BOOL                            mLoop;
00287         F32                                     mLoopInPoint;
00288         F32                                     mLoopOutPoint;
00289         F32                                     mEaseIn;
00290         F32                                     mEaseOut;
00291         S32                                     mHand;
00292         std::string                     mEmoteName;
00293 
00294         BOOL                            mInitialized;
00295         Status                          mStatus;
00296         // computed values
00297         F32     mDuration;
00298 };
00299 
00300 #endif // LL_LLBVHLOADER_H

Generated on Thu Jul 1 06:08:20 2010 for Second Life Viewer by  doxygen 1.4.7