From a4116e633a4b85db56f7e9469c21074b79dc312a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Fri, 20 Nov 2015 11:26:54 -0800 Subject: [PATCH] Removed last consumer of JointState class Removed option to render IK constraints used by old animation system --- interface/src/Menu.cpp | 1 - interface/src/Menu.h | 1 - interface/src/avatar/FaceModel.cpp | 5 +- interface/src/avatar/MyAvatar.cpp | 6 +- interface/src/avatar/SkeletonModel.cpp | 101 +------------------------ interface/src/avatar/SkeletonModel.h | 20 ++--- libraries/animation/src/Rig.cpp | 10 ++- libraries/animation/src/Rig.h | 3 + 8 files changed, 26 insertions(+), 121 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index a6db205fe1..c56b430622 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -458,7 +458,6 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::EnableHandMouseInput, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::LowVelocityFilter, 0, true, qApp, SLOT(setLowVelocityFilter(bool))); - addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false); MenuWrapper* leapOptionsMenu = handOptionsMenu->addMenu("Leap Motion"); addCheckableActionToQMenuAndActionHash(leapOptionsMenu, MenuOption::LeapMotionOnHMD, 0, false); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 7546ed59f2..4efb7e7749 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -271,7 +271,6 @@ namespace MenuOption { const QString ScriptedMotorControl = "Enable Scripted Motor Control"; const QString ShowDSConnectTable = "Show Domain Connection Timing"; const QString ShowBordersEntityNodes = "Show Entity Nodes"; - const QString ShowIKConstraints = "Show IK Constraints"; const QString ShowRealtimeEntityStats = "Show Realtime Entity Stats"; const QString ShowWhosLookingAtMe = "Show Who's Looking at Me"; const QString StandingHMDSensorMode = "Standing HMD Sensor Mode"; diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 0e8e5a6a91..9c22fc17ac 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -32,10 +32,7 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) { neckPosition = owningAvatar->getPosition(); } setTranslation(neckPosition); - glm::quat neckParentRotation; - if (!owningAvatar->getSkeletonModel().getNeckParentRotationFromDefaultOrientation(neckParentRotation)) { - neckParentRotation = owningAvatar->getOrientation(); - } + glm::quat neckParentRotation = owningAvatar->getOrientation(); setRotation(neckParentRotation); setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningHead->getScale()); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 3680d32797..fb72adafa1 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -268,7 +268,6 @@ void MyAvatar::simulate(float deltaTime) { { PerformanceTimer perfTimer("joints"); // copy out the skeleton joints from the model - _jointData.resize(_rig->getJointStateCount()); _rig->copyJointsIntoJointData(_jointData); } @@ -507,11 +506,14 @@ void MyAvatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { Avatar::render(renderArgs, cameraPosition); + // AJT: REMOVE + /* // don't display IK constraints in shadow mode if (Menu::getInstance()->isOptionChecked(MenuOption::ShowIKConstraints) && renderArgs && renderArgs->_batch) { _skeletonModel.renderIKConstraints(*renderArgs->_batch); } + */ } void MyAvatar::clearReferential() { @@ -1285,7 +1287,7 @@ void MyAvatar::preRender(RenderArgs* renderArgs) { auto rig = _skeletonModel.getRig(); - // build AnimPoseVec from JointStates. + // build absolute AnimPoseVec from rig AnimPoseVec absPoses; absPoses.reserve(_debugDrawSkeleton->getNumJoints()); for (int i = 0; i < _rig->getJointStateCount(); i++) { diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 570bc0589a..8ee4e83ac4 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -26,7 +26,6 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) : Model(rig, parent), - _triangleFanID(DependencyManager::get()->allocateID()), _owningAvatar(owningAvatar), _boundingCapsuleLocalOffset(0.0f), _boundingCapsuleRadius(0.0f), @@ -254,11 +253,6 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { } } -void SkeletonModel::renderIKConstraints(gpu::Batch& batch) { - renderJointConstraints(batch, getRightHandJointIndex()); - renderJointConstraints(batch, getLeftHandJointIndex()); -} - class IndexValue { public: int index; @@ -285,98 +279,6 @@ void SkeletonModel::applyPalmData(int jointIndex, const PalmData& palm) { glm::quat palmRotation = inverseRotation * palm.getRotation(); } -void SkeletonModel::renderJointConstraints(gpu::Batch& batch, int jointIndex) { - if (jointIndex == -1 || jointIndex >= _rig->getJointStateCount()) { - return; - } - const FBXGeometry& geometry = _geometry->getFBXGeometry(); - const float BASE_DIRECTION_SIZE = 0.3f; - float directionSize = BASE_DIRECTION_SIZE * extractUniformScale(_scale); - // FIXME: THe line width of 3.0f is not supported anymore, we ll need a workaround - - do { - const FBXJoint& joint = geometry.joints.at(jointIndex); - const JointState& jointState = _rig->getJointState(jointIndex); - glm::vec3 position = _rotation * jointState.getPosition() + _translation; - glm::quat parentRotation = (joint.parentIndex == -1) ? - _rotation : - _rotation * _rig->getJointState(joint.parentIndex).getRotation(); - float fanScale = directionSize * 0.75f; - - Transform transform = Transform(); - transform.setTranslation(position); - transform.setRotation(parentRotation); - transform.setScale(fanScale); - batch.setModelTransform(transform); - - const int AXIS_COUNT = 3; - - auto geometryCache = DependencyManager::get(); - - for (int i = 0; i < AXIS_COUNT; i++) { - if (joint.rotationMin[i] <= -PI + EPSILON && joint.rotationMax[i] >= PI - EPSILON) { - continue; // unconstrained - } - glm::vec3 axis; - axis[i] = 1.0f; - - glm::vec3 otherAxis; - if (i == 0) { - otherAxis.y = 1.0f; - } else { - otherAxis.x = 1.0f; - } - glm::vec4 color(otherAxis.r, otherAxis.g, otherAxis.b, 0.75f); - - QVector points; - points << glm::vec3(0.0f, 0.0f, 0.0f); - const int FAN_SEGMENTS = 16; - for (int j = 0; j < FAN_SEGMENTS; j++) { - glm::vec3 rotated = glm::angleAxis(glm::mix(joint.rotationMin[i], joint.rotationMax[i], - (float)j / (FAN_SEGMENTS - 1)), axis) * otherAxis; - points << rotated; - } - // TODO: this is really inefficient constantly recreating these vertices buffers. It would be - // better if the skeleton model cached these buffers for each of the joints they are rendering - geometryCache->updateVertices(_triangleFanID, points, color); - geometryCache->renderVertices(batch, gpu::TRIANGLE_FAN, _triangleFanID); - - } - - renderOrientationDirections(batch, jointIndex, position, _rotation * jointState.getRotation(), directionSize); - jointIndex = joint.parentIndex; - - } while (jointIndex != -1 && geometry.joints.at(jointIndex).isFree); -} - -void SkeletonModel::renderOrientationDirections(gpu::Batch& batch, int jointIndex, - glm::vec3 position, const glm::quat& orientation, float size) { - - auto geometryCache = DependencyManager::get(); - - if (!_jointOrientationLines.contains(jointIndex)) { - OrientationLineIDs jointLineIDs; - jointLineIDs._up = geometryCache->allocateID(); - jointLineIDs._front = geometryCache->allocateID(); - jointLineIDs._right = geometryCache->allocateID(); - _jointOrientationLines[jointIndex] = jointLineIDs; - } - OrientationLineIDs& jointLineIDs = _jointOrientationLines[jointIndex]; - - glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; - glm::vec3 pUp = position + orientation * IDENTITY_UP * size; - glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; - - glm::vec3 red(1.0f, 0.0f, 0.0f); - geometryCache->renderLine(batch, position, pRight, red, jointLineIDs._right); - - glm::vec3 green(0.0f, 1.0f, 0.0f); - geometryCache->renderLine(batch, position, pUp, green, jointLineIDs._up); - - glm::vec3 blue(0.0f, 0.0f, 1.0f); - geometryCache->renderLine(batch, position, pFront, blue, jointLineIDs._front); -} - bool SkeletonModel::getLeftHandPosition(glm::vec3& position) const { return getJointPositionInWorldFrame(getLeftHandJointIndex(), position); } @@ -421,6 +323,8 @@ bool SkeletonModel::getLocalNeckPosition(glm::vec3& neckPosition) const { return isActive() && getJointPosition(_geometry->getFBXGeometry().neckJointIndex, neckPosition); } +// AJT: REMOVE +/* bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckParentRotation) const { if (!isActive()) { return false; @@ -437,6 +341,7 @@ bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckP } return success; } +*/ bool SkeletonModel::getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const { if (!isActive()) { diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 9f57d403a9..fbbe72f61a 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -33,7 +33,10 @@ public: virtual void updateRig(float deltaTime, glm::mat4 parentTransform) override; void updateAttitude(); + // AJT: REMOVE + /* void renderIKConstraints(gpu::Batch& batch); + */ /// Returns the index of the left hand joint, or -1 if not found. int getLeftHandJointIndex() const { return isActive() ? _geometry->getFBXGeometry().leftHandJointIndex : -1; } @@ -82,10 +85,13 @@ public: bool getNeckPosition(glm::vec3& neckPosition) const; bool getLocalNeckPosition(glm::vec3& neckPosition) const; - + + // AJT: REMOVE + /* /// Returns the rotation of the neck joint's parent from default orientation /// \return whether or not the neck was found bool getNeckParentRotationFromDefaultOrientation(glm::quat& neckParentRotation) const; + */ /// Retrieve the positions of up to two eye meshes. /// \return whether or not both eye meshes were found @@ -117,18 +123,6 @@ protected: void applyPalmData(int jointIndex, const PalmData& palm); private: - void renderJointConstraints(gpu::Batch& batch, int jointIndex); - void renderOrientationDirections(gpu::Batch& batch, int jointIndex, - glm::vec3 position, const glm::quat& orientation, float size); - - struct OrientationLineIDs { - int _up; - int _front; - int _right; - }; - QHash _jointOrientationLines; - int _triangleFanID; - bool getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; Avatar* _owningAvatar; diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 4f344ae4ea..f9f3f8086f 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -299,12 +299,15 @@ void Rig::reset(const QVector& fbxJoints) { } } +// AJT: REMOVE +/* JointState Rig::getJointState(int jointIndex) const { if (jointIndex == -1 || jointIndex >= _jointStates.size()) { return JointState(); } return _jointStates[jointIndex]; } +*/ bool Rig::getJointStateRotation(int index, glm::quat& rotation) const { if (AJT_HACK_USE_JOINT_STATES) { // AJT: LEGACY @@ -453,7 +456,7 @@ bool Rig::getJointRotation(int jointIndex, glm::quat& rotation) const { rotation = _jointStates[jointIndex].getRotation(); } - if (jointIndex >= 0 && jointIndex < _relativePoses.size()) { + if (jointIndex >= 0 && jointIndex < (int)_relativePoses.size()) { rotation = _relativePoses[jointIndex].rot; return true; } else { @@ -470,7 +473,7 @@ bool Rig::getJointTranslation(int jointIndex, glm::vec3& translation) const { translation = _jointStates[jointIndex].getTranslation(); } - if (jointIndex >= 0 && jointIndex < _relativePoses.size()) { + if (jointIndex >= 0 && jointIndex < (int)_relativePoses.size()) { translation = _relativePoses[jointIndex].trans; return true; } else { @@ -1020,12 +1023,14 @@ void Rig::clearJointStatePriorities() { } } +/* void Rig::applyJointRotationDelta(int jointIndex, const glm::quat& delta, float priority) { if (jointIndex == -1 || _jointStates.isEmpty()) { return; } _jointStates[jointIndex].applyRotationDelta(delta, priority); } +*/ glm::quat Rig::getJointDefaultRotationInParentFrame(int jointIndex) { if (jointIndex == -1 || _jointStates.isEmpty()) { @@ -1400,6 +1405,7 @@ glm::mat4 Rig::getJointTransform(int jointIndex) const { } void Rig::copyJointsIntoJointData(QVector& jointDataVec) const { + jointDataVec.resize(getJointStateCount()); for (int i = 0; i < jointDataVec.size(); i++) { JointData& data = jointDataVec[i]; data.rotationSet |= getJointStateRotation(i, data.rotation); diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index 61e32d625e..dd1a5ec366 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -102,8 +102,11 @@ public: void reset(const QVector& fbxJoints); bool getJointStateRotation(int index, glm::quat& rotation) const; bool getJointStateTranslation(int index, glm::vec3& translation) const; + // AJT: REMOVE + /* void applyJointRotationDelta(int jointIndex, const glm::quat& delta, float priority); JointState getJointState(int jointIndex) const; // XXX + */ void clearJointState(int index); void clearJointStates(); void clearJointAnimationPriority(int index);