PageRenderTime 125ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcharacter/llhandmotion.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 220 lines | 127 code | 31 blank | 62 comment | 28 complexity | 3efe1b2be6f01875e0f8767d27fd9bf1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llhandmotion.cpp
  3. * @brief Implementation of LLHandMotion 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. //-----------------------------------------------------------------------------
  27. // Header Files
  28. //-----------------------------------------------------------------------------
  29. #include "linden_common.h"
  30. #include "llhandmotion.h"
  31. #include "llcharacter.h"
  32. #include "m3math.h"
  33. //-----------------------------------------------------------------------------
  34. // Constants
  35. //-----------------------------------------------------------------------------
  36. const char *gHandPoseNames[LLHandMotion::NUM_HAND_POSES] = /* Flawfinder: ignore */
  37. {
  38. "",
  39. "Hands_Relaxed",
  40. "Hands_Point",
  41. "Hands_Fist",
  42. "Hands_Relaxed_L",
  43. "Hands_Point_L",
  44. "Hands_Fist_L",
  45. "Hands_Relaxed_R",
  46. "Hands_Point_R",
  47. "Hands_Fist_R",
  48. "Hands_Salute_R",
  49. "Hands_Typing",
  50. "Hands_Peace_R",
  51. "Hands_Spread_R"
  52. };
  53. const F32 HAND_MORPH_BLEND_TIME = 0.2f;
  54. //-----------------------------------------------------------------------------
  55. // LLHandMotion()
  56. // Class Constructor
  57. //-----------------------------------------------------------------------------
  58. LLHandMotion::LLHandMotion(const LLUUID &id) : LLMotion(id)
  59. {
  60. mCharacter = NULL;
  61. mLastTime = 0.f;
  62. mCurrentPose = HAND_POSE_RELAXED;
  63. mNewPose = HAND_POSE_RELAXED;
  64. mName = "hand_motion";
  65. //RN: flag hand joint as highest priority for now, until we implement a proper animation track
  66. mJointSignature[0][LL_HAND_JOINT_NUM] = 0xff;
  67. mJointSignature[1][LL_HAND_JOINT_NUM] = 0xff;
  68. mJointSignature[2][LL_HAND_JOINT_NUM] = 0xff;
  69. }
  70. //-----------------------------------------------------------------------------
  71. // ~LLHandMotion()
  72. // Class Destructor
  73. //-----------------------------------------------------------------------------
  74. LLHandMotion::~LLHandMotion()
  75. {
  76. }
  77. //-----------------------------------------------------------------------------
  78. // LLHandMotion::onInitialize(LLCharacter *character)
  79. //-----------------------------------------------------------------------------
  80. LLMotion::LLMotionInitStatus LLHandMotion::onInitialize(LLCharacter *character)
  81. {
  82. mCharacter = character;
  83. return STATUS_SUCCESS;
  84. }
  85. //-----------------------------------------------------------------------------
  86. // LLHandMotion::onActivate()
  87. //-----------------------------------------------------------------------------
  88. BOOL LLHandMotion::onActivate()
  89. {
  90. LLPolyMesh *upperBodyMesh = mCharacter->getUpperBodyMesh();
  91. if (upperBodyMesh)
  92. {
  93. // Note: 0 is the default
  94. for (S32 i = 1; i < LLHandMotion::NUM_HAND_POSES; i++)
  95. {
  96. mCharacter->setVisualParamWeight(gHandPoseNames[i], 0.f);
  97. }
  98. mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], 1.f);
  99. mCharacter->updateVisualParams();
  100. }
  101. return TRUE;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // LLHandMotion::onUpdate()
  105. //-----------------------------------------------------------------------------
  106. BOOL LLHandMotion::onUpdate(F32 time, U8* joint_mask)
  107. {
  108. eHandPose *requestedHandPose;
  109. F32 timeDelta = time - mLastTime;
  110. mLastTime = time;
  111. requestedHandPose = (eHandPose *)mCharacter->getAnimationData("Hand Pose");
  112. // check to see if requested pose has changed
  113. if (!requestedHandPose)
  114. {
  115. if (mNewPose != HAND_POSE_RELAXED && mNewPose != mCurrentPose)
  116. {
  117. mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
  118. }
  119. mNewPose = HAND_POSE_RELAXED;
  120. }
  121. else
  122. {
  123. // this is a new morph we didn't know about before
  124. if (*requestedHandPose != mNewPose && mNewPose != mCurrentPose && mNewPose != HAND_POSE_SPREAD)
  125. {
  126. mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
  127. }
  128. mNewPose = *requestedHandPose;
  129. }
  130. mCharacter->removeAnimationData("Hand Pose");
  131. mCharacter->removeAnimationData("Hand Pose Priority");
  132. // if (requestedHandPose)
  133. // llinfos << "Hand Pose " << *requestedHandPose << llendl;
  134. // if we are still blending...
  135. if (mCurrentPose != mNewPose)
  136. {
  137. F32 incomingWeight = 1.f;
  138. F32 outgoingWeight = 0.f;
  139. if (mNewPose != HAND_POSE_SPREAD)
  140. {
  141. incomingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mNewPose]);
  142. incomingWeight += (timeDelta / HAND_MORPH_BLEND_TIME);
  143. incomingWeight = llclamp(incomingWeight, 0.f, 1.f);
  144. mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], incomingWeight);
  145. }
  146. if (mCurrentPose != HAND_POSE_SPREAD)
  147. {
  148. outgoingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mCurrentPose]);
  149. outgoingWeight -= (timeDelta / HAND_MORPH_BLEND_TIME);
  150. outgoingWeight = llclamp(outgoingWeight, 0.f, 1.f);
  151. mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], outgoingWeight);
  152. }
  153. mCharacter->updateVisualParams();
  154. if (incomingWeight == 1.f && outgoingWeight == 0.f)
  155. {
  156. mCurrentPose = mNewPose;
  157. }
  158. }
  159. return TRUE;
  160. }
  161. //-----------------------------------------------------------------------------
  162. // LLHandMotion::onDeactivate()
  163. //-----------------------------------------------------------------------------
  164. void LLHandMotion::onDeactivate()
  165. {
  166. }
  167. //-----------------------------------------------------------------------------
  168. // LLHandMotion::getHandPoseName()
  169. //-----------------------------------------------------------------------------
  170. std::string LLHandMotion::getHandPoseName(eHandPose pose)
  171. {
  172. if ((S32)pose < LLHandMotion::NUM_HAND_POSES && (S32)pose >= 0)
  173. {
  174. return std::string(gHandPoseNames[pose]);
  175. }
  176. return LLStringUtil::null;
  177. }
  178. LLHandMotion::eHandPose LLHandMotion::getHandPose(std::string posename)
  179. {
  180. for (S32 pose = 0; pose < LLHandMotion::NUM_HAND_POSES; ++pose)
  181. {
  182. if (gHandPoseNames[pose] == posename)
  183. {
  184. return (eHandPose)pose;
  185. }
  186. }
  187. return (eHandPose)0;
  188. }
  189. // End