00001
00032
00033
00034
00035
00036 #include "linden_common.h"
00037
00038 #include "llcharacter.h"
00039 #include "llstring.h"
00040
00041 #define SKEL_HEADER "Linden Skeleton 1.0"
00042
00043 LLStringTable LLCharacter::sVisualParamNames(1024);
00044
00045 std::vector< LLCharacter* > LLCharacter::sInstances;
00046
00047
00048
00049
00050
00051
00052 LLCharacter::LLCharacter()
00053 :
00054 mPreferredPelvisHeight( 0.f ),
00055 mSex( SEX_FEMALE ),
00056 mAppearanceSerialNum( 0 ),
00057 mSkeletonSerialNum( 0 )
00058 {
00059 mMotionController.setCharacter( this );
00060 sInstances.push_back(this);
00061 mPauseRequest = new LLPauseRequestHandle();
00062 }
00063
00064
00065
00066
00067
00068
00069 LLCharacter::~LLCharacter()
00070 {
00071 for (LLVisualParam *param = getFirstVisualParam();
00072 param;
00073 param = getNextVisualParam())
00074 {
00075 delete param;
00076 }
00077 std::vector<LLCharacter*>::iterator iter = std::find(sInstances.begin(), sInstances.end(), this);
00078 if (iter != sInstances.end())
00079 {
00080 sInstances.erase(iter);
00081 }
00082 }
00083
00084
00085
00086
00087
00088 LLJoint *LLCharacter::getJoint( const std::string &name )
00089 {
00090 LLJoint* joint = NULL;
00091
00092 LLJoint *root = getRootJoint();
00093 if (root)
00094 {
00095 joint = root->findJoint(name);
00096 }
00097
00098 if (!joint)
00099 {
00100 llwarns << "Failed to find joint." << llendl;
00101 }
00102 return joint;
00103 }
00104
00105
00106
00107
00108 BOOL LLCharacter::addMotion( const LLUUID& id, LLMotionConstructor create )
00109 {
00110 return mMotionController.addMotion(id, create);
00111 }
00112
00113
00114
00115
00116 void LLCharacter::removeMotion( const LLUUID& id )
00117 {
00118 mMotionController.removeMotion(id);
00119 }
00120
00121
00122
00123
00124 LLMotion* LLCharacter::createMotion( const LLUUID &id )
00125 {
00126 return mMotionController.createMotion( id );
00127 }
00128
00129
00130
00131
00132 BOOL LLCharacter::startMotion(const LLUUID &id, F32 start_offset)
00133 {
00134 return mMotionController.startMotion(id, start_offset);
00135 }
00136
00137
00138
00139
00140
00141 BOOL LLCharacter::stopMotion(const LLUUID& id, BOOL stop_immediate)
00142 {
00143 return mMotionController.stopMotionLocally(id, stop_immediate);
00144 }
00145
00146
00147
00148
00149 BOOL LLCharacter::isMotionActive(const LLUUID& id)
00150 {
00151 LLMotion *motionp = mMotionController.findMotion(id);
00152 if (motionp)
00153 {
00154 return mMotionController.isMotionActive(motionp);
00155 }
00156
00157 return FALSE;
00158 }
00159
00160
00161
00162
00163
00164 void LLCharacter::requestStopMotion( LLMotion* motion)
00165 {
00166
00167 }
00168
00169
00170
00171
00172
00173 void LLCharacter::updateMotion(BOOL force_update)
00174 {
00175
00176
00177
00178 if (mMotionController.isPaused() &&
00179 (force_update || mPauseRequest->getNumRefs() == 1))
00180 {
00181 mMotionController.unpause();
00182 }
00183
00184 mMotionController.updateMotion();
00185
00186
00187
00188 if (force_update && mPauseRequest->getNumRefs() > 1)
00189 {
00190 mMotionController.pause();
00191 }
00192 }
00193
00194
00195
00196
00197
00198 void LLCharacter::deactivateAllMotions()
00199 {
00200 mMotionController.deactivateAllMotions();
00201 }
00202
00203
00204
00205
00206
00207 void LLCharacter::flushAllMotions()
00208 {
00209 mMotionController.flushAllMotions();
00210 }
00211
00212
00213
00214
00215
00216 void LLCharacter::dumpCharacter( LLJoint* joint )
00217 {
00218
00219 if (joint == NULL)
00220 {
00221 llinfos << "DEBUG: Dumping Character @" << this << llendl;
00222 dumpCharacter( getRootJoint() );
00223 llinfos << "DEBUG: Done." << llendl;
00224 return;
00225 }
00226
00227
00228 llinfos << "DEBUG: " << joint->getName() << " (" << (joint->getParent()?joint->getParent()->getName():std::string("ROOT")) << ")" << llendl;
00229
00230
00231 for (LLJoint::child_list_t::iterator iter = joint->mChildren.begin();
00232 iter != joint->mChildren.end(); ++iter)
00233 {
00234 LLJoint* child_joint = *iter;
00235 dumpCharacter(child_joint);
00236 }
00237 }
00238
00239
00240
00241
00242 void LLCharacter::setAnimationData(std::string name, void *data)
00243 {
00244 if(mAnimationData.getValue(name))
00245 {
00246 *mAnimationData[name] = data;
00247 }
00248 else
00249 {
00250 mAnimationData.addToHead(name, data);
00251 }
00252 }
00253
00254
00255
00256
00257 void * LLCharacter::getAnimationData(std::string name)
00258 {
00259 void **result = mAnimationData.getValue(name);
00260 void *return_value;
00261 if (!result)
00262 {
00263 return_value = NULL;
00264 }
00265 else
00266 {
00267 return_value = *result;
00268 }
00269
00270 return return_value;
00271 }
00272
00273
00274
00275
00276 void LLCharacter::removeAnimationData(std::string name)
00277 {
00278 mAnimationData.remove(name);
00279 }
00280
00281
00282
00283
00284 BOOL LLCharacter::setVisualParamWeight(LLVisualParam* which_param, F32 weight, BOOL set_by_user)
00285 {
00286 S32 index = which_param->getID();
00287 VisualParamIndexMap_t::iterator index_iter = mVisualParamIndexMap.find(index);
00288 if (index_iter != mVisualParamIndexMap.end())
00289 {
00290 index_iter->second->setWeight(weight, set_by_user);
00291 return TRUE;
00292 }
00293 return FALSE;
00294 }
00295
00296
00297
00298
00299 BOOL LLCharacter::setVisualParamWeight(const char* param_name, F32 weight, BOOL set_by_user)
00300 {
00301 LLString tname(param_name);
00302 LLString::toLower(tname);
00303 char *tableptr = sVisualParamNames.checkString(tname);
00304 VisualParamNameMap_t::iterator name_iter = mVisualParamNameMap.find(tableptr);
00305 if (name_iter != mVisualParamNameMap.end())
00306 {
00307 name_iter->second->setWeight(weight, set_by_user);
00308 return TRUE;
00309 }
00310 llwarns << "LLCharacter::setVisualParamWeight() Invalid visual parameter: " << param_name << llendl;
00311 return FALSE;
00312 }
00313
00314
00315
00316
00317 BOOL LLCharacter::setVisualParamWeight(S32 index, F32 weight, BOOL set_by_user)
00318 {
00319 VisualParamIndexMap_t::iterator index_iter = mVisualParamIndexMap.find(index);
00320 if (index_iter != mVisualParamIndexMap.end())
00321 {
00322 index_iter->second->setWeight(weight, set_by_user);
00323 return TRUE;
00324 }
00325 llwarns << "LLCharacter::setVisualParamWeight() Invalid visual parameter index: " << index << llendl;
00326 return FALSE;
00327 }
00328
00329
00330
00331
00332 F32 LLCharacter::getVisualParamWeight(LLVisualParam *which_param)
00333 {
00334 S32 index = which_param->getID();
00335 VisualParamIndexMap_t::iterator index_iter = mVisualParamIndexMap.find(index);
00336 if (index_iter != mVisualParamIndexMap.end())
00337 {
00338 return index_iter->second->getWeight();
00339 }
00340 else
00341 {
00342 llwarns << "LLCharacter::getVisualParamWeight() Invalid visual parameter*, index= " << index << llendl;
00343 return 0.f;
00344 }
00345 }
00346
00347
00348
00349
00350 F32 LLCharacter::getVisualParamWeight(const char* param_name)
00351 {
00352 LLString tname(param_name);
00353 LLString::toLower(tname);
00354 char *tableptr = sVisualParamNames.checkString(tname);
00355 VisualParamNameMap_t::iterator name_iter = mVisualParamNameMap.find(tableptr);
00356 if (name_iter != mVisualParamNameMap.end())
00357 {
00358 return name_iter->second->getWeight();
00359 }
00360 llwarns << "LLCharacter::getVisualParamWeight() Invalid visual parameter: " << param_name << llendl;
00361 return 0.f;
00362 }
00363
00364
00365
00366
00367 F32 LLCharacter::getVisualParamWeight(S32 index)
00368 {
00369 VisualParamIndexMap_t::iterator index_iter = mVisualParamIndexMap.find(index);
00370 if (index_iter != mVisualParamIndexMap.end())
00371 {
00372 return index_iter->second->getWeight();
00373 }
00374 else
00375 {
00376 llwarns << "LLCharacter::getVisualParamWeight() Invalid visual parameter index: " << index << llendl;
00377 return 0.f;
00378 }
00379 }
00380
00381
00382
00383
00384 void LLCharacter::clearVisualParamWeights()
00385 {
00386 for (LLVisualParam *param = getFirstVisualParam();
00387 param;
00388 param = getNextVisualParam())
00389 {
00390 if (param->getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
00391 {
00392 param->setWeight( param->getDefaultWeight(), FALSE );
00393 }
00394 }
00395 }
00396
00397
00398
00399
00400 LLVisualParam* LLCharacter::getVisualParam(const char *param_name)
00401 {
00402 LLString tname(param_name);
00403 LLString::toLower(tname);
00404 char *tableptr = sVisualParamNames.checkString(tname);
00405 VisualParamNameMap_t::iterator name_iter = mVisualParamNameMap.find(tableptr);
00406 if (name_iter != mVisualParamNameMap.end())
00407 {
00408 return name_iter->second;
00409 }
00410 llwarns << "LLCharacter::getVisualParam() Invalid visual parameter: " << param_name << llendl;
00411 return NULL;
00412 }
00413
00414
00415
00416
00417 void LLCharacter::addSharedVisualParam(LLVisualParam *param)
00418 {
00419 S32 index = param->getID();
00420 VisualParamIndexMap_t::iterator index_iter = mVisualParamIndexMap.find(index);
00421 LLVisualParam* current_param = 0;
00422 if (index_iter != mVisualParamIndexMap.end())
00423 current_param = index_iter->second;
00424 if( current_param )
00425 {
00426 LLVisualParam* next_param = current_param;
00427 while(next_param->getNextParam())
00428 {
00429 next_param = next_param->getNextParam();
00430 }
00431 next_param->setNextParam(param);
00432 }
00433 else
00434 {
00435 llwarns << "Shared visual parameter " << param->getName() << " does not already exist with ID " <<
00436 param->getID() << llendl;
00437 }
00438 }
00439
00440
00441
00442
00443 void LLCharacter::addVisualParam(LLVisualParam *param)
00444 {
00445 S32 index = param->getID();
00446
00447 std::pair<VisualParamIndexMap_t::iterator, bool> idxres;
00448 idxres = mVisualParamIndexMap.insert(VisualParamIndexMap_t::value_type(index, param));
00449 if (!idxres.second)
00450 {
00451 llwarns << "Visual parameter " << param->getName() << " already exists with same ID as " <<
00452 param->getName() << llendl;
00453 VisualParamIndexMap_t::iterator index_iter = idxres.first;
00454 index_iter->second = param;
00455 }
00456
00457 if (param->getInfo())
00458 {
00459
00460 LLString tname(param->getName());
00461 LLString::toLower(tname);
00462 char *tableptr = sVisualParamNames.addString(tname);
00463 std::pair<VisualParamNameMap_t::iterator, bool> nameres;
00464 nameres = mVisualParamNameMap.insert(VisualParamNameMap_t::value_type(tableptr, param));
00465 if (!nameres.second)
00466 {
00467
00468 VisualParamNameMap_t::iterator name_iter = nameres.first;
00469 name_iter->second = param;
00470 }
00471 }
00472
00473 }
00474
00475
00476
00477
00478 void LLCharacter::updateVisualParams()
00479 {
00480 for (LLVisualParam *param = getFirstVisualParam();
00481 param;
00482 param = getNextVisualParam())
00483 {
00484 if (param->isAnimating())
00485 {
00486 continue;
00487 }
00488
00489 F32 effective_weight = ( param->getSex() & mSex ) ? param->getWeight() : param->getDefaultWeight();
00490 if (effective_weight != param->getLastWeight())
00491 {
00492 param->apply( mSex );
00493 }
00494 }
00495 }
00496
00497 LLAnimPauseRequest LLCharacter::requestPause()
00498 {
00499 mMotionController.pause();
00500 return mPauseRequest;
00501 }
00502