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