PageRenderTime 30ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcharacter/llcharacter.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 297 lines | 142 code | 69 blank | 86 comment | 11 complexity | 8c6208880b3a976cb1ea467d3ff5b961 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcharacter.h
  3. * @brief Implementation of LLCharacter class.
  4. *
  5. * $LicenseInfo:firstyear=2001&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. #ifndef LL_LLCHARACTER_H
  27. #define LL_LLCHARACTER_H
  28. //-----------------------------------------------------------------------------
  29. // Header Files
  30. //-----------------------------------------------------------------------------
  31. #include <string>
  32. #include "lljoint.h"
  33. #include "llmotioncontroller.h"
  34. #include "llvisualparam.h"
  35. #include "string_table.h"
  36. #include "llpointer.h"
  37. #include "llthread.h"
  38. class LLPolyMesh;
  39. class LLPauseRequestHandle : public LLThreadSafeRefCount
  40. {
  41. public:
  42. LLPauseRequestHandle() {};
  43. };
  44. typedef LLPointer<LLPauseRequestHandle> LLAnimPauseRequest;
  45. //-----------------------------------------------------------------------------
  46. // class LLCharacter
  47. //-----------------------------------------------------------------------------
  48. class LLCharacter
  49. {
  50. public:
  51. // Constructor
  52. LLCharacter();
  53. // Destructor
  54. virtual ~LLCharacter();
  55. //-------------------------------------------------------------------------
  56. // LLCharacter Interface
  57. // These functions must be implemented by subclasses.
  58. //-------------------------------------------------------------------------
  59. // get the prefix to be used to lookup motion data files
  60. // from the viewer data directory
  61. virtual const char *getAnimationPrefix() = 0;
  62. // get the root joint of the character
  63. virtual LLJoint *getRootJoint() = 0;
  64. // get the specified joint
  65. // default implementation does recursive search,
  66. // subclasses may optimize/cache results.
  67. virtual LLJoint *getJoint( const std::string &name );
  68. // get the position of the character
  69. virtual LLVector3 getCharacterPosition() = 0;
  70. // get the rotation of the character
  71. virtual LLQuaternion getCharacterRotation() = 0;
  72. // get the velocity of the character
  73. virtual LLVector3 getCharacterVelocity() = 0;
  74. // get the angular velocity of the character
  75. virtual LLVector3 getCharacterAngularVelocity() = 0;
  76. // get the height & normal of the ground under a point
  77. virtual void getGround(const LLVector3 &inPos, LLVector3 &outPos, LLVector3 &outNorm) = 0;
  78. // allocate an array of joints for the character skeleton
  79. // this must be overloaded to support joint subclasses,
  80. // and is called implicitly from buildSkeleton().
  81. // Note this must handle reallocation as it will be called
  82. // each time buildSkeleton() is called.
  83. virtual BOOL allocateCharacterJoints( U32 num ) = 0;
  84. // skeleton joint accessor to support joint subclasses
  85. virtual LLJoint *getCharacterJoint( U32 i ) = 0;
  86. // get the physics time dilation for the simulator
  87. virtual F32 getTimeDilation() = 0;
  88. // gets current pixel area of this character
  89. virtual F32 getPixelArea() const = 0;
  90. // gets the head mesh of the character
  91. virtual LLPolyMesh* getHeadMesh() = 0;
  92. // gets the upper body mesh of the character
  93. virtual LLPolyMesh* getUpperBodyMesh() = 0;
  94. // gets global coordinates from agent local coordinates
  95. virtual LLVector3d getPosGlobalFromAgent(const LLVector3 &position) = 0;
  96. // gets agent local coordinates from global coordinates
  97. virtual LLVector3 getPosAgentFromGlobal(const LLVector3d &position) = 0;
  98. // updates all visual parameters for this character
  99. virtual void updateVisualParams();
  100. virtual void addDebugText( const std::string& text ) = 0;
  101. virtual const LLUUID& getID() = 0;
  102. //-------------------------------------------------------------------------
  103. // End Interface
  104. //-------------------------------------------------------------------------
  105. // registers a motion with the character
  106. // returns true if successfull
  107. BOOL registerMotion( const LLUUID& id, LLMotionConstructor create );
  108. void removeMotion( const LLUUID& id );
  109. // returns an instance of a registered motion, creating one if necessary
  110. LLMotion* createMotion( const LLUUID &id );
  111. // returns an existing instance of a registered motion
  112. LLMotion* findMotion( const LLUUID &id );
  113. // start a motion
  114. // returns true if successful, false if an error occurred
  115. virtual BOOL startMotion( const LLUUID& id, F32 start_offset = 0.f);
  116. // stop a motion
  117. virtual BOOL stopMotion( const LLUUID& id, BOOL stop_immediate = FALSE );
  118. // is this motion active?
  119. BOOL isMotionActive( const LLUUID& id );
  120. // Event handler for motion deactivation.
  121. // Called when a motion has completely stopped and has been deactivated.
  122. // Subclasses may optionally override this.
  123. // The default implementation does nothing.
  124. virtual void requestStopMotion( LLMotion* motion );
  125. // periodic update function, steps the motion controller
  126. enum e_update_t { NORMAL_UPDATE, HIDDEN_UPDATE, FORCE_UPDATE };
  127. void updateMotions(e_update_t update_type);
  128. LLAnimPauseRequest requestPause();
  129. BOOL areAnimationsPaused() const { return mMotionController.isPaused(); }
  130. void setAnimTimeFactor(F32 factor) { mMotionController.setTimeFactor(factor); }
  131. void setTimeStep(F32 time_step) { mMotionController.setTimeStep(time_step); }
  132. LLMotionController& getMotionController() { return mMotionController; }
  133. // Releases all motion instances which should result in
  134. // no cached references to character joint data. This is
  135. // useful if a character wants to rebuild it's skeleton.
  136. virtual void flushAllMotions();
  137. // Flush only wipes active animations.
  138. virtual void deactivateAllMotions();
  139. // dumps information for debugging
  140. virtual void dumpCharacter( LLJoint *joint = NULL );
  141. virtual F32 getPreferredPelvisHeight() { return mPreferredPelvisHeight; }
  142. virtual LLVector3 getVolumePos(S32 joint_index, LLVector3& volume_offset) { return LLVector3::zero; }
  143. virtual LLJoint* findCollisionVolume(U32 volume_id) { return NULL; }
  144. virtual S32 getCollisionVolumeID(std::string &name) { return -1; }
  145. void setAnimationData(std::string name, void *data);
  146. void *getAnimationData(std::string name);
  147. void removeAnimationData(std::string name);
  148. void addVisualParam(LLVisualParam *param);
  149. void addSharedVisualParam(LLVisualParam *param);
  150. virtual BOOL setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL upload_bake = FALSE );
  151. virtual BOOL setVisualParamWeight(const char* param_name, F32 weight, BOOL upload_bake = FALSE );
  152. virtual BOOL setVisualParamWeight(S32 index, F32 weight, BOOL upload_bake = FALSE );
  153. // get visual param weight by param or name
  154. F32 getVisualParamWeight(LLVisualParam *distortion);
  155. F32 getVisualParamWeight(const char* param_name);
  156. F32 getVisualParamWeight(S32 index);
  157. // set all morph weights to defaults
  158. void clearVisualParamWeights();
  159. // visual parameter accessors
  160. LLVisualParam* getFirstVisualParam()
  161. {
  162. mCurIterator = mVisualParamIndexMap.begin();
  163. return getNextVisualParam();
  164. }
  165. LLVisualParam* getNextVisualParam()
  166. {
  167. if (mCurIterator == mVisualParamIndexMap.end())
  168. return 0;
  169. return (mCurIterator++)->second;
  170. }
  171. S32 getVisualParamCountInGroup(const EVisualParamGroup group) const
  172. {
  173. S32 rtn = 0;
  174. for (visual_param_index_map_t::const_iterator iter = mVisualParamIndexMap.begin();
  175. iter != mVisualParamIndexMap.end();
  176. /**/ )
  177. {
  178. if ((iter++)->second->getGroup() == group)
  179. {
  180. ++rtn;
  181. }
  182. }
  183. return rtn;
  184. }
  185. LLVisualParam* getVisualParam(S32 id) const
  186. {
  187. visual_param_index_map_t::const_iterator iter = mVisualParamIndexMap.find(id);
  188. return (iter == mVisualParamIndexMap.end()) ? 0 : iter->second;
  189. }
  190. S32 getVisualParamID(LLVisualParam *id)
  191. {
  192. visual_param_index_map_t::iterator iter;
  193. for (iter = mVisualParamIndexMap.begin(); iter != mVisualParamIndexMap.end(); iter++)
  194. {
  195. if (iter->second == id)
  196. return iter->first;
  197. }
  198. return 0;
  199. }
  200. S32 getVisualParamCount() const { return (S32)mVisualParamIndexMap.size(); }
  201. LLVisualParam* getVisualParam(const char *name);
  202. ESex getSex() const { return mSex; }
  203. void setSex( ESex sex ) { mSex = sex; }
  204. U32 getAppearanceSerialNum() const { return mAppearanceSerialNum; }
  205. void setAppearanceSerialNum( U32 num ) { mAppearanceSerialNum = num; }
  206. U32 getSkeletonSerialNum() const { return mSkeletonSerialNum; }
  207. void setSkeletonSerialNum( U32 num ) { mSkeletonSerialNum = num; }
  208. static std::vector< LLCharacter* > sInstances;
  209. static BOOL sAllowInstancesChange ; //debug use
  210. protected:
  211. LLMotionController mMotionController;
  212. typedef std::map<std::string, void *> animation_data_map_t;
  213. animation_data_map_t mAnimationData;
  214. F32 mPreferredPelvisHeight;
  215. ESex mSex;
  216. U32 mAppearanceSerialNum;
  217. U32 mSkeletonSerialNum;
  218. LLAnimPauseRequest mPauseRequest;
  219. private:
  220. // visual parameter stuff
  221. typedef std::map<S32, LLVisualParam *> visual_param_index_map_t;
  222. typedef std::map<char *, LLVisualParam *> visual_param_name_map_t;
  223. visual_param_index_map_t::iterator mCurIterator;
  224. visual_param_index_map_t mVisualParamIndexMap;
  225. visual_param_name_map_t mVisualParamNameMap;
  226. static LLStringTable sVisualParamNames;
  227. };
  228. #endif // LL_LLCHARACTER_H