fixed NIMA deformed vertices rendering

Bug: skia:
Change-Id: I43c1a86eead7701db052451c446f9ad59467f909
Reviewed-on: https://skia-review.googlesource.com/136610
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ruiqi Mao <ruiqimao@google.com>
This commit is contained in:
Ruiqi Mao 2018-06-21 11:24:13 -04:00 committed by Skia Commit-Bot
parent 94ed719bf8
commit 9ac1b729f1
4 changed files with 15 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 170 KiB

View File

@ -10,11 +10,10 @@
#include "SkString.h"
#include "SkVertices.h"
#include "SkPaint.h"
#include "SkFilterQuality.h"
#include "Resources.h"
#include <algorithm>
#include <iostream>
using namespace nima;
SampleActor::SampleActor(std::string baseName)
@ -32,6 +31,7 @@ SampleActor::SampleActor(std::string baseName)
// Create the paint.
fPaint = std::make_unique<SkPaint>();
fPaint->setShader(fTexture->makeShader(nullptr));
fPaint->setFilterQuality(SkFilterQuality::kLow_SkFilterQuality);
// Load the image nodes.
fActorImages.reserve(m_ImageNodeCount);
@ -89,6 +89,11 @@ void SampleActorImage::render(const SampleActor* actor, SkCanvas* canvas) const
float* attrBoneIdx = vertexData + j + 4;
float* attrBoneWgt = vertexData + j + 8;
// Get deformed positions if necessary.
if (fActorImage->doesAnimationVertexDeform()) {
attrPosition = fActorImage->animationDeformedVertices() + i * 2;
}
// Deform the position.
Vec2D position(attrPosition[0], attrPosition[1]);
if (fActorImage->connectedBoneCount() > 0) {

View File

@ -9,7 +9,7 @@
#include "Nima.h"
#include "SkAnimTimer.h"
#include "SkView.h"
#include <nima/Animation/ActorAnimation.hpp>
#include <nima/Animation/ActorAnimationInstance.hpp>
#include <cmath>
using namespace nima;
@ -17,7 +17,8 @@ using namespace nima;
class NimaView : public SampleView {
public:
NimaView()
: fActor(nullptr) {
: fActor(nullptr)
, fAnimation(nullptr) {
}
protected:
@ -35,7 +36,7 @@ protected:
fActor = std::make_unique<SampleActor>("Robot");
// Get the animation.
fAnimation = fActor->animation("jump");
fAnimation = fActor->animationInstance("attack");
}
void onDrawContent(SkCanvas* canvas) override {
@ -53,15 +54,16 @@ protected:
bool onAnimate(const SkAnimTimer& timer) override {
// Apply the animation.
if (fAnimation) {
float time = std::fmod(timer.secs(), fAnimation->duration());
fAnimation->apply(time, fActor.get(), 1.0f);
float time = std::fmod(timer.secs(), fAnimation->max());
fAnimation->time(time);
fAnimation->apply(1.0f);
}
return true;
}
private:
std::unique_ptr<SampleActor> fActor;
ActorAnimation* fAnimation = nullptr;
ActorAnimationInstance* fAnimation;
typedef SampleView INHERITED;
};