diff options
author | Jacek Antonelli | 2008-08-15 23:45:27 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:27 -0500 |
commit | a8a62201ba762e98dff92cf49033e577fc34d8d4 (patch) | |
tree | 11f8513c5cdc222f2fac0c93eb724c089803c200 /linden/indra/llcharacter/llkeyframemotion.cpp | |
parent | Second Life viewer sources 1.18.6.4-RC (diff) | |
download | meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.zip meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.gz meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.bz2 meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.xz |
Second Life viewer sources 1.19.0.0
Diffstat (limited to 'linden/indra/llcharacter/llkeyframemotion.cpp')
-rw-r--r-- | linden/indra/llcharacter/llkeyframemotion.cpp | 241 |
1 files changed, 133 insertions, 108 deletions
diff --git a/linden/indra/llcharacter/llkeyframemotion.cpp b/linden/indra/llcharacter/llkeyframemotion.cpp index 9979750..4288b8d 100644 --- a/linden/indra/llcharacter/llkeyframemotion.cpp +++ b/linden/indra/llcharacter/llkeyframemotion.cpp | |||
@@ -12,12 +12,12 @@ | |||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | 12 | * ("GPL"), unless you have obtained a separate licensing agreement |
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | 13 | * ("Other License"), formally executed by you and Linden Lab. Terms of |
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | 14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or |
15 | * online at http://secondlife.com/developers/opensource/gplv2 | 15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 |
16 | * | 16 | * |
17 | * There are special exceptions to the terms and conditions of the GPL as | 17 | * There are special exceptions to the terms and conditions of the GPL as |
18 | * it is applied to this Source Code. View the full text of the exception | 18 | * it is applied to this Source Code. View the full text of the exception |
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | 19 | * in the file doc/FLOSS-exception.txt in this software distribution, or |
20 | * online at http://secondlife.com/developers/opensource/flossexception | 20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception |
21 | * | 21 | * |
22 | * By copying, modifying or distributing this software, you acknowledge | 22 | * By copying, modifying or distributing this software, you acknowledge |
23 | * that you have read and understood your obligations described above, | 23 | * that you have read and understood your obligations described above, |
@@ -71,24 +71,22 @@ static F32 MAX_CONSTRAINTS = 10; | |||
71 | // JointMotionList | 71 | // JointMotionList |
72 | //----------------------------------------------------------------------------- | 72 | //----------------------------------------------------------------------------- |
73 | LLKeyframeMotion::JointMotionList::JointMotionList() | 73 | LLKeyframeMotion::JointMotionList::JointMotionList() |
74 | : mNumJointMotions(0), | ||
75 | mJointMotionArray(NULL) | ||
76 | { | 74 | { |
77 | } | 75 | } |
78 | 76 | ||
79 | LLKeyframeMotion::JointMotionList::~JointMotionList() | 77 | LLKeyframeMotion::JointMotionList::~JointMotionList() |
80 | { | 78 | { |
81 | for_each(mConstraints.begin(), mConstraints.end(), DeletePointer()); | 79 | for_each(mConstraints.begin(), mConstraints.end(), DeletePointer()); |
82 | delete [] mJointMotionArray; | 80 | for_each(mJointMotionArray.begin(), mJointMotionArray.end(), DeletePointer()); |
83 | } | 81 | } |
84 | 82 | ||
85 | U32 LLKeyframeMotion::JointMotionList::dumpDiagInfo() | 83 | U32 LLKeyframeMotion::JointMotionList::dumpDiagInfo() |
86 | { | 84 | { |
87 | S32 total_size = sizeof(JointMotionList); | 85 | S32 total_size = sizeof(JointMotionList); |
88 | 86 | ||
89 | for (U32 i = 0; i < mNumJointMotions; i++) | 87 | for (U32 i = 0; i < getNumJointMotions(); i++) |
90 | { | 88 | { |
91 | LLKeyframeMotion::JointMotion* joint_motion_p = &mJointMotionArray[i]; | 89 | LLKeyframeMotion::JointMotion* joint_motion_p = mJointMotionArray[i]; |
92 | 90 | ||
93 | llinfos << "\tJoint " << joint_motion_p->mJointName << llendl; | 91 | llinfos << "\tJoint " << joint_motion_p->mJointName << llendl; |
94 | if (joint_motion_p->mUsage & LLJointState::SCALE) | 92 | if (joint_motion_p->mUsage & LLJointState::SCALE) |
@@ -385,10 +383,10 @@ void LLKeyframeMotion::JointMotion::update(LLJointState* joint_state, F32 time, | |||
385 | { | 383 | { |
386 | // this value being 0 is the cause of https://jira.lindenlab.com/browse/SL-22678 but I haven't | 384 | // this value being 0 is the cause of https://jira.lindenlab.com/browse/SL-22678 but I haven't |
387 | // managed to get a stack to see how it got here. Testing for 0 here will stop the crash. | 385 | // managed to get a stack to see how it got here. Testing for 0 here will stop the crash. |
388 | if ( joint_state == 0 ) | 386 | if ( joint_state == NULL ) |
389 | { | 387 | { |
390 | return; | 388 | return; |
391 | }; | 389 | } |
392 | 390 | ||
393 | U32 usage = joint_state->getUsage(); | 391 | U32 usage = joint_state->getUsage(); |
394 | 392 | ||
@@ -431,7 +429,6 @@ void LLKeyframeMotion::JointMotion::update(LLJointState* joint_state, F32 time, | |||
431 | LLKeyframeMotion::LLKeyframeMotion(const LLUUID &id) | 429 | LLKeyframeMotion::LLKeyframeMotion(const LLUUID &id) |
432 | : LLMotion(id), | 430 | : LLMotion(id), |
433 | mJointMotionList(NULL), | 431 | mJointMotionList(NULL), |
434 | mJointStates(NULL), | ||
435 | mPelvisp(NULL), | 432 | mPelvisp(NULL), |
436 | mLastSkeletonSerialNum(0), | 433 | mLastSkeletonSerialNum(0), |
437 | mLastUpdateTime(0.f), | 434 | mLastUpdateTime(0.f), |
@@ -448,10 +445,6 @@ LLKeyframeMotion::LLKeyframeMotion(const LLUUID &id) | |||
448 | //----------------------------------------------------------------------------- | 445 | //----------------------------------------------------------------------------- |
449 | LLKeyframeMotion::~LLKeyframeMotion() | 446 | LLKeyframeMotion::~LLKeyframeMotion() |
450 | { | 447 | { |
451 | if (mJointStates) | ||
452 | { | ||
453 | delete [] mJointStates; | ||
454 | } | ||
455 | for_each(mConstraints.begin(), mConstraints.end(), DeletePointer()); | 448 | for_each(mConstraints.begin(), mConstraints.end(), DeletePointer()); |
456 | } | 449 | } |
457 | 450 | ||
@@ -464,6 +457,26 @@ LLMotion *LLKeyframeMotion::create(const LLUUID &id) | |||
464 | } | 457 | } |
465 | 458 | ||
466 | //----------------------------------------------------------------------------- | 459 | //----------------------------------------------------------------------------- |
460 | // getJointState() | ||
461 | //----------------------------------------------------------------------------- | ||
462 | LLPointer<LLJointState>& LLKeyframeMotion::getJointState(U32 index) | ||
463 | { | ||
464 | llassert_always (index < (S32)mJointStates.size()); | ||
465 | return mJointStates[index]; | ||
466 | } | ||
467 | |||
468 | //----------------------------------------------------------------------------- | ||
469 | // getJoin() | ||
470 | //----------------------------------------------------------------------------- | ||
471 | LLJoint* LLKeyframeMotion::getJoint(U32 index) | ||
472 | { | ||
473 | llassert_always (index < (S32)mJointStates.size()); | ||
474 | LLJoint* joint = mJointStates[index]->getJoint(); | ||
475 | llassert_always (joint); | ||
476 | return joint; | ||
477 | } | ||
478 | |||
479 | //----------------------------------------------------------------------------- | ||
467 | // LLKeyframeMotion::onInitialize(LLCharacter *character) | 480 | // LLKeyframeMotion::onInitialize(LLCharacter *character) |
468 | //----------------------------------------------------------------------------- | 481 | //----------------------------------------------------------------------------- |
469 | LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *character) | 482 | LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *character) |
@@ -506,17 +519,25 @@ LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *charact | |||
506 | // motion already existed in cache, so grab it | 519 | // motion already existed in cache, so grab it |
507 | mJointMotionList = joint_motion_list; | 520 | mJointMotionList = joint_motion_list; |
508 | 521 | ||
522 | mJointStates.reserve(mJointMotionList->getNumJointMotions()); | ||
523 | |||
509 | // don't forget to allocate joint states | 524 | // don't forget to allocate joint states |
510 | mJointStates = new LLJointState[mJointMotionList->mNumJointMotions]; | ||
511 | |||
512 | // set up joint states to point to character joints | 525 | // set up joint states to point to character joints |
513 | for(U32 i = 0; i < mJointMotionList->mNumJointMotions; i++) | 526 | for(U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++) |
514 | { | 527 | { |
515 | if (LLJoint *jointp = mCharacter->getJoint(mJointMotionList->mJointMotionArray[i].mJointName)) | 528 | JointMotion* joint_motion = mJointMotionList->getJointMotion(i); |
529 | if (LLJoint *joint = mCharacter->getJoint(joint_motion->mJointName)) | ||
530 | { | ||
531 | LLPointer<LLJointState> joint_state = new LLJointState; | ||
532 | mJointStates.push_back(joint_state); | ||
533 | joint_state->setJoint(joint); | ||
534 | joint_state->setUsage(joint_motion->mUsage); | ||
535 | joint_state->setPriority(joint_motion->mPriority); | ||
536 | } | ||
537 | else | ||
516 | { | 538 | { |
517 | mJointStates[i].setJoint(jointp); | 539 | // add dummy joint state with no associated joint |
518 | mJointStates[i].setUsage(mJointMotionList->mJointMotionArray[i].mUsage); | 540 | mJointStates.push_back(new LLJointState); |
519 | mJointStates[i].setPriority(joint_motion_list->mJointMotionArray[i].mPriority); | ||
520 | } | 541 | } |
521 | } | 542 | } |
522 | mAssetStatus = ASSET_LOADED; | 543 | mAssetStatus = ASSET_LOADED; |
@@ -587,11 +608,12 @@ LLMotion::LLMotionInitStatus LLKeyframeMotion::onInitialize(LLCharacter *charact | |||
587 | BOOL LLKeyframeMotion::setupPose() | 608 | BOOL LLKeyframeMotion::setupPose() |
588 | { | 609 | { |
589 | // add all valid joint states to the pose | 610 | // add all valid joint states to the pose |
590 | for (U32 jm=0; jm<mJointMotionList->mNumJointMotions; jm++) | 611 | for (U32 jm=0; jm<mJointMotionList->getNumJointMotions(); jm++) |
591 | { | 612 | { |
592 | if ( mJointStates[jm].getJoint() ) | 613 | LLPointer<LLJointState> joint_state = getJointState(jm); |
614 | if ( joint_state->getJoint() ) | ||
593 | { | 615 | { |
594 | addJointState( &mJointStates[jm] ); | 616 | addJointState( joint_state ); |
595 | } | 617 | } |
596 | } | 618 | } |
597 | 619 | ||
@@ -692,13 +714,12 @@ BOOL LLKeyframeMotion::onUpdate(F32 time, U8* joint_mask) | |||
692 | //----------------------------------------------------------------------------- | 714 | //----------------------------------------------------------------------------- |
693 | void LLKeyframeMotion::applyKeyframes(F32 time) | 715 | void LLKeyframeMotion::applyKeyframes(F32 time) |
694 | { | 716 | { |
695 | U32 i; | 717 | llassert_always (mJointMotionList->getNumJointMotions() <= mJointStates.size()); |
696 | for (i=0; i<mJointMotionList->mNumJointMotions; i++) | 718 | for (U32 i=0; i<mJointMotionList->getNumJointMotions(); i++) |
697 | { | 719 | { |
698 | mJointMotionList->mJointMotionArray[i].update( | 720 | mJointMotionList->getJointMotion(i)->update(mJointStates[i], |
699 | &mJointStates[i], | 721 | time, |
700 | time, | 722 | mJointMotionList->mDuration ); |
701 | mJointMotionList->mDuration ); | ||
702 | } | 723 | } |
703 | 724 | ||
704 | LLJoint::JointPriority* pose_priority = (LLJoint::JointPriority* )mCharacter->getAnimationData("Hand Pose Priority"); | 725 | LLJoint::JointPriority* pose_priority = (LLJoint::JointPriority* )mCharacter->getAnimationData("Hand Pose Priority"); |
@@ -793,7 +814,7 @@ void LLKeyframeMotion::initializeConstraint(JointConstraint* constraint) | |||
793 | 814 | ||
794 | S32 joint_num; | 815 | S32 joint_num; |
795 | LLVector3 source_pos = mCharacter->getVolumePos(shared_data->mSourceConstraintVolume, shared_data->mSourceConstraintOffset); | 816 | LLVector3 source_pos = mCharacter->getVolumePos(shared_data->mSourceConstraintVolume, shared_data->mSourceConstraintOffset); |
796 | LLJoint* cur_joint = mJointStates[shared_data->mJointStateIndices[0]].getJoint(); | 817 | LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[0]); |
797 | 818 | ||
798 | F32 source_pos_offset = dist_vec(source_pos, cur_joint->getWorldPosition()); | 819 | F32 source_pos_offset = dist_vec(source_pos, cur_joint->getWorldPosition()); |
799 | 820 | ||
@@ -802,7 +823,7 @@ void LLKeyframeMotion::initializeConstraint(JointConstraint* constraint) | |||
802 | // grab joint lengths | 823 | // grab joint lengths |
803 | for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++) | 824 | for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++) |
804 | { | 825 | { |
805 | cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint(); | 826 | cur_joint = getJointState(shared_data->mJointStateIndices[joint_num])->getJoint(); |
806 | if (!cur_joint) | 827 | if (!cur_joint) |
807 | { | 828 | { |
808 | return; | 829 | return; |
@@ -844,7 +865,7 @@ void LLKeyframeMotion::activateConstraint(JointConstraint* constraint) | |||
844 | 865 | ||
845 | for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++) | 866 | for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++) |
846 | { | 867 | { |
847 | LLJoint* cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint(); | 868 | LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[joint_num]); |
848 | constraint->mPositions[joint_num] = (cur_joint->getWorldPosition() - mPelvisp->getWorldPosition()) * ~mPelvisp->getWorldRotation(); | 869 | constraint->mPositions[joint_num] = (cur_joint->getWorldPosition() - mPelvisp->getWorldPosition()) * ~mPelvisp->getWorldRotation(); |
849 | } | 870 | } |
850 | 871 | ||
@@ -884,7 +905,6 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
884 | LLVector3 velocities[MAX_CHAIN_LENGTH - 1]; | 905 | LLVector3 velocities[MAX_CHAIN_LENGTH - 1]; |
885 | LLQuaternion old_rots[MAX_CHAIN_LENGTH]; | 906 | LLQuaternion old_rots[MAX_CHAIN_LENGTH]; |
886 | S32 joint_num; | 907 | S32 joint_num; |
887 | LLJoint* cur_joint; | ||
888 | 908 | ||
889 | if (time < shared_data->mEaseInStartTime) | 909 | if (time < shared_data->mEaseInStartTime) |
890 | { | 910 | { |
@@ -905,7 +925,7 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
905 | activateConstraint(constraint); | 925 | activateConstraint(constraint); |
906 | } | 926 | } |
907 | 927 | ||
908 | LLJoint* root_joint = mJointStates[shared_data->mJointStateIndices[shared_data->mChainLength]].getJoint(); | 928 | LLJoint* root_joint = getJoint(shared_data->mJointStateIndices[shared_data->mChainLength]); |
909 | LLVector3 root_pos = root_joint->getWorldPosition(); | 929 | LLVector3 root_pos = root_joint->getWorldPosition(); |
910 | // LLQuaternion root_rot = | 930 | // LLQuaternion root_rot = |
911 | root_joint->getParent()->getWorldRotation(); | 931 | root_joint->getParent()->getWorldRotation(); |
@@ -916,14 +936,14 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
916 | //apply underlying keyframe animation to get nominal "kinematic" joint positions | 936 | //apply underlying keyframe animation to get nominal "kinematic" joint positions |
917 | for (joint_num = 0; joint_num <= shared_data->mChainLength; joint_num++) | 937 | for (joint_num = 0; joint_num <= shared_data->mChainLength; joint_num++) |
918 | { | 938 | { |
919 | cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint(); | 939 | LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[joint_num]); |
920 | if (joint_mask[cur_joint->getJointNum()] >= (0xff >> (7 - getPriority()))) | 940 | if (joint_mask[cur_joint->getJointNum()] >= (0xff >> (7 - getPriority()))) |
921 | { | 941 | { |
922 | // skip constraint | 942 | // skip constraint |
923 | return; | 943 | return; |
924 | } | 944 | } |
925 | old_rots[joint_num] = cur_joint->getRotation(); | 945 | old_rots[joint_num] = cur_joint->getRotation(); |
926 | cur_joint->setRotation(mJointStates[shared_data->mJointStateIndices[joint_num]].getRotation()); | 946 | cur_joint->setRotation(getJointState(shared_data->mJointStateIndices[joint_num])->getRotation()); |
927 | } | 947 | } |
928 | 948 | ||
929 | 949 | ||
@@ -1007,7 +1027,7 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
1007 | 1027 | ||
1008 | if (shared_data->mChainLength) | 1028 | if (shared_data->mChainLength) |
1009 | { | 1029 | { |
1010 | LLQuaternion end_rot = mJointStates[shared_data->mJointStateIndices[0]].getJoint()->getWorldRotation(); | 1030 | LLQuaternion end_rot = getJoint(shared_data->mJointStateIndices[0])->getWorldRotation(); |
1011 | 1031 | ||
1012 | // slam start and end of chain to the proper positions (rest of chain stays put) | 1032 | // slam start and end of chain to the proper positions (rest of chain stays put) |
1013 | positions[0] = lerp(keyframe_source_pos, target_pos, weight); | 1033 | positions[0] = lerp(keyframe_source_pos, target_pos, weight); |
@@ -1016,7 +1036,7 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
1016 | // grab keyframe-specified positions of joints | 1036 | // grab keyframe-specified positions of joints |
1017 | for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++) | 1037 | for (joint_num = 1; joint_num < shared_data->mChainLength; joint_num++) |
1018 | { | 1038 | { |
1019 | LLVector3 kinematic_position = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint()->getWorldPosition() + | 1039 | LLVector3 kinematic_position = getJoint(shared_data->mJointStateIndices[joint_num])->getWorldPosition() + |
1020 | (source_to_target * constraint->mJointLengthFractions[joint_num]); | 1040 | (source_to_target * constraint->mJointLengthFractions[joint_num]); |
1021 | 1041 | ||
1022 | // convert intermediate joint positions to world coordinates | 1042 | // convert intermediate joint positions to world coordinates |
@@ -1061,9 +1081,9 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
1061 | 1081 | ||
1062 | for (joint_num = shared_data->mChainLength; joint_num > 0; joint_num--) | 1082 | for (joint_num = shared_data->mChainLength; joint_num > 0; joint_num--) |
1063 | { | 1083 | { |
1064 | LLQuaternion parent_rot = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint()->getParent()->getWorldRotation(); | 1084 | LLJoint* cur_joint = getJoint(shared_data->mJointStateIndices[joint_num]); |
1065 | cur_joint = mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint(); | 1085 | LLJoint* child_joint = getJoint(shared_data->mJointStateIndices[joint_num - 1]); |
1066 | LLJoint* child_joint = mJointStates[shared_data->mJointStateIndices[joint_num - 1]].getJoint(); | 1086 | LLQuaternion parent_rot = cur_joint->getParent()->getWorldRotation(); |
1067 | 1087 | ||
1068 | LLQuaternion cur_rot = cur_joint->getWorldRotation(); | 1088 | LLQuaternion cur_rot = cur_joint->getWorldRotation(); |
1069 | LLQuaternion fixup_rot; | 1089 | LLQuaternion fixup_rot; |
@@ -1088,25 +1108,25 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
1088 | 1108 | ||
1089 | if (weight != 1.f) | 1109 | if (weight != 1.f) |
1090 | { | 1110 | { |
1091 | LLQuaternion cur_rot = mJointStates[shared_data->mJointStateIndices[joint_num]].getRotation(); | 1111 | LLQuaternion cur_rot = getJointState(shared_data->mJointStateIndices[joint_num])->getRotation(); |
1092 | target_rot = nlerp(weight, cur_rot, target_rot); | 1112 | target_rot = nlerp(weight, cur_rot, target_rot); |
1093 | } | 1113 | } |
1094 | 1114 | ||
1095 | mJointStates[shared_data->mJointStateIndices[joint_num]].setRotation(target_rot); | 1115 | getJointState(shared_data->mJointStateIndices[joint_num])->setRotation(target_rot); |
1096 | cur_joint->setRotation(target_rot); | 1116 | cur_joint->setRotation(target_rot); |
1097 | } | 1117 | } |
1098 | 1118 | ||
1099 | LLJoint* end_joint = mJointStates[shared_data->mJointStateIndices[0]].getJoint(); | 1119 | LLJoint* end_joint = getJoint(shared_data->mJointStateIndices[0]); |
1100 | LLQuaternion end_local_rot = end_rot * ~end_joint->getParent()->getWorldRotation(); | 1120 | LLQuaternion end_local_rot = end_rot * ~end_joint->getParent()->getWorldRotation(); |
1101 | 1121 | ||
1102 | if (weight == 1.f) | 1122 | if (weight == 1.f) |
1103 | { | 1123 | { |
1104 | mJointStates[shared_data->mJointStateIndices[0]].setRotation(end_local_rot); | 1124 | getJointState(shared_data->mJointStateIndices[0])->setRotation(end_local_rot); |
1105 | } | 1125 | } |
1106 | else | 1126 | else |
1107 | { | 1127 | { |
1108 | LLQuaternion cur_rot = mJointStates[shared_data->mJointStateIndices[0]].getRotation(); | 1128 | LLQuaternion cur_rot = getJointState(shared_data->mJointStateIndices[0])->getRotation(); |
1109 | mJointStates[shared_data->mJointStateIndices[0]].setRotation(nlerp(weight, cur_rot, end_local_rot)); | 1129 | getJointState(shared_data->mJointStateIndices[0])->setRotation(nlerp(weight, cur_rot, end_local_rot)); |
1110 | } | 1130 | } |
1111 | 1131 | ||
1112 | // save simulated positions in pelvis-space and calculate total fixup distance | 1132 | // save simulated positions in pelvis-space and calculate total fixup distance |
@@ -1124,17 +1144,17 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8 | |||
1124 | //reset old joint rots | 1144 | //reset old joint rots |
1125 | for (joint_num = 0; joint_num <= shared_data->mChainLength; joint_num++) | 1145 | for (joint_num = 0; joint_num <= shared_data->mChainLength; joint_num++) |
1126 | { | 1146 | { |
1127 | mJointStates[shared_data->mJointStateIndices[joint_num]].getJoint()->setRotation(old_rots[joint_num]); | 1147 | getJoint(shared_data->mJointStateIndices[joint_num])->setRotation(old_rots[joint_num]); |
1128 | } | 1148 | } |
1129 | } | 1149 | } |
1130 | // simple positional constraint (pelvis only) | 1150 | // simple positional constraint (pelvis only) |
1131 | else if (mJointStates[shared_data->mJointStateIndices[0]].getUsage() & LLJointState::POS) | 1151 | else if (getJointState(shared_data->mJointStateIndices[0])->getUsage() & LLJointState::POS) |
1132 | { | 1152 | { |
1133 | LLVector3 delta = source_to_target * weight; | 1153 | LLVector3 delta = source_to_target * weight; |
1134 | LLJointState* current_joint_statep = &mJointStates[shared_data->mJointStateIndices[0]]; | 1154 | LLPointer<LLJointState> current_joint_state = getJointState(shared_data->mJointStateIndices[0]); |
1135 | LLQuaternion parent_rot = current_joint_statep->getJoint()->getParent()->getWorldRotation(); | 1155 | LLQuaternion parent_rot = current_joint_state->getJoint()->getParent()->getWorldRotation(); |
1136 | delta = delta * ~parent_rot; | 1156 | delta = delta * ~parent_rot; |
1137 | current_joint_statep->setPosition(current_joint_statep->getJoint()->getPosition() + delta); | 1157 | current_joint_state->setPosition(current_joint_state->getJoint()->getPosition() + delta); |
1138 | } | 1158 | } |
1139 | } | 1159 | } |
1140 | 1160 | ||
@@ -1145,7 +1165,6 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1145 | { | 1165 | { |
1146 | BOOL old_version = FALSE; | 1166 | BOOL old_version = FALSE; |
1147 | mJointMotionList = new LLKeyframeMotion::JointMotionList; | 1167 | mJointMotionList = new LLKeyframeMotion::JointMotionList; |
1148 | mJointMotionList->mNumJointMotions = 0; | ||
1149 | 1168 | ||
1150 | //------------------------------------------------------------------------- | 1169 | //------------------------------------------------------------------------- |
1151 | // get base priority | 1170 | // get base priority |
@@ -1261,40 +1280,38 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1261 | //------------------------------------------------------------------------- | 1280 | //------------------------------------------------------------------------- |
1262 | // get number of joint motions | 1281 | // get number of joint motions |
1263 | //------------------------------------------------------------------------- | 1282 | //------------------------------------------------------------------------- |
1264 | if (!dp.unpackU32(mJointMotionList->mNumJointMotions, "num_joints")) | 1283 | U32 num_motions = 0; |
1284 | if (!dp.unpackU32(num_motions, "num_joints")) | ||
1265 | { | 1285 | { |
1266 | llwarns << "can't read number of joints" << llendl; | 1286 | llwarns << "can't read number of joints" << llendl; |
1267 | return FALSE; | 1287 | return FALSE; |
1268 | } | 1288 | } |
1269 | 1289 | ||
1270 | if (mJointMotionList->mNumJointMotions == 0) | 1290 | if (num_motions == 0) |
1271 | { | 1291 | { |
1272 | llwarns << "no joints in animation" << llendl; | 1292 | llwarns << "no joints in animation" << llendl; |
1273 | return FALSE; | 1293 | return FALSE; |
1274 | } | 1294 | } |
1275 | else if (mJointMotionList->mNumJointMotions > LL_CHARACTER_MAX_JOINTS) | 1295 | else if (num_motions > LL_CHARACTER_MAX_JOINTS) |
1276 | { | 1296 | { |
1277 | llwarns << "too many joints in animation" << llendl; | 1297 | llwarns << "too many joints in animation" << llendl; |
1278 | return FALSE; | 1298 | return FALSE; |
1279 | } | 1299 | } |
1280 | 1300 | ||
1281 | mJointMotionList->mJointMotionArray = new JointMotion[mJointMotionList->mNumJointMotions]; | 1301 | mJointMotionList->mJointMotionArray.clear(); |
1282 | mJointStates = new LLJointState[mJointMotionList->mNumJointMotions]; | 1302 | mJointMotionList->mJointMotionArray.reserve(num_motions); |
1283 | 1303 | mJointStates.clear(); | |
1284 | if (!mJointMotionList->mJointMotionArray) | 1304 | mJointStates.reserve(num_motions); |
1285 | { | ||
1286 | mJointMotionList->mDuration = 0.0f; | ||
1287 | mJointMotionList->mEaseInDuration = 0.0f; | ||
1288 | mJointMotionList->mEaseOutDuration = 0.0f; | ||
1289 | return FALSE; | ||
1290 | } | ||
1291 | 1305 | ||
1292 | //------------------------------------------------------------------------- | 1306 | //------------------------------------------------------------------------- |
1293 | // initialize joint motions | 1307 | // initialize joint motions |
1294 | //------------------------------------------------------------------------- | 1308 | //------------------------------------------------------------------------- |
1295 | S32 k; | 1309 | |
1296 | for(U32 i=0; i<mJointMotionList->mNumJointMotions; ++i) | 1310 | for(U32 i=0; i<num_motions; ++i) |
1297 | { | 1311 | { |
1312 | JointMotion* joint_motion = new JointMotion; | ||
1313 | mJointMotionList->mJointMotionArray.push_back(joint_motion); | ||
1314 | |||
1298 | std::string joint_name; | 1315 | std::string joint_name; |
1299 | if (!dp.unpackString(joint_name, "joint_name")) | 1316 | if (!dp.unpackString(joint_name, "joint_name")) |
1300 | { | 1317 | { |
@@ -1316,9 +1333,12 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1316 | //return FALSE; | 1333 | //return FALSE; |
1317 | } | 1334 | } |
1318 | 1335 | ||
1319 | mJointMotionList->mJointMotionArray[i].mJointName = joint_name; | 1336 | joint_motion->mJointName = joint_name; |
1320 | mJointStates[i].setJoint( joint ); | 1337 | |
1321 | mJointStates[i].setUsage( 0 ); | 1338 | LLPointer<LLJointState> joint_state = new LLJointState; |
1339 | mJointStates.push_back(joint_state); | ||
1340 | joint_state->setJoint( joint ); | ||
1341 | joint_state->setUsage( 0 ); | ||
1322 | 1342 | ||
1323 | //--------------------------------------------------------------------- | 1343 | //--------------------------------------------------------------------- |
1324 | // get joint priority | 1344 | // get joint priority |
@@ -1330,36 +1350,36 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1330 | return FALSE; | 1350 | return FALSE; |
1331 | } | 1351 | } |
1332 | 1352 | ||
1333 | mJointMotionList->mJointMotionArray[i].mPriority = (LLJoint::JointPriority)joint_priority; | 1353 | joint_motion->mPriority = (LLJoint::JointPriority)joint_priority; |
1334 | if (joint_priority != LLJoint::USE_MOTION_PRIORITY && | 1354 | if (joint_priority != LLJoint::USE_MOTION_PRIORITY && |
1335 | joint_priority > mJointMotionList->mMaxPriority) | 1355 | joint_priority > mJointMotionList->mMaxPriority) |
1336 | { | 1356 | { |
1337 | mJointMotionList->mMaxPriority = (LLJoint::JointPriority)joint_priority; | 1357 | mJointMotionList->mMaxPriority = (LLJoint::JointPriority)joint_priority; |
1338 | } | 1358 | } |
1339 | 1359 | ||
1340 | mJointStates[i].setPriority((LLJoint::JointPriority)joint_priority); | 1360 | joint_state->setPriority((LLJoint::JointPriority)joint_priority); |
1341 | 1361 | ||
1342 | //--------------------------------------------------------------------- | 1362 | //--------------------------------------------------------------------- |
1343 | // scan rotation curve header | 1363 | // scan rotation curve header |
1344 | //--------------------------------------------------------------------- | 1364 | //--------------------------------------------------------------------- |
1345 | if (!dp.unpackS32(mJointMotionList->mJointMotionArray[i].mRotationCurve.mNumKeys, "num_rot_keys")) | 1365 | if (!dp.unpackS32(joint_motion->mRotationCurve.mNumKeys, "num_rot_keys")) |
1346 | { | 1366 | { |
1347 | llwarns << "can't read number of rotation keys" << llendl; | 1367 | llwarns << "can't read number of rotation keys" << llendl; |
1348 | return FALSE; | 1368 | return FALSE; |
1349 | } | 1369 | } |
1350 | 1370 | ||
1351 | mJointMotionList->mJointMotionArray[i].mRotationCurve.mInterpolationType = IT_LINEAR; | 1371 | joint_motion->mRotationCurve.mInterpolationType = IT_LINEAR; |
1352 | if (mJointMotionList->mJointMotionArray[i].mRotationCurve.mNumKeys != 0) | 1372 | if (joint_motion->mRotationCurve.mNumKeys != 0) |
1353 | { | 1373 | { |
1354 | mJointStates[i].setUsage(mJointStates[i].getUsage() | LLJointState::ROT ); | 1374 | joint_state->setUsage(joint_state->getUsage() | LLJointState::ROT ); |
1355 | } | 1375 | } |
1356 | 1376 | ||
1357 | //--------------------------------------------------------------------- | 1377 | //--------------------------------------------------------------------- |
1358 | // scan rotation curve keys | 1378 | // scan rotation curve keys |
1359 | //--------------------------------------------------------------------- | 1379 | //--------------------------------------------------------------------- |
1360 | RotationCurve *rCurve = &mJointMotionList->mJointMotionArray[i].mRotationCurve; | 1380 | RotationCurve *rCurve = &joint_motion->mRotationCurve; |
1361 | 1381 | ||
1362 | for (k = 0; k < mJointMotionList->mJointMotionArray[i].mRotationCurve.mNumKeys; k++) | 1382 | for (S32 k = 0; k < joint_motion->mRotationCurve.mNumKeys; k++) |
1363 | { | 1383 | { |
1364 | F32 time; | 1384 | F32 time; |
1365 | U16 time_short; | 1385 | U16 time_short; |
@@ -1424,24 +1444,24 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1424 | //--------------------------------------------------------------------- | 1444 | //--------------------------------------------------------------------- |
1425 | // scan position curve header | 1445 | // scan position curve header |
1426 | //--------------------------------------------------------------------- | 1446 | //--------------------------------------------------------------------- |
1427 | if (!dp.unpackS32(mJointMotionList->mJointMotionArray[i].mPositionCurve.mNumKeys, "num_pos_keys")) | 1447 | if (!dp.unpackS32(joint_motion->mPositionCurve.mNumKeys, "num_pos_keys")) |
1428 | { | 1448 | { |
1429 | llwarns << "can't read number of position keys" << llendl; | 1449 | llwarns << "can't read number of position keys" << llendl; |
1430 | return FALSE; | 1450 | return FALSE; |
1431 | } | 1451 | } |
1432 | 1452 | ||
1433 | mJointMotionList->mJointMotionArray[i].mPositionCurve.mInterpolationType = IT_LINEAR; | 1453 | joint_motion->mPositionCurve.mInterpolationType = IT_LINEAR; |
1434 | if (mJointMotionList->mJointMotionArray[i].mPositionCurve.mNumKeys != 0) | 1454 | if (joint_motion->mPositionCurve.mNumKeys != 0) |
1435 | { | 1455 | { |
1436 | mJointStates[i].setUsage(mJointStates[i].getUsage() | LLJointState::POS ); | 1456 | joint_state->setUsage(joint_state->getUsage() | LLJointState::POS ); |
1437 | } | 1457 | } |
1438 | 1458 | ||
1439 | //--------------------------------------------------------------------- | 1459 | //--------------------------------------------------------------------- |
1440 | // scan position curve keys | 1460 | // scan position curve keys |
1441 | //--------------------------------------------------------------------- | 1461 | //--------------------------------------------------------------------- |
1442 | PositionCurve *pCurve = &mJointMotionList->mJointMotionArray[i].mPositionCurve; | 1462 | PositionCurve *pCurve = &joint_motion->mPositionCurve; |
1443 | BOOL is_pelvis = mJointMotionList->mJointMotionArray[i].mJointName == "mPelvis"; | 1463 | BOOL is_pelvis = joint_motion->mJointName == "mPelvis"; |
1444 | for (k = 0; k < mJointMotionList->mJointMotionArray[i].mPositionCurve.mNumKeys; k++) | 1464 | for (S32 k = 0; k < joint_motion->mPositionCurve.mNumKeys; k++) |
1445 | { | 1465 | { |
1446 | U16 time_short; | 1466 | U16 time_short; |
1447 | PositionKey* pos_key = new PositionKey; | 1467 | PositionKey* pos_key = new PositionKey; |
@@ -1501,7 +1521,7 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1501 | } | 1521 | } |
1502 | } | 1522 | } |
1503 | 1523 | ||
1504 | mJointMotionList->mJointMotionArray[i].mUsage = mJointStates[i].getUsage(); | 1524 | joint_motion->mUsage = joint_state->getUsage(); |
1505 | } | 1525 | } |
1506 | 1526 | ||
1507 | //------------------------------------------------------------------------- | 1527 | //------------------------------------------------------------------------- |
@@ -1655,9 +1675,9 @@ BOOL LLKeyframeMotion::deserialize(LLDataPacker& dp) | |||
1655 | } | 1675 | } |
1656 | joint = parent; | 1676 | joint = parent; |
1657 | constraintp->mJointStateIndices[i] = -1; | 1677 | constraintp->mJointStateIndices[i] = -1; |
1658 | for (U32 j = 0; j < mJointMotionList->mNumJointMotions; j++) | 1678 | for (U32 j = 0; j < mJointMotionList->getNumJointMotions(); j++) |
1659 | { | 1679 | { |
1660 | if(mJointStates[j].getJoint() == joint) | 1680 | if(getJoint(j) == joint) |
1661 | { | 1681 | { |
1662 | constraintp->mJointStateIndices[i] = (S32)j; | 1682 | constraintp->mJointStateIndices[i] = (S32)j; |
1663 | break; | 1683 | break; |
@@ -1695,11 +1715,11 @@ BOOL LLKeyframeMotion::serialize(LLDataPacker& dp) const | |||
1695 | success &= dp.packF32(mJointMotionList->mEaseInDuration, "ease_in_duration"); | 1715 | success &= dp.packF32(mJointMotionList->mEaseInDuration, "ease_in_duration"); |
1696 | success &= dp.packF32(mJointMotionList->mEaseOutDuration, "ease_out_duration"); | 1716 | success &= dp.packF32(mJointMotionList->mEaseOutDuration, "ease_out_duration"); |
1697 | success &= dp.packU32(mJointMotionList->mHandPose, "hand_pose"); | 1717 | success &= dp.packU32(mJointMotionList->mHandPose, "hand_pose"); |
1698 | success &= dp.packU32(mJointMotionList->mNumJointMotions, "num_joints"); | 1718 | success &= dp.packU32(mJointMotionList->getNumJointMotions(), "num_joints"); |
1699 | 1719 | ||
1700 | for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++) | 1720 | for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++) |
1701 | { | 1721 | { |
1702 | JointMotion* joint_motionp = &mJointMotionList->mJointMotionArray[i]; | 1722 | JointMotion* joint_motionp = mJointMotionList->getJointMotion(i); |
1703 | success &= dp.packString(joint_motionp->mJointName.c_str(), "joint_name"); | 1723 | success &= dp.packString(joint_motionp->mJointName.c_str(), "joint_name"); |
1704 | success &= dp.packS32(joint_motionp->mPriority, "joint_priority"); | 1724 | success &= dp.packS32(joint_motionp->mPriority, "joint_priority"); |
1705 | success &= dp.packS32(joint_motionp->mRotationCurve.mNumKeys, "num_rot_keys"); | 1725 | success &= dp.packS32(joint_motionp->mRotationCurve.mNumKeys, "num_rot_keys"); |
@@ -1806,13 +1826,14 @@ void LLKeyframeMotion::setPriority(S32 priority) | |||
1806 | mJointMotionList->mBasePriority = (LLJoint::JointPriority)priority; | 1826 | mJointMotionList->mBasePriority = (LLJoint::JointPriority)priority; |
1807 | mJointMotionList->mMaxPriority = mJointMotionList->mBasePriority; | 1827 | mJointMotionList->mMaxPriority = mJointMotionList->mBasePriority; |
1808 | 1828 | ||
1809 | for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++) | 1829 | for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++) |
1810 | { | 1830 | { |
1811 | mJointMotionList->mJointMotionArray[i].mPriority = (LLJoint::JointPriority)llclamp( | 1831 | JointMotion* joint_motion = mJointMotionList->getJointMotion(i); |
1812 | (S32)mJointMotionList->mJointMotionArray[i].mPriority + priority_delta, | 1832 | joint_motion->mPriority = (LLJoint::JointPriority)llclamp( |
1833 | (S32)joint_motion->mPriority + priority_delta, | ||
1813 | (S32)LLJoint::LOW_PRIORITY, | 1834 | (S32)LLJoint::LOW_PRIORITY, |
1814 | (S32)LLJoint::HIGHEST_PRIORITY); | 1835 | (S32)LLJoint::HIGHEST_PRIORITY); |
1815 | mJointStates[i].setPriority(mJointMotionList->mJointMotionArray[i].mPriority); | 1836 | getJointState(i)->setPriority(joint_motion->mPriority); |
1816 | } | 1837 | } |
1817 | } | 1838 | } |
1818 | } | 1839 | } |
@@ -1888,11 +1909,13 @@ void LLKeyframeMotion::setLoopIn(F32 in_point) | |||
1888 | mJointMotionList->mLoopInPoint = in_point; | 1909 | mJointMotionList->mLoopInPoint = in_point; |
1889 | 1910 | ||
1890 | // set up loop keys | 1911 | // set up loop keys |
1891 | for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++) | 1912 | for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++) |
1892 | { | 1913 | { |
1893 | PositionCurve* pos_curve = &mJointMotionList->mJointMotionArray[i].mPositionCurve; | 1914 | JointMotion* joint_motion = mJointMotionList->getJointMotion(i); |
1894 | RotationCurve* rot_curve = &mJointMotionList->mJointMotionArray[i].mRotationCurve; | 1915 | |
1895 | ScaleCurve* scale_curve = &mJointMotionList->mJointMotionArray[i].mScaleCurve; | 1916 | PositionCurve* pos_curve = &joint_motion->mPositionCurve; |
1917 | RotationCurve* rot_curve = &joint_motion->mRotationCurve; | ||
1918 | ScaleCurve* scale_curve = &joint_motion->mScaleCurve; | ||
1896 | 1919 | ||
1897 | pos_curve->mLoopInKey.mTime = mJointMotionList->mLoopInPoint; | 1920 | pos_curve->mLoopInKey.mTime = mJointMotionList->mLoopInPoint; |
1898 | rot_curve->mLoopInKey.mTime = mJointMotionList->mLoopInPoint; | 1921 | rot_curve->mLoopInKey.mTime = mJointMotionList->mLoopInPoint; |
@@ -1915,11 +1938,13 @@ void LLKeyframeMotion::setLoopOut(F32 out_point) | |||
1915 | mJointMotionList->mLoopOutPoint = out_point; | 1938 | mJointMotionList->mLoopOutPoint = out_point; |
1916 | 1939 | ||
1917 | // set up loop keys | 1940 | // set up loop keys |
1918 | for (U32 i = 0; i < mJointMotionList->mNumJointMotions; i++) | 1941 | for (U32 i = 0; i < mJointMotionList->getNumJointMotions(); i++) |
1919 | { | 1942 | { |
1920 | PositionCurve* pos_curve = &mJointMotionList->mJointMotionArray[i].mPositionCurve; | 1943 | JointMotion* joint_motion = mJointMotionList->getJointMotion(i); |
1921 | RotationCurve* rot_curve = &mJointMotionList->mJointMotionArray[i].mRotationCurve; | 1944 | |
1922 | ScaleCurve* scale_curve = &mJointMotionList->mJointMotionArray[i].mScaleCurve; | 1945 | PositionCurve* pos_curve = &joint_motion->mPositionCurve; |
1946 | RotationCurve* rot_curve = &joint_motion->mRotationCurve; | ||
1947 | ScaleCurve* scale_curve = &joint_motion->mScaleCurve; | ||
1923 | 1948 | ||
1924 | pos_curve->mLoopOutKey.mTime = mJointMotionList->mLoopOutPoint; | 1949 | pos_curve->mLoopOutKey.mTime = mJointMotionList->mLoopOutPoint; |
1925 | rot_curve->mLoopOutKey.mTime = mJointMotionList->mLoopOutPoint; | 1950 | rot_curve->mLoopOutKey.mTime = mJointMotionList->mLoopOutPoint; |
@@ -2020,10 +2045,10 @@ void LLKeyframeMotion::writeCAL3D(apr_file_t* fp) | |||
2020 | // </TRACK> | 2045 | // </TRACK> |
2021 | // </ANIMATION> | 2046 | // </ANIMATION> |
2022 | 2047 | ||
2023 | apr_file_printf(fp, "<ANIMATION VERSION=\"1000\" DURATION=\"%.5f\" NUMTRACKS=\"%d\">\n", getDuration(), mJointMotionList->mNumJointMotions); | 2048 | apr_file_printf(fp, "<ANIMATION VERSION=\"1000\" DURATION=\"%.5f\" NUMTRACKS=\"%d\">\n", getDuration(), mJointMotionList->getNumJointMotions()); |
2024 | for (U32 joint_index = 0; joint_index < mJointMotionList->mNumJointMotions; joint_index++) | 2049 | for (U32 joint_index = 0; joint_index < mJointMotionList->getNumJointMotions(); joint_index++) |
2025 | { | 2050 | { |
2026 | JointMotion* joint_motionp = &mJointMotionList->mJointMotionArray[joint_index]; | 2051 | JointMotion* joint_motionp = mJointMotionList->getJointMotion(joint_index); |
2027 | LLJoint* animated_joint = mCharacter->getJoint(joint_motionp->mJointName); | 2052 | LLJoint* animated_joint = mCharacter->getJoint(joint_motionp->mJointName); |
2028 | S32 joint_num = animated_joint->mJointNum + 1; | 2053 | S32 joint_num = animated_joint->mJointNum + 1; |
2029 | 2054 | ||