From 11fee94459498e7d1203e51f0747d04d1ba40717 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 22 Sep 2015 17:19:47 -0700 Subject: [PATCH 1/3] remove warning about signed/unsigned comparison --- libraries/render-utils/src/Model.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index a55e83b9ec..08c42d90a7 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -193,7 +193,7 @@ public: int getBlendshapeCoefficientsNum() const { return _blendshapeCoefficients.size(); } float getBlendshapeCoefficient(unsigned int index) const { - return index >= _blendshapeCoefficients.size() ? 0.0f : _blendshapeCoefficients.at(index); + return index >= (unsigned int)_blendshapeCoefficients.size() ? 0.0f : _blendshapeCoefficients.at(index); } protected: From 2edffaf91a2414bf781d18bf96e24a74ffadc367 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 22 Sep 2015 17:20:13 -0700 Subject: [PATCH 2/3] remove unused variables --- interface/src/avatar/SkeletonModel.cpp | 2 -- libraries/render-utils/src/Model.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 6b56e92d80..f88508ba5b 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -635,8 +635,6 @@ void SkeletonModel::computeBoundingShape() { } void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha) { - const int BALL_SUBDIVISIONS = 10; - auto geometryCache = DependencyManager::get(); auto deferredLighting = DependencyManager::get(); // draw a blue sphere at the capsule top point diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 7cf965951b..ff27c3ab62 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1727,9 +1727,7 @@ void Model::segregateMeshGroups() { // Run through all of the meshes, and place them into their segregated, but unsorted buckets int shapeID = 0; for (int i = 0; i < (int)networkMeshes.size(); i++) { - const NetworkMesh& networkMesh = *(networkMeshes.at(i).get()); const FBXMesh& mesh = geometry.meshes.at(i); - const MeshState& state = _meshStates.at(i); // Create the render payloads int totalParts = mesh.parts.size(); From d25ba8946e31b3cf8d22183196a6df335535db8c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 22 Sep 2015 17:20:26 -0700 Subject: [PATCH 3/3] fix animation attenuation from IK relaxation step --- .../animation/src/AnimInverseKinematics.cpp | 37 +++++++------------ .../animation/src/AnimInverseKinematics.h | 4 +- .../animation/src/RotationAccumulator.cpp | 10 ++++- libraries/animation/src/RotationAccumulator.h | 12 +++++- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index 57459abacb..e31f7795f3 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -33,8 +33,10 @@ void AnimInverseKinematics::loadPoses(const AnimPoseVec& poses) { assert(_skeleton && ((poses.size() == 0) || (_skeleton->getNumJoints() == (int)poses.size()))); if (_skeleton->getNumJoints() == (int)poses.size()) { _relativePoses = poses; + _accumulators.resize(_relativePoses.size()); } else { _relativePoses.clear(); + _accumulators.clear(); } } @@ -133,8 +135,8 @@ void AnimInverseKinematics::solveWithCyclicCoordinateDescent(std::vector 0) { - _relativePoses[accumulatorPair.first].rot = accumulator.getAverage(); - accumulator.clear(); + const int numJoints = (int)_accumulators.size(); + for (int i = 0; i < numJoints; ++i) { + if (_accumulators[i].size() > 0) { + _relativePoses[i].rot = _accumulators[i].getAverage(); + _accumulators[i].clear(); } } @@ -299,7 +301,11 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars int numJoints = (int)_relativePoses.size(); for (int i = 0; i < numJoints; ++i) { float dotSign = copysignf(1.0f, glm::dot(_relativePoses[i].rot, underPoses[i].rot)); - _relativePoses[i].rot = glm::normalize(glm::lerp(_relativePoses[i].rot, dotSign * underPoses[i].rot, blend)); + if (_accumulators[i].isDirty()) { + _relativePoses[i].rot = glm::normalize(glm::lerp(_relativePoses[i].rot, dotSign * underPoses[i].rot, blend)); + } else { + _relativePoses[i].rot = underPoses[i].rot; + } } } return evaluate(animVars, dt, triggersOut); @@ -642,18 +648,3 @@ void AnimInverseKinematics::setSkeletonInternal(AnimSkeleton::ConstPointer skele clearConstraints(); } } - -void AnimInverseKinematics::relaxTowardDefaults(float dt) { - // NOTE: for now we just use a single relaxation timescale for all joints, but in the future - // we could vary the timescale on a per-joint basis or do other fancy things. - - // for each joint: lerp towards the default pose - const float RELAXATION_TIMESCALE = 0.25f; - const float alpha = glm::clamp(dt / RELAXATION_TIMESCALE, 0.0f, 1.0f); - int numJoints = (int)_relativePoses.size(); - for (int i = 0; i < numJoints; ++i) { - float dotSign = copysignf(1.0f, glm::dot(_relativePoses[i].rot, _defaultRelativePoses[i].rot)); - _relativePoses[i].rot = glm::normalize(glm::lerp(_relativePoses[i].rot, dotSign * _defaultRelativePoses[i].rot, alpha)); - } -} - diff --git a/libraries/animation/src/AnimInverseKinematics.h b/libraries/animation/src/AnimInverseKinematics.h index f2073c01b8..70808f5919 100644 --- a/libraries/animation/src/AnimInverseKinematics.h +++ b/libraries/animation/src/AnimInverseKinematics.h @@ -50,8 +50,6 @@ protected: // for AnimDebugDraw rendering virtual const AnimPoseVec& getPosesInternal() const override { return _relativePoses; } - void relaxTowardDefaults(float dt); - RotationConstraint* getConstraint(int index); void clearConstraints(); void initConstraints(); @@ -72,7 +70,7 @@ protected: }; std::map _constraints; - std::map _accumulators; // class-member to exploit temporal coherency + std::vector _accumulators; std::vector _targetVarVec; AnimPoseVec _defaultRelativePoses; // poses of the relaxed state AnimPoseVec _relativePoses; // current relative poses diff --git a/libraries/animation/src/RotationAccumulator.cpp b/libraries/animation/src/RotationAccumulator.cpp index 58ce4b9f36..26bdfd8517 100644 --- a/libraries/animation/src/RotationAccumulator.cpp +++ b/libraries/animation/src/RotationAccumulator.cpp @@ -11,17 +11,23 @@ #include -void RotationAccumulator::add(glm::quat rotation) { +void RotationAccumulator::add(const glm::quat& rotation) { // make sure both quaternions are on the same hyper-hemisphere before we add them linearly (lerp) _rotationSum += copysignf(1.0f, glm::dot(_rotationSum, rotation)) * rotation; ++_numRotations; + _isDirty = true; } glm::quat RotationAccumulator::getAverage() { return (_numRotations > 0) ? glm::normalize(_rotationSum) : glm::quat(); } -void RotationAccumulator::clear() { +void RotationAccumulator::clear() { _rotationSum *= 0.0f; _numRotations = 0; } + +void RotationAccumulator::clearAndClean() { + clear(); + _isDirty = false; +} diff --git a/libraries/animation/src/RotationAccumulator.h b/libraries/animation/src/RotationAccumulator.h index 634a3d0eac..87b1a753c9 100644 --- a/libraries/animation/src/RotationAccumulator.h +++ b/libraries/animation/src/RotationAccumulator.h @@ -14,19 +14,27 @@ class RotationAccumulator { public: - RotationAccumulator() : _rotationSum(0.0f, 0.0f, 0.0f, 0.0f), _numRotations(0) { } + RotationAccumulator() : _rotationSum(0.0f, 0.0f, 0.0f, 0.0f), _numRotations(0), _isDirty(false) { } int size() const { return _numRotations; } - void add(glm::quat rotation); + void add(const glm::quat& rotation); glm::quat getAverage(); + /// \return true if any rotations were accumulated + bool isDirty() const { return _isDirty; } + + /// \brief clear accumulated rotation but don't change _isDirty void clear(); + /// \brief clear accumulated rotation and set _isDirty to false + void clearAndClean(); + private: glm::quat _rotationSum; int _numRotations; + bool _isDirty; }; #endif // hifi_RotationAccumulator_h