00001
00032 #ifndef LL_LLCHARACTER_H
00033 #define LL_LLCHARACTER_H
00034
00035
00036
00037
00038 #include <string>
00039
00040 #include "lljoint.h"
00041 #include "llmotioncontroller.h"
00042 #include "llassoclist.h"
00043 #include "llvisualparam.h"
00044 #include "linked_lists.h"
00045 #include "string_table.h"
00046 #include "llmemory.h"
00047 #include "llthread.h"
00048
00049 class LLPolyMesh;
00050
00051 class LLPauseRequestHandle : public LLThreadSafeRefCount
00052 {
00053 public:
00054 LLPauseRequestHandle() {};
00055 };
00056
00057 typedef LLPointer<LLPauseRequestHandle> LLAnimPauseRequest;
00058
00059
00060
00061
00062 class LLCharacter
00063 {
00064 public:
00065
00066 LLCharacter();
00067
00068
00069 virtual ~LLCharacter();
00070
00071
00072
00073
00074
00075
00076
00077
00078 virtual const char *getAnimationPrefix() = 0;
00079
00080
00081 virtual LLJoint *getRootJoint() = 0;
00082
00083
00084
00085
00086 virtual LLJoint *getJoint( const std::string &name );
00087
00088
00089 virtual LLVector3 getCharacterPosition() = 0;
00090
00091
00092 virtual LLQuaternion getCharacterRotation() = 0;
00093
00094
00095 virtual LLVector3 getCharacterVelocity() = 0;
00096
00097
00098 virtual LLVector3 getCharacterAngularVelocity() = 0;
00099
00100
00101 virtual void getGround(const LLVector3 &inPos, LLVector3 &outPos, LLVector3 &outNorm) = 0;
00102
00103
00104
00105
00106
00107
00108 virtual BOOL allocateCharacterJoints( U32 num ) = 0;
00109
00110
00111 virtual LLJoint *getCharacterJoint( U32 i ) = 0;
00112
00113
00114 virtual F32 getTimeDilation() = 0;
00115
00116
00117 virtual F32 getPixelArea() const = 0;
00118
00119
00120 virtual LLPolyMesh* getHeadMesh() = 0;
00121
00122
00123 virtual LLPolyMesh* getUpperBodyMesh() = 0;
00124
00125
00126 virtual LLVector3d getPosGlobalFromAgent(const LLVector3 &position) = 0;
00127
00128
00129 virtual LLVector3 getPosAgentFromGlobal(const LLVector3d &position) = 0;
00130
00131
00132 virtual void updateVisualParams();
00133
00134 virtual void addDebugText( const std::string& text ) = 0;
00135
00136 virtual const LLUUID& getID() = 0;
00137
00138
00139
00140
00141
00142 BOOL addMotion( const LLUUID& id, LLMotionConstructor create );
00143
00144 void removeMotion( const LLUUID& id );
00145
00146
00147 LLMotion* createMotion( const LLUUID &id );
00148
00149
00150
00151 virtual BOOL startMotion( const LLUUID& id, F32 start_offset = 0.f);
00152
00153
00154 virtual BOOL stopMotion( const LLUUID& id, BOOL stop_immediate = FALSE );
00155
00156
00157 BOOL isMotionActive( const LLUUID& id );
00158
00159
00160
00161
00162
00163 virtual void requestStopMotion( LLMotion* motion );
00164
00165
00166 void updateMotion(BOOL force_update = FALSE);
00167
00168 LLAnimPauseRequest requestPause();
00169 BOOL areAnimationsPaused() { return mMotionController.isPaused(); }
00170 void setAnimTimeFactor(F32 factor) { mMotionController.setTimeFactor(factor); }
00171 void setTimeStep(F32 time_step) { mMotionController.setTimeStep(time_step); }
00172
00173
00174
00175 virtual void flushAllMotions();
00176
00177
00178 virtual void deactivateAllMotions();
00179
00180
00181 virtual void dumpCharacter( LLJoint *joint = NULL );
00182
00183 virtual F32 getPreferredPelvisHeight() { return mPreferredPelvisHeight; }
00184
00185 virtual LLVector3 getVolumePos(S32 joint_index, LLVector3& volume_offset) { return LLVector3::zero; }
00186
00187 virtual LLJoint* findCollisionVolume(U32 volume_id) { return NULL; }
00188
00189 virtual S32 getCollisionVolumeID(std::string &name) { return -1; }
00190
00191 void setAnimationData(std::string name, void *data);
00192
00193 void *getAnimationData(std::string name);
00194
00195 void removeAnimationData(std::string name);
00196
00197 void addVisualParam(LLVisualParam *param);
00198 void addSharedVisualParam(LLVisualParam *param);
00199
00200 BOOL setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL set_by_user = FALSE );
00201 BOOL setVisualParamWeight(const char* param_name, F32 weight, BOOL set_by_user = FALSE );
00202 BOOL setVisualParamWeight(S32 index, F32 weight, BOOL set_by_user = FALSE );
00203
00204
00205 F32 getVisualParamWeight(LLVisualParam *distortion);
00206 F32 getVisualParamWeight(const char* param_name);
00207 F32 getVisualParamWeight(S32 index);
00208
00209
00210 void clearVisualParamWeights();
00211
00212
00213 LLVisualParam* getFirstVisualParam()
00214 {
00215 mCurIterator = mVisualParamIndexMap.begin();
00216 return getNextVisualParam();
00217 }
00218 LLVisualParam* getNextVisualParam()
00219 {
00220 if (mCurIterator == mVisualParamIndexMap.end())
00221 return 0;
00222 return (mCurIterator++)->second;
00223 }
00224
00225 LLVisualParam* getVisualParam(S32 id)
00226 {
00227 VisualParamIndexMap_t::iterator iter = mVisualParamIndexMap.find(id);
00228 return (iter == mVisualParamIndexMap.end()) ? 0 : iter->second;
00229 }
00230 S32 getVisualParamID(LLVisualParam *id)
00231 {
00232 VisualParamIndexMap_t::iterator iter;
00233 for (iter = mVisualParamIndexMap.begin(); iter != mVisualParamIndexMap.end(); iter++)
00234 {
00235 if (iter->second == id)
00236 return iter->first;
00237 }
00238 return 0;
00239 }
00240 S32 getVisualParamCount() { return (S32)mVisualParamIndexMap.size(); }
00241 LLVisualParam* getVisualParam(const char *name);
00242
00243
00244 ESex getSex() { return mSex; }
00245 void setSex( ESex sex ) { mSex = sex; }
00246
00247 U32 getAppearanceSerialNum() const { return mAppearanceSerialNum; }
00248 void setAppearanceSerialNum( U32 num ) { mAppearanceSerialNum = num; }
00249
00250 U32 getSkeletonSerialNum() const { return mSkeletonSerialNum; }
00251 void setSkeletonSerialNum( U32 num ) { mSkeletonSerialNum = num; }
00252
00253 static std::vector< LLCharacter* > sInstances;
00254
00255 protected:
00256 LLMotionController mMotionController;
00257
00258 LLAssocList<std::string, void *> mAnimationData;
00259
00260 F32 mPreferredPelvisHeight;
00261 ESex mSex;
00262 U32 mAppearanceSerialNum;
00263 U32 mSkeletonSerialNum;
00264 LLAnimPauseRequest mPauseRequest;
00265
00266
00267 private:
00268
00269 typedef std::map<S32, LLVisualParam *> VisualParamIndexMap_t;
00270 VisualParamIndexMap_t mVisualParamIndexMap;
00271 VisualParamIndexMap_t::iterator mCurIterator;
00272 typedef std::map<char *, LLVisualParam *> VisualParamNameMap_t;
00273 VisualParamNameMap_t mVisualParamNameMap;
00274
00275 static LLStringTable sVisualParamNames;
00276 };
00277
00278 #endif // LL_LLCHARACTER_H
00279