00001
00032
00033
00034
00035 #include "linden_common.h"
00036
00037 #include "llhandmotion.h"
00038 #include "llcharacter.h"
00039 #include "m3math.h"
00040
00041
00042
00043
00044
00045 const char *gHandPoseNames[LLHandMotion::NUM_HAND_POSES] =
00046 {
00047 "",
00048 "Hands_Relaxed",
00049 "Hands_Point",
00050 "Hands_Fist",
00051 "Hands_Relaxed_L",
00052 "Hands_Point_L",
00053 "Hands_Fist_L",
00054 "Hands_Relaxed_R",
00055 "Hands_Point_R",
00056 "Hands_Fist_R",
00057 "Hands_Salute_R",
00058 "Hands_Typing",
00059 "Hands_Peace_R",
00060 "Hands_Spread_R"
00061 };
00062
00063 const F32 HAND_MORPH_BLEND_TIME = 0.2f;
00064
00065
00066
00067
00068
00069 LLHandMotion::LLHandMotion(const LLUUID &id) : LLMotion(id)
00070 {
00071 mCharacter = NULL;
00072 mLastTime = 0.f;
00073 mCurrentPose = HAND_POSE_RELAXED;
00074 mNewPose = HAND_POSE_RELAXED;
00075 mName = "hand_motion";
00076
00077
00078 mJointSignature[0][LL_HAND_JOINT_NUM] = 0xff;
00079 mJointSignature[1][LL_HAND_JOINT_NUM] = 0xff;
00080 mJointSignature[2][LL_HAND_JOINT_NUM] = 0xff;
00081 }
00082
00083
00084
00085
00086
00087
00088 LLHandMotion::~LLHandMotion()
00089 {
00090 }
00091
00092
00093
00094
00095 LLMotion::LLMotionInitStatus LLHandMotion::onInitialize(LLCharacter *character)
00096 {
00097 mCharacter = character;
00098
00099 return STATUS_SUCCESS;
00100 }
00101
00102
00103
00104
00105
00106 BOOL LLHandMotion::onActivate()
00107 {
00108 LLPolyMesh *upperBodyMesh = mCharacter->getUpperBodyMesh();
00109
00110 if (upperBodyMesh)
00111 {
00112
00113 for (S32 i = 1; i < LLHandMotion::NUM_HAND_POSES; i++)
00114 {
00115 mCharacter->setVisualParamWeight(gHandPoseNames[i], 0.f);
00116 }
00117 mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], 1.f);
00118 mCharacter->updateVisualParams();
00119 }
00120 return TRUE;
00121 }
00122
00123
00124
00125
00126
00127 BOOL LLHandMotion::onUpdate(F32 time, U8* joint_mask)
00128 {
00129 eHandPose *requestedHandPose;
00130
00131 F32 timeDelta = time - mLastTime;
00132 mLastTime = time;
00133
00134 requestedHandPose = (eHandPose *)mCharacter->getAnimationData("Hand Pose");
00135
00136 if (!requestedHandPose)
00137 {
00138 if (mNewPose != HAND_POSE_RELAXED && mNewPose != mCurrentPose)
00139 {
00140 mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
00141 }
00142 mNewPose = HAND_POSE_RELAXED;
00143 }
00144 else
00145 {
00146
00147 if (*requestedHandPose != mNewPose && mNewPose != mCurrentPose && mNewPose != HAND_POSE_SPREAD)
00148 {
00149 mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], 0.f);
00150 }
00151 mNewPose = *requestedHandPose;
00152 }
00153
00154 mCharacter->removeAnimationData("Hand Pose");
00155 mCharacter->removeAnimationData("Hand Pose Priority");
00156
00157
00158
00159
00160
00161 if (mCurrentPose != mNewPose)
00162 {
00163 F32 incomingWeight = 1.f;
00164 F32 outgoingWeight = 0.f;
00165
00166 if (mNewPose != HAND_POSE_SPREAD)
00167 {
00168 incomingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mNewPose]);
00169 incomingWeight += (timeDelta / HAND_MORPH_BLEND_TIME);
00170 incomingWeight = llclamp(incomingWeight, 0.f, 1.f);
00171 mCharacter->setVisualParamWeight(gHandPoseNames[mNewPose], incomingWeight);
00172 }
00173
00174 if (mCurrentPose != HAND_POSE_SPREAD)
00175 {
00176 outgoingWeight = mCharacter->getVisualParamWeight(gHandPoseNames[mCurrentPose]);
00177 outgoingWeight -= (timeDelta / HAND_MORPH_BLEND_TIME);
00178 outgoingWeight = llclamp(outgoingWeight, 0.f, 1.f);
00179 mCharacter->setVisualParamWeight(gHandPoseNames[mCurrentPose], outgoingWeight);
00180 }
00181
00182 mCharacter->updateVisualParams();
00183
00184 if (incomingWeight == 1.f && outgoingWeight == 0.f)
00185 {
00186 mCurrentPose = mNewPose;
00187 }
00188 }
00189
00190 return TRUE;
00191 }
00192
00193
00194
00195
00196
00197 void LLHandMotion::onDeactivate()
00198 {
00199 }
00200
00201
00202
00203
00204 LLString LLHandMotion::getHandPoseName(eHandPose pose)
00205 {
00206 if ((S32)pose < LLHandMotion::NUM_HAND_POSES && (S32)pose >= 0)
00207 {
00208 return gHandPoseNames[pose];
00209 }
00210 return "";
00211 }
00212
00213 LLHandMotion::eHandPose LLHandMotion::getHandPose(LLString posename)
00214 {
00215 for (S32 pose = 0; pose < LLHandMotion::NUM_HAND_POSES; ++pose)
00216 {
00217 if (gHandPoseNames[pose] == posename)
00218 {
00219 return (eHandPose)pose;
00220 }
00221 }
00222 return (eHandPose)0;
00223 }
00224
00225