From 8a2298bfcb87acda4f65aff645deeb2c91a94026 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Fri, 9 Nov 2018 23:42:20 +0800 Subject: [PATCH] Smooth pose sheet Simple smooth algorithm: average the frame transform with neiboring frames. --- src/motionsgenerator.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/motionsgenerator.cpp b/src/motionsgenerator.cpp index 01bd6b58..a4993016 100644 --- a/src/motionsgenerator.cpp +++ b/src/motionsgenerator.cpp @@ -187,18 +187,19 @@ void MotionsGenerator::generateMotion(const QUuid &motionId, std::set &vi int frame = clipLocalProgress * frames->size() / clipDuration; if (frame >= (int)frames->size()) frame = frames->size() - 1; - //int nextFrame = frame + 1; - //if (nextFrame >= (int)frames->size()) - // nextFrame = frames->size() - 1; - //float offset = clipLocalProgress / clipDuration; - //qDebug() << "frame:" << frame << "clipLocalProgress:" << clipLocalProgress << "clipDuration:" << clipDuration; - if (frame >= 0 && frame < (int)frames->size()/* && - nextFrame >= 0 && nextFrame < (int)frames->size()*/) { + int previousFrame = frame - 1; + if (previousFrame < 0) + previousFrame = 0; + int nextFrame = frame + 1; + if (nextFrame >= (int)frames->size()) + nextFrame = frames->size() - 1; + if (frame >= 0 && frame < (int)frames->size()) { + const JointNodeTree previousJointNodeTree = poseJointNodeTree(progressClip.linkToId, previousFrame); const JointNodeTree jointNodeTree = poseJointNodeTree(progressClip.linkToId, frame); - //const JointNodeTree nextJointNodeTree = poseJointNodeTree(progressClip.linkToId, nextFrame); - //outcomes.push_back({progress - lastProgress, - // generateInterpolation(progressClip.interpolationType, jointNodeTree, nextJointNodeTree, offset)}); - outcomes.push_back({progress - lastProgress, jointNodeTree}); + const JointNodeTree nextJointNodeTree = poseJointNodeTree(progressClip.linkToId, nextFrame); + const JointNodeTree middleJointNodeTree = generateInterpolation(InterpolationType::Linear, previousJointNodeTree, nextJointNodeTree, 0.5); + outcomes.push_back({progress - lastProgress, + generateInterpolation(InterpolationType::Linear, jointNodeTree, middleJointNodeTree, 0.5)}); lastProgress = progress; } progress += interval;