00001
00032 #ifndef LL_LLKEYFRAMEMOTION_H
00033 #define LL_LLKEYFRAMEMOTION_H
00034
00035
00036
00037
00038
00039 #include <string>
00040
00041 #include "llassetstorage.h"
00042 #include "llbboxlocal.h"
00043 #include "llhandmotion.h"
00044 #include "lljointstate.h"
00045 #include "llmotion.h"
00046 #include "llquaternion.h"
00047 #include "v3dmath.h"
00048 #include "v3math.h"
00049 #include "llapr.h"
00050
00051 class LLKeyframeDataCache;
00052 class LLVFS;
00053 class LLDataPacker;
00054
00055 #define MIN_REQUIRED_PIXEL_AREA_KEYFRAME (40.f)
00056 #define MAX_CHAIN_LENGTH (4)
00057
00058 const S32 KEYFRAME_MOTION_VERSION = 1;
00059 const S32 KEYFRAME_MOTION_SUBVERSION = 0;
00060
00061
00062
00063
00064 class LLKeyframeMotion :
00065 public LLMotion
00066 {
00067 friend class LLKeyframeDataCache;
00068 public:
00069
00070 LLKeyframeMotion(const LLUUID &id);
00071
00072
00073 virtual ~LLKeyframeMotion();
00074
00075 private:
00076
00077 LLPointer<LLJointState>& getJointState(U32 index);
00078 LLJoint* getJoint(U32 index);
00079
00080 public:
00081
00082
00083
00084
00085
00086
00087 static LLMotion *create(const LLUUID& id);
00088
00089 public:
00090
00091
00092
00093
00094
00095 virtual BOOL getLoop() {
00096 if (mJointMotionList) return mJointMotionList->mLoop;
00097 else return FALSE;
00098 }
00099
00100
00101 virtual F32 getDuration() {
00102 if (mJointMotionList) return mJointMotionList->mDuration;
00103 else return 0.f;
00104 }
00105
00106
00107 virtual F32 getEaseInDuration() {
00108 if (mJointMotionList) return mJointMotionList->mEaseInDuration;
00109 else return 0.f;
00110 }
00111
00112
00113 virtual F32 getEaseOutDuration() {
00114 if (mJointMotionList) return mJointMotionList->mEaseOutDuration;
00115 else return 0.f;
00116 }
00117
00118
00119 virtual LLJoint::JointPriority getPriority() {
00120 if (mJointMotionList) return mJointMotionList->mBasePriority;
00121 else return LLJoint::LOW_PRIORITY;
00122 }
00123
00124 virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
00125
00126
00127 virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_KEYFRAME; }
00128
00129
00130
00131
00132 virtual LLMotionInitStatus onInitialize(LLCharacter *character);
00133
00134
00135
00136
00137 virtual BOOL onActivate();
00138
00139
00140
00141
00142 virtual BOOL onUpdate(F32 time, U8* joint_mask);
00143
00144
00145 virtual void onDeactivate();
00146
00147 virtual void setStopTime(F32 time);
00148
00149 static void setVFS(LLVFS* vfs) { sVFS = vfs; }
00150
00151 static void onLoadComplete(LLVFS *vfs,
00152 const LLUUID& asset_uuid,
00153 LLAssetType::EType type,
00154 void* user_data, S32 status, LLExtStat ext_status);
00155
00156 public:
00157 U32 getFileSize();
00158 BOOL serialize(LLDataPacker& dp) const;
00159 BOOL deserialize(LLDataPacker& dp);
00160 BOOL isLoaded() { return mJointMotionList != NULL; }
00161
00162
00163
00164 void setLoop(BOOL loop);
00165
00166 F32 getLoopIn() {
00167 return (mJointMotionList) ? mJointMotionList->mLoopInPoint : 0.f;
00168 }
00169
00170 F32 getLoopOut() {
00171 return (mJointMotionList) ? mJointMotionList->mLoopOutPoint : 0.f;
00172 }
00173
00174 void setLoopIn(F32 in_point);
00175
00176 void setLoopOut(F32 out_point);
00177
00178 void setHandPose(LLHandMotion::eHandPose pose) {
00179 if (mJointMotionList) mJointMotionList->mHandPose = pose;
00180 }
00181
00182 LLHandMotion::eHandPose getHandPose() {
00183 return (mJointMotionList) ? mJointMotionList->mHandPose : LLHandMotion::HAND_POSE_RELAXED;
00184 }
00185
00186 void setPriority(S32 priority);
00187
00188 void setEmote(const LLUUID& emote_id);
00189
00190 void setEaseIn(F32 ease_in);
00191
00192 void setEaseOut(F32 ease_in);
00193
00194 F32 getLastUpdateTime() { return mLastLoopedTime; }
00195
00196 const LLBBoxLocal& getPelvisBBox();
00197
00198 static void flushKeyframeCache();
00199
00200 typedef enum e_constraint_type
00201 {
00202 TYPE_POINT,
00203 TYPE_PLANE
00204 } EConstraintType;
00205
00206 typedef enum e_constraint_target_type
00207 {
00208 TYPE_BODY,
00209 TYPE_GROUND
00210 } EConstraintTargetType;
00211
00212 protected:
00213
00214
00215
00216 class JointConstraintSharedData
00217 {
00218 public:
00219 JointConstraintSharedData() :
00220 mChainLength(0),
00221 mEaseInStartTime(0.f),
00222 mEaseInStopTime(0.f),
00223 mEaseOutStartTime(0.f),
00224 mEaseOutStopTime(0.f),
00225 mUseTargetOffset(FALSE),
00226 mConstraintType(TYPE_POINT),
00227 mConstraintTargetType(TYPE_BODY) {};
00228 ~JointConstraintSharedData() { delete [] mJointStateIndices; }
00229
00230 S32 mSourceConstraintVolume;
00231 LLVector3 mSourceConstraintOffset;
00232 S32 mTargetConstraintVolume;
00233 LLVector3 mTargetConstraintOffset;
00234 LLVector3 mTargetConstraintDir;
00235 S32 mChainLength;
00236 S32* mJointStateIndices;
00237 F32 mEaseInStartTime;
00238 F32 mEaseInStopTime;
00239 F32 mEaseOutStartTime;
00240 F32 mEaseOutStopTime;
00241 BOOL mUseTargetOffset;
00242 EConstraintType mConstraintType;
00243 EConstraintTargetType mConstraintTargetType;
00244 };
00245
00246
00247
00248
00249 class JointConstraint
00250 {
00251 public:
00252 JointConstraint(JointConstraintSharedData* shared_data);
00253 ~JointConstraint();
00254
00255 JointConstraintSharedData* mSharedData;
00256 F32 mWeight;
00257 F32 mTotalLength;
00258 LLVector3 mPositions[MAX_CHAIN_LENGTH];
00259 F32 mJointLengths[MAX_CHAIN_LENGTH];
00260 F32 mJointLengthFractions[MAX_CHAIN_LENGTH];
00261 BOOL mActive;
00262 LLVector3d mGroundPos;
00263 LLVector3 mGroundNorm;
00264 LLJoint* mSourceVolume;
00265 LLJoint* mTargetVolume;
00266 F32 mFixupDistanceRMS;
00267 };
00268
00269 void applyKeyframes(F32 time);
00270
00271 void applyConstraints(F32 time, U8* joint_mask);
00272
00273 void activateConstraint(JointConstraint* constraintp);
00274
00275 void initializeConstraint(JointConstraint* constraint);
00276
00277 void deactivateConstraint(JointConstraint *constraintp);
00278
00279 void applyConstraint(JointConstraint* constraintp, F32 time, U8* joint_mask);
00280
00281 BOOL setupPose();
00282
00283 public:
00284 enum AssetStatus { ASSET_LOADED, ASSET_FETCHED, ASSET_NEEDS_FETCH, ASSET_FETCH_FAILED, ASSET_UNDEFINED };
00285
00286 enum InterpolationType { IT_STEP, IT_LINEAR, IT_SPLINE };
00287
00288
00289
00290
00291 class ScaleKey
00292 {
00293 public:
00294 ScaleKey() { mTime = 0.0f; }
00295 ScaleKey(F32 time, const LLVector3 &scale) { mTime = time; mScale = scale; }
00296
00297 F32 mTime;
00298 LLVector3 mScale;
00299 };
00300
00301
00302
00303
00304 class RotationKey
00305 {
00306 public:
00307 RotationKey() { mTime = 0.0f; }
00308 RotationKey(F32 time, const LLQuaternion &rotation) { mTime = time; mRotation = rotation; }
00309
00310 F32 mTime;
00311 LLQuaternion mRotation;
00312 };
00313
00314
00315
00316
00317 class PositionKey
00318 {
00319 public:
00320 PositionKey() { mTime = 0.0f; }
00321 PositionKey(F32 time, const LLVector3 &position) { mTime = time; mPosition = position; }
00322
00323 F32 mTime;
00324 LLVector3 mPosition;
00325 };
00326
00327
00328
00329
00330 class ScaleCurve
00331 {
00332 public:
00333 ScaleCurve();
00334 ~ScaleCurve();
00335 LLVector3 getValue(F32 time, F32 duration);
00336 LLVector3 interp(F32 u, ScaleKey& before, ScaleKey& after);
00337
00338 InterpolationType mInterpolationType;
00339 S32 mNumKeys;
00340 typedef std::map<F32, ScaleKey> key_map_t;
00341 key_map_t mKeys;
00342 ScaleKey mLoopInKey;
00343 ScaleKey mLoopOutKey;
00344 };
00345
00346
00347
00348
00349 class RotationCurve
00350 {
00351 public:
00352 RotationCurve();
00353 ~RotationCurve();
00354 LLQuaternion getValue(F32 time, F32 duration);
00355 LLQuaternion interp(F32 u, RotationKey& before, RotationKey& after);
00356
00357 InterpolationType mInterpolationType;
00358 S32 mNumKeys;
00359 typedef std::map<F32, RotationKey> key_map_t;
00360 key_map_t mKeys;
00361 RotationKey mLoopInKey;
00362 RotationKey mLoopOutKey;
00363 };
00364
00365
00366
00367
00368 class PositionCurve
00369 {
00370 public:
00371 PositionCurve();
00372 ~PositionCurve();
00373 LLVector3 getValue(F32 time, F32 duration);
00374 LLVector3 interp(F32 u, PositionKey& before, PositionKey& after);
00375
00376 InterpolationType mInterpolationType;
00377 S32 mNumKeys;
00378 typedef std::map<F32, PositionKey> key_map_t;
00379 key_map_t mKeys;
00380 PositionKey mLoopInKey;
00381 PositionKey mLoopOutKey;
00382 };
00383
00384
00385
00386
00387 class JointMotion
00388 {
00389 public:
00390 PositionCurve mPositionCurve;
00391 RotationCurve mRotationCurve;
00392 ScaleCurve mScaleCurve;
00393 std::string mJointName;
00394 U32 mUsage;
00395 LLJoint::JointPriority mPriority;
00396
00397 void update(LLJointState* joint_state, F32 time, F32 duration);
00398 };
00399
00400
00401
00402
00403 class JointMotionList
00404 {
00405 public:
00406 std::vector<JointMotion*> mJointMotionArray;
00407 F32 mDuration;
00408 BOOL mLoop;
00409 F32 mLoopInPoint;
00410 F32 mLoopOutPoint;
00411 F32 mEaseInDuration;
00412 F32 mEaseOutDuration;
00413 LLJoint::JointPriority mBasePriority;
00414 LLHandMotion::eHandPose mHandPose;
00415 LLJoint::JointPriority mMaxPriority;
00416 typedef std::list<JointConstraintSharedData*> constraint_list_t;
00417 constraint_list_t mConstraints;
00418 LLBBoxLocal mPelvisBBox;
00419 public:
00420 JointMotionList();
00421 ~JointMotionList();
00422 U32 dumpDiagInfo();
00423 JointMotion* getJointMotion(U32 index) const { llassert(index < mJointMotionArray.size()); return mJointMotionArray[index]; }
00424 U32 getNumJointMotions() const { return mJointMotionArray.size(); }
00425 };
00426
00427
00428 protected:
00429 static LLVFS* sVFS;
00430
00431
00432
00433
00434 JointMotionList* mJointMotionList;
00435 std::vector<LLPointer<LLJointState> > mJointStates;
00436 LLJoint* mPelvisp;
00437 LLCharacter* mCharacter;
00438 std::string mEmoteName;
00439 typedef std::list<JointConstraint*> constraint_list_t;
00440 constraint_list_t mConstraints;
00441 U32 mLastSkeletonSerialNum;
00442 F32 mLastUpdateTime;
00443 F32 mLastLoopedTime;
00444 AssetStatus mAssetStatus;
00445 };
00446
00447 class LLKeyframeDataCache
00448 {
00449 public:
00450
00451 LLKeyframeDataCache(){};
00452 ~LLKeyframeDataCache();
00453
00454 typedef std::map<LLUUID, class LLKeyframeMotion::JointMotionList*> keyframe_data_map_t;
00455 static keyframe_data_map_t sKeyframeDataMap;
00456
00457 static void addKeyframeData(const LLUUID& id, LLKeyframeMotion::JointMotionList*);
00458 static LLKeyframeMotion::JointMotionList* getKeyframeData(const LLUUID& id);
00459
00460 static void removeKeyframeData(const LLUUID& id);
00461
00462
00463 static void dumpDiagInfo();
00464 static void clear();
00465 };
00466
00467 #endif // LL_LLKEYFRAMEMOTION_H
00468
00469