diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index fe4d4bc3cb..f29c21f114 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -900,10 +900,37 @@ glm::vec3 MyAvatar::getDefaultEyePosition() const { const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f; const float RECORDER_PRIORITY = SCRIPT_PRIORITY + 1.0f; +void MyAvatar::setJointRotations(QVector jointRotations) { + int numStates = glm::min(_skeletonModel.getJointStateCount(), jointRotations.size()); + for (int i = 0; i < numStates; ++i) { + // HACK: ATM only Recorder calls setJointRotations() so we hardcode its priority here + _skeletonModel.setJointState(i, true, jointRotations[i], RECORDER_PRIORITY); + } +} + +void MyAvatar::setJointData(int index, const glm::quat& rotation) { + if (QThread::currentThread() == thread()) { + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _rig->setJointState(index, true, rotation, SCRIPT_PRIORITY); + } +} + +void MyAvatar::clearJointData(int index) { + if (QThread::currentThread() == thread()) { + // HACK: ATM only JS scripts call clearJointData() on MyAvatar so we hardcode the priority + _rig->setJointState(index, false, glm::quat(), 0.0f); + _rig->clearJointAnimationPriority(index); + } +} + +void MyAvatar::clearJointsData() { + clearJointAnimationPriorities(); +} + void MyAvatar::clearJointAnimationPriorities() { int numStates = _skeletonModel.getJointStateCount(); for (int i = 0; i < numStates; ++i) { - _skeletonModel.clearJointAnimationPriority(i); + _rig->clearJointAnimationPriority(i); } } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index e83deddf16..4dfe0611af 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -104,6 +104,11 @@ public: void updateLookAtTargetAvatar(); void clearLookAtTargetAvatar(); + virtual void setJointRotations(QVector jointRotations); + virtual void setJointData(int index, const glm::quat& rotation); + virtual void clearJointData(int index); + virtual void clearJointsData(); + Q_INVOKABLE void useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelName = QString()); Q_INVOKABLE void useHeadURL(const QUrl& headURL, const QString& modelName = QString()); Q_INVOKABLE void useBodyURL(const QUrl& bodyURL, const QString& modelName = QString()); diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 14dc2da3f0..5d76ac1149 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -22,68 +22,68 @@ class MuscleConstraint; /// A skeleton loaded from a model. class SkeletonModel : public Model { Q_OBJECT - + public: SkeletonModel(Avatar* owningAvatar, QObject* parent = nullptr, RigPointer rig = nullptr); ~SkeletonModel(); - + virtual void initJointStates(QVector states); void simulate(float deltaTime, bool fullUpdate = true); 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; } - + /// Returns the index of the right hand joint, or -1 if not found. int getRightHandJointIndex() const { return isActive() ? _geometry->getFBXGeometry().rightHandJointIndex : -1; } /// Retrieve the position of the left hand /// \return true whether or not the position was found bool getLeftHandPosition(glm::vec3& position) const; - + /// Retrieve the position of the right hand /// \return true whether or not the position was found bool getRightHandPosition(glm::vec3& position) const; - + /// Restores some fraction of the default position of the left hand. /// \param fraction the fraction of the default position to restore /// \return whether or not the left hand joint was found bool restoreLeftHandPosition(float fraction = 1.0f, float priority = 1.0f); - + /// Gets the position of the left shoulder. /// \return whether or not the left shoulder joint was found bool getLeftShoulderPosition(glm::vec3& position) const; - + /// Returns the extended length from the left hand to its last free ancestor. float getLeftArmLength() const; - + /// Restores some fraction of the default position of the right hand. /// \param fraction the fraction of the default position to restore /// \return whether or not the right hand joint was found bool restoreRightHandPosition(float fraction = 1.0f, float priority = 1.0f); - + /// Gets the position of the right shoulder. /// \return whether or not the right shoulder joint was found bool getRightShoulderPosition(glm::vec3& position) const; - + /// Returns the extended length from the right hand to its first free ancestor. float getRightArmLength() const; /// Returns the position of the head joint. /// \return whether or not the head was found bool getHeadPosition(glm::vec3& headPosition) const; - + /// Returns the position of the neck joint. /// \return whether or not the neck was found bool getNeckPosition(glm::vec3& neckPosition) const; - + /// 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 bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; @@ -119,12 +119,12 @@ protected: /// \param jointIndex index of joint in model /// \param position position of joint in model-frame void applyHandPosition(int jointIndex, const glm::vec3& position); - + void applyPalmData(int jointIndex, PalmData& palm); - + /// Updates the state of the joint at the specified index. - virtual void updateJointState(int index); - + virtual void updateJointState(int index); + void maybeUpdateLeanRotation(const JointState& parentState, int index); void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, int index); void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, int index); @@ -137,9 +137,9 @@ protected: private: void renderJointConstraints(gpu::Batch& batch, int jointIndex); - void renderOrientationDirections(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; @@ -154,7 +154,7 @@ private: void setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation); bool getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; - + Avatar* _owningAvatar; CapsuleShape _boundingShape; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index a316da0f99..1f7b67ef05 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1052,10 +1052,6 @@ void Model::clearJointState(int index) { _rig->clearJointState(index); } -void Model::clearJointAnimationPriority(int index) { - _rig->clearJointAnimationPriority(index); -} - void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) { _rig->setJointState(index, valid, rotation, priority); } diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 45d7ce63ab..fc8347581b 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -150,10 +149,6 @@ public: /// Sets the distance parameter used for LOD computations. void setLODDistance(float distance) { _lodDistance = distance; } - const QList& getRunningAnimations() const { return _rig->getRunningAnimations(); } - /// Clear the joint animation priority - void clearJointAnimationPriority(int index); - void setScaleToFit(bool scaleToFit, float largestDimension = 0.0f, bool forceRescale = false); bool getScaleToFit() const { return _scaleToFit; } /// is scale to fit enabled