Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 19 files). Show all
Unified · Split
| @@ -30,7 +30,7 @@ enum StandingFootState { · 29 unmodified lines | ||
| 30 | 30 | }; |
| 31 | 31 | |
| 32 | 32 | SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) : |
| 33 | − Model(parent, rig), | |
| 33 | + Model(rig, parent), | |
| 34 | 34 | _triangleFanID(DependencyManager::get<GeometryCache>()->allocateID()), |
| 35 | 35 | _owningAvatar(owningAvatar), |
| 36 | 36 | _boundingShape(), |
| @@ -51,11 +51,13 @@ SkeletonModel::~SkeletonModel() { · 14 unmodified lines | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | void SkeletonModel::initJointStates(QVector<JointState> states) { |
| 54 | − Model::initJointStates(states); | |
| 54 | + const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 55 | + glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset; | |
| 56 | + _boundingRadius = _rig->initJointStates(states, parentTransform); | |
| 55 | 57 | |
| 56 | 58 | // Determine the default eye position for avatar scale = 1.0 |
| 57 | 59 | int headJointIndex = _geometry->getFBXGeometry().headJointIndex; |
| 58 | − if (0 <= headJointIndex && headJointIndex < _jointStates.size()) { | |
| 60 | + if (0 <= headJointIndex && headJointIndex < _rig->getJointStateCount()) { | |
| 59 | 61 | |
| 60 | 62 | glm::vec3 leftEyePosition, rightEyePosition; |
| 61 | 63 | getEyeModelPositions(leftEyePosition, rightEyePosition); |
| @@ -75,8 +77,8 @@ void SkeletonModel::initJointStates(QVector<JointState> states) { · 13 unmodified lines | ||
| 75 | 77 | // the SkeletonModel override of updateJointState() will clear the translation part |
| 76 | 78 | // of its root joint and we need that done before we try to build shapes hence we |
| 77 | 79 | // recompute all joint transforms at this time. |
| 78 | − for (int i = 0; i < _jointStates.size(); i++) { | |
| 79 | − updateJointState(i); | |
| 80 | + for (int i = 0; i < _rig->getJointStateCount(); i++) { | |
| 81 | + _rig->updateJointState(i, parentTransform); | |
| 80 | 82 | } |
| 81 | 83 | |
| 82 | 84 | clearShapes(); |
| @@ -168,7 +170,7 @@ void SkeletonModel::getHandShapes(int jointIndex, QVector<const Shape*>& shapes) · 85 unmodified lines | ||
| 168 | 170 | || jointIndex == getRightHandJointIndex()) { |
| 169 | 171 | // get all shapes that have this hand as an ancestor in the skeleton heirarchy |
| 170 | 172 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| 171 | − for (int i = 0; i < _jointStates.size(); i++) { | |
| 173 | + for (int i = 0; i < _rig->getJointStateCount(); i++) { | |
| 172 | 174 | const FBXJoint& joint = geometry.joints[i]; |
| 173 | 175 | int parentIndex = joint.parentIndex; |
| 174 | 176 | Shape* shape = _shapes[i]; |
| @@ -211,7 +213,7 @@ bool operator<(const IndexValue& firstIndex, const IndexValue& secondIndex) { · 36 unmodified lines | ||
| 211 | 213 | } |
| 212 | 214 | |
| 213 | 215 | void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position) { |
| 214 | − if (jointIndex == -1 || jointIndex >= _jointStates.size()) { | |
| 216 | + if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) { | |
| 215 | 217 | return; |
| 216 | 218 | } |
| 217 | 219 | // NOTE: 'position' is in model-frame |
| @@ -226,16 +228,20 @@ void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position) · 8 unmodified lines | ||
| 226 | 228 | if (forearmLength < EPSILON) { |
| 227 | 229 | return; |
| 228 | 230 | } |
| 229 | − JointState& state = _jointStates[jointIndex]; | |
| 230 | − glm::quat handRotation = state.getRotation(); | |
| 231 | + glm::quat handRotation; | |
| 232 | + if (!_rig->getJointStateRotation(jointIndex, handRotation)) { | |
| 233 | + return; | |
| 234 | + } | |
| 231 | 235 | |
| 232 | 236 | // align hand with forearm |
| 233 | 237 | float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f; |
| 234 | − state.applyRotationDelta(rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector), true, PALM_PRIORITY); | |
| 238 | + _rig->applyJointRotationDelta(jointIndex, | |
| 239 | + rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector), | |
| 240 | + true, PALM_PRIORITY); | |
| 235 | 241 | } |
| 236 | 242 | |
| 237 | 243 | void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { |
| 238 | − if (jointIndex == -1 || jointIndex >= _jointStates.size()) { | |
| 244 | + if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) { | |
| 239 | 245 | return; |
| 240 | 246 | } |
| 241 | 247 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| @@ -261,43 +267,40 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { · 19 unmodified lines | ||
| 261 | 267 | glm::vec3 forearm = palmRotation * glm::vec3(sign * forearmLength, 0.0f, 0.0f); |
| 262 | 268 | setJointPosition(parentJointIndex, palmPosition + forearm, |
| 263 | 269 | glm::quat(), false, -1, false, glm::vec3(0.0f, -1.0f, 0.0f), PALM_PRIORITY); |
| 264 | − JointState& parentState = _jointStates[parentJointIndex]; | |
| 265 | − parentState.setRotationInBindFrame(palmRotation, PALM_PRIORITY); | |
| 270 | + _rig->setJointRotationInBindFrame(parentJointIndex, palmRotation, PALM_PRIORITY); | |
| 266 | 271 | // lock hand to forearm by slamming its rotation (in parent-frame) to identity |
| 267 | − _jointStates[jointIndex].setRotationInConstrainedFrame(glm::quat(), PALM_PRIORITY); | |
| 272 | + _rig->setJointRotationInConstrainedFrame(jointIndex, glm::quat(), PALM_PRIORITY); | |
| 268 | 273 | } else { |
| 269 | 274 | inverseKinematics(jointIndex, palmPosition, palmRotation, PALM_PRIORITY); |
| 270 | 275 | } |
| 271 | 276 | } |
| 272 | 277 | |
| 273 | 278 | void SkeletonModel::updateJointState(int index) { |
| 274 | − if (index < 0 && index >= _jointStates.size()) { | |
| 275 | − return; // bail | |
| 276 | − } | |
| 277 | − JointState& state = _jointStates[index]; | |
| 278 | − const FBXJoint& joint = state.getFBXJoint(); | |
| 279 | − if (joint.parentIndex >= 0 && joint.parentIndex < _jointStates.size()) { | |
| 280 | − const JointState& parentState = _jointStates.at(joint.parentIndex); | |
| 281 | − const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 279 | + const FBXGeometry& geometry = _geometry->getFBXGeometry(); | |
| 280 | + glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset; | |
| 281 | + | |
| 282 | + const JointState joint = _rig->getJointState(index); | |
| 283 | + if (joint.getParentIndex() >= 0 && joint.getParentIndex() < _rig->getJointStateCount()) { | |
| 284 | + const JointState parentState = _rig->getJointState(joint.getParentIndex()); | |
| 282 | 285 | if (index == geometry.leanJointIndex) { |
| 283 | − maybeUpdateLeanRotation(parentState, state); | |
| 284 | − | |
| 286 | + maybeUpdateLeanRotation(parentState, index); | |
| 287 | + | |
| 285 | 288 | } else if (index == geometry.neckJointIndex) { |
| 286 | − maybeUpdateNeckRotation(parentState, joint, state); | |
| 287 | − | |
| 289 | + maybeUpdateNeckRotation(parentState, joint.getFBXJoint(), index); | |
| 290 | + | |
| 288 | 291 | } else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) { |
| 289 | − maybeUpdateEyeRotation(parentState, joint, state); | |
| 292 | + maybeUpdateEyeRotation(parentState, joint.getFBXJoint(), index); | |
| 290 | 293 | } |
| 291 | 294 | } |
| 292 | 295 | |
| 293 | − Model::updateJointState(index); | |
| 296 | + _rig->updateJointState(index, parentTransform); | |
| 294 | 297 | |
| 295 | 298 | if (index == _geometry->getFBXGeometry().rootJointIndex) { |
| 296 | − state.clearTransformTranslation(); | |
| 299 | + _rig->clearJointTransformTranslation(index); | |
| 297 | 300 | } |
| 298 | 301 | } |
| 299 | 302 | |
| 300 | −void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, JointState& state) { | |
| 303 | +void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, int index) { | |
| 301 | 304 | if (!_owningAvatar->isMyAvatar()) { |
| 302 | 305 | return; |
| 303 | 306 | } |
| @@ -305,24 +308,24 @@ void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, Joint · 1 unmodified line | ||
| 305 | 308 | glm::vec3 xAxis(1.0f, 0.0f, 0.0f); |
| 306 | 309 | glm::vec3 yAxis(0.0f, 1.0f, 0.0f); |
| 307 | 310 | glm::vec3 zAxis(0.0f, 0.0f, 1.0f); |
| 308 | − glm::quat inverse = glm::inverse(parentState.getRotation() * state.getDefaultRotationInParentFrame()); | |
| 309 | − state.setRotationInConstrainedFrame( | |
| 310 | − glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), inverse * zAxis) | |
| 311 | − * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(), inverse * xAxis) | |
| 312 | − * glm::angleAxis(RADIANS_PER_DEGREE * _owningAvatar->getHead()->getTorsoTwist(), inverse * yAxis) | |
| 313 | − * state.getFBXJoint().rotation, LEAN_PRIORITY); | |
| 311 | + glm::quat inverse = glm::inverse(parentState.getRotation() * _rig->getJointDefaultRotationInParentFrame(index)); | |
| 312 | + _rig->setJointRotationInConstrainedFrame(index, | |
| 313 | + glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), inverse * zAxis) | |
| 314 | + * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(), inverse * xAxis) | |
| 315 | + * glm::angleAxis(RADIANS_PER_DEGREE * _owningAvatar->getHead()->getTorsoTwist(), inverse * yAxis) | |
| 316 | + * _rig->getJointState(index).getFBXJoint().rotation, LEAN_PRIORITY); | |
| 314 | 317 | } |
| 315 | 318 | |
| 316 | −void SkeletonModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { | |
| 317 | − _owningAvatar->getHead()->getFaceModel().maybeUpdateNeckRotation(parentState, joint, state); | |
| 319 | +void SkeletonModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, int index) { | |
| 320 | + _owningAvatar->getHead()->getFaceModel().maybeUpdateNeckRotation(parentState, joint, index); | |
| 318 | 321 | } |
| 319 | 322 | |
| 320 | −void SkeletonModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { | |
| 321 | − _owningAvatar->getHead()->getFaceModel().maybeUpdateEyeRotation(this, parentState, joint, state); | |
| 323 | +void SkeletonModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, int index) { | |
| 324 | + _owningAvatar->getHead()->getFaceModel().maybeUpdateEyeRotation(this, parentState, joint, index); | |
| 322 | 325 | } |
| 323 | 326 | |
| 324 | 327 | void SkeletonModel::renderJointConstraints(gpu::Batch& batch, int jointIndex) { |
| 325 | − if (jointIndex == -1 || jointIndex >= _jointStates.size()) { | |
| 328 | + if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) { | |
| 326 | 329 | return; |
| 327 | 330 | } |
| 328 | 331 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| @@ -331,9 +334,11 @@ void SkeletonModel::renderJointConstraints(gpu::Batch& batch, int jointIndex) { · 2 unmodified lines | ||
| 331 | 334 | batch._glLineWidth(3.0f); |
| 332 | 335 | do { |
| 333 | 336 | const FBXJoint& joint = geometry.joints.at(jointIndex); |
| 334 | − const JointState& jointState = _jointStates.at(jointIndex); | |
| 337 | + const JointState& jointState = _rig->getJointState(jointIndex); | |
| 335 | 338 | glm::vec3 position = _rotation * jointState.getPosition() + _translation; |
| 336 | − glm::quat parentRotation = (joint.parentIndex == -1) ? _rotation : _rotation * _jointStates.at(joint.parentIndex).getRotation(); | |
| 339 | + glm::quat parentRotation = (joint.parentIndex == -1) ? | |
| 340 | + _rotation : | |
| 341 | + _rotation * _rig->getJointState(joint.parentIndex).getRotation(); | |
| 337 | 342 | float fanScale = directionSize * 0.75f; |
| 338 | 343 | |
| 339 | 344 | Transform transform = Transform(); |
| @@ -464,14 +469,11 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c · 124 unmodified lines | ||
| 464 | 469 | glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); |
| 465 | 470 | glm::quat shoulderRotation = rotationBetween(forwardVector, elbowPosition - shoulderPosition); |
| 466 | 471 | |
| 467 | − JointState& shoulderState = _jointStates[shoulderJointIndex]; | |
| 468 | − shoulderState.setRotationInBindFrame(shoulderRotation, PALM_PRIORITY); | |
| 469 | − | |
| 470 | − JointState& elbowState = _jointStates[elbowJointIndex]; | |
| 471 | − elbowState.setRotationInBindFrame(rotationBetween(shoulderRotation * forwardVector, wristPosition - elbowPosition) * shoulderRotation, PALM_PRIORITY); | |
| 472 | − | |
| 473 | − JointState& handState = _jointStates[jointIndex]; | |
| 474 | − handState.setRotationInBindFrame(rotation, PALM_PRIORITY); | |
| 472 | + _rig->setJointRotationInBindFrame(shoulderJointIndex, shoulderRotation, PALM_PRIORITY); | |
| 473 | + _rig->setJointRotationInBindFrame(elbowJointIndex, | |
| 474 | + rotationBetween(shoulderRotation * forwardVector, wristPosition - elbowPosition) * | |
| 475 | + shoulderRotation, PALM_PRIORITY); | |
| 476 | + _rig->setJointRotationInBindFrame(jointIndex, rotation, PALM_PRIORITY); | |
| 475 | 477 | } |
| 476 | 478 | |
| 477 | 479 | bool SkeletonModel::getLeftHandPosition(glm::vec3& position) const { |
| @@ -526,7 +528,7 @@ bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckP · 48 unmodified lines | ||
| 526 | 528 | glm::quat worldFrameRotation; |
| 527 | 529 | bool success = getJointRotationInWorldFrame(parentIndex, worldFrameRotation); |
| 528 | 530 | if (success) { |
| 529 | − neckParentRotation = worldFrameRotation * _jointStates[parentIndex].getFBXJoint().inverseDefaultRotation; | |
| 531 | + neckParentRotation = worldFrameRotation * _rig->getJointState(parentIndex).getFBXJoint().inverseDefaultRotation; | |
| 530 | 532 | } |
| 531 | 533 | return success; |
| 532 | 534 | } |
| @@ -636,7 +638,7 @@ float VERY_BIG_MASS = 1.0e6f; · 103 unmodified lines | ||
| 636 | 638 | |
| 637 | 639 | // virtual |
| 638 | 640 | void SkeletonModel::buildShapes() { |
| 639 | − if (_geometry == NULL || _jointStates.isEmpty()) { | |
| 641 | + if (_geometry == NULL || _rig->jointStatesEmpty()) { | |
| 640 | 642 | return; |
| 641 | 643 | } |
| 642 | 644 | |
| @@ -647,9 +649,8 @@ void SkeletonModel::buildShapes() { · 4 unmodified lines | ||
| 647 | 649 | } |
| 648 | 650 | |
| 649 | 651 | float uniformScale = extractUniformScale(_scale); |
| 650 | − const int numStates = _jointStates.size(); | |
| 651 | − for (int i = 0; i < numStates; i++) { | |
| 652 | − JointState& state = _jointStates[i]; | |
| 652 | + for (int i = 0; i < _rig->getJointStateCount(); i++) { | |
| 653 | + const JointState& state = _rig->getJointState(i); | |
| 653 | 654 | const FBXJoint& joint = state.getFBXJoint(); |
| 654 | 655 | float radius = uniformScale * joint.boneRadius; |
| 655 | 656 | float halfHeight = 0.5f * uniformScale * joint.distanceToParent; |
| @@ -683,7 +684,7 @@ void SkeletonModel::buildShapes() { · 27 unmodified lines | ||
| 683 | 684 | |
| 684 | 685 | void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { |
| 685 | 686 | // compute default joint transforms |
| 686 | − int numStates = _jointStates.size(); | |
| 687 | + int numStates = _rig->getJointStateCount(); | |
| 687 | 688 | assert(numStates == _shapes.size()); |
| 688 | 689 | QVector<glm::mat4> transforms; |
| 689 | 690 | transforms.fill(glm::mat4(), numStates); |
| @@ -694,11 +695,11 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { · 4 unmodified lines | ||
| 694 | 695 | totalExtents.addPoint(glm::vec3(0.0f)); |
| 695 | 696 | for (int i = 0; i < numStates; i++) { |
| 696 | 697 | // compute the default transform of this joint |
| 697 | − JointState& state = _jointStates[i]; | |
| 698 | + const JointState& state = _rig->getJointState(i); | |
| 698 | 699 | const FBXJoint& joint = state.getFBXJoint(); |
| 699 | 700 | int parentIndex = joint.parentIndex; |
| 700 | 701 | if (parentIndex == -1) { |
| 701 | − transforms[i] = _jointStates[i].getTransform(); | |
| 702 | + transforms[i] = _rig->getJointTransform(i); | |
| 702 | 703 | } else { |
| 703 | 704 | glm::quat modifiedRotation = joint.preRotation * joint.rotation * joint.postRotation; |
| 704 | 705 | transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) |
| @@ -748,7 +749,7 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { · 43 unmodified lines | ||
| 748 | 749 | _boundingShape.setRadius(capsuleRadius); |
| 749 | 750 | _boundingShape.setHalfHeight(0.5f * diagonal.y - capsuleRadius); |
| 750 | 751 | |
| 751 | − glm::vec3 rootPosition = _jointStates[geometry.rootJointIndex].getPosition(); | |
| 752 | + glm::vec3 rootPosition = _rig->getJointState(geometry.rootJointIndex).getPosition(); | |
| 752 | 753 | _boundingShapeLocalOffset = 0.5f * (totalExtents.maximum + totalExtents.minimum) - rootPosition; |
| 753 | 754 | _boundingRadius = 0.5f * glm::length(diagonal); |
| 754 | 755 | } |
| @@ -853,7 +854,7 @@ void SkeletonModel::cauterizeHead() { · 98 unmodified lines | ||
| 853 | 854 | if (isActive()) { |
| 854 | 855 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| 855 | 856 | const int neckJointIndex = geometry.neckJointIndex; |
| 856 | − if (neckJointIndex > 0 && neckJointIndex < _jointStates.size()) { | |
| 857 | + if (neckJointIndex > 0 && neckJointIndex < _rig->getJointStateCount()) { | |
| 857 | 858 | |
| 858 | 859 | // lazy init of headBones |
| 859 | 860 | if (_headBones.size() == 0) { |
| @@ -861,13 +862,13 @@ void SkeletonModel::cauterizeHead() { · 1 unmodified line | ||
| 861 | 862 | } |
| 862 | 863 | |
| 863 | 864 | // preserve the translation for the neck |
| 864 | − glm::vec4 trans = _jointStates[neckJointIndex].getTransform()[3]; | |
| 865 | + // glm::vec4 trans = _jointStates[neckJointIndex].getTransform()[3]; | |
| 866 | + glm::vec4 trans = _rig->getJointTransform(neckJointIndex)[3]; | |
| 865 | 867 | glm::vec4 zero(0, 0, 0, 0); |
| 866 | 868 | for (const int &i : _headBones) { |
| 867 | − JointState& joint = _jointStates[i]; | |
| 868 | 869 | glm::mat4 newXform(zero, zero, zero, trans); |
| 869 | − joint.setTransform(newXform); | |
| 870 | − joint.setVisibleTransform(newXform); | |
| 870 | + _rig->setJointTransform(i, newXform); | |
| 871 | + _rig->setJointVisibleTransform(i, newXform); | |
| 871 | 872 | } |
| 872 | 873 | } |
| 873 | 874 | } |