Remove Nima from DEPS, experiments, Viewer, etc.

Change-Id: Ide69d3c9f0f02e886bd0d52723d425a548edd2e0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214187
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2019-05-16 12:21:11 -04:00 committed by Skia Commit-Bot
parent d063e8b6f1
commit c6568afa0b
10 changed files with 0 additions and 895 deletions

View File

@ -42,7 +42,6 @@ declare_args() {
skia_enable_ccpr = true
skia_enable_nvpr = !skia_enable_flutter_defines
skia_enable_discrete_gpu = true
skia_enable_nima = false
skia_enable_pdf = true
skia_enable_spirv_validation = is_skia_dev_build && is_debug
skia_enable_skpicture = true
@ -892,10 +891,6 @@ component("skia") {
":xml",
]
if (skia_enable_nima) {
deps += [ "//third_party/Nima-Cpp" ]
}
# This file (and all GN files in Skia) are designed to work with an
# empty sources assignment filter; we handle all that explicitly.
# We clear the filter here for clients who may have set up a global filter.
@ -1787,12 +1782,6 @@ if (skia_enable_tools) {
"modules/skshaper",
]
# NIMA does not build on Windows clang
if (!is_win || !is_clang) {
sources += [ "experimental/nima/NimaActor.cpp" ]
deps += [ "//third_party/Nima-Cpp" ]
}
if (skia_use_lua) {
sources += [ "samplecode/SampleLua.cpp" ]
deps += [
@ -1865,11 +1854,6 @@ if (skia_enable_tools) {
"modules/skottie:utils",
"modules/sksg",
]
# NIMA does not build on Windows clang
if (!is_win || !is_clang) {
deps += [ "//third_party/Nima-Cpp" ]
}
}
}
@ -2341,12 +2325,6 @@ if (skia_enable_tools) {
"modules/sksg:samples",
"//third_party/imgui",
]
# NIMA does not build on Windows clang
if (!is_win || !is_clang) {
sources += [ "tools/viewer/NIMASlide.cpp" ]
deps += [ "//third_party/Nima-Cpp" ]
}
}
if (!skia_use_angle && (is_linux || is_win || is_mac)) {

2
DEPS
View File

@ -32,8 +32,6 @@ deps = {
#"third_party/externals/v8" : "https://chromium.googlesource.com/v8/v8.git@5f1ae66d5634e43563b2d25ea652dfb94c31a3b4",
"third_party/externals/wuffs" : "https://skia.googlesource.com/external/github.com/google/wuffs.git@f58ffbc927899b9534a273d3057094ce6ac1ed61",
"third_party/externals/zlib" : "https://chromium.googlesource.com/chromium/src/third_party/zlib@47af7c547f8551bd25424e56354a2ae1e9062859",
"third_party/externals/Nima-Cpp" : "https://skia.googlesource.com/external/github.com/2d-inc/Nima-Cpp.git@4bd02269d7d1d2e650950411325eafa15defb084",
"third_party/externals/Nima-Math-Cpp" : "https://skia.googlesource.com/external/github.com/2d-inc/Nima-Math-Cpp.git@e0c12772093fa8860f55358274515b86885f0108",
"../src": {
"url": "https://chromium.googlesource.com/chromium/src.git@8c742b264faa683884dc348471d8160d8c8e977f",

View File

@ -1,323 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/nima/NimaActor.h"
#include "include/core/SkData.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkString.h"
#include "include/core/SkVertices.h"
#include <algorithm>
#include <cmath>
NimaActor::NimaActor(std::string nimaPath, std::string texturePath)
: fTexture(nullptr)
, fActorImages()
, fPaint(nullptr)
, fAnimationNames()
, fAnimationInstance(nullptr) {
// Load the NIMA data.
INHERITED::load(nimaPath);
// Load the image asset.
fTexture = SkImage::MakeFromEncoded(SkData::MakeFromFileName(texturePath.c_str()));
this->init();
}
NimaActor::NimaActor(sk_sp<SkData> nimaBytes, sk_sp<SkData> textureBytes)
: fTexture(nullptr)
, fActorImages()
, fPaint(nullptr)
, fAnimationNames()
, fAnimationInstance(nullptr) {
// Load the NIMA data.
INHERITED::load(const_cast<uint8_t*>(nimaBytes->bytes()), nimaBytes->size());
// Load the image asset.
fTexture = SkImage::MakeFromEncoded(textureBytes);
this->init();
}
void NimaActor::init() {
// 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);
for (uint32_t i = 0; i < m_ImageNodeCount; i ++) {
fActorImages.emplace_back(m_ImageNodes[i], fTexture.get(), fPaint.get());
}
// Sort the image nodes.
std::sort(fActorImages.begin(), fActorImages.end(), [](auto a, auto b) {
return a.drawOrder() < b.drawOrder();
});
// Get the list of animations.
fAnimationNames.reserve(m_AnimationsCount);
for (uint32_t i = 0; i < m_AnimationsCount; i++) {
fAnimationNames.push_back(m_Animations[i].name());
}
this->setAnimation(0);
}
SkScalar NimaActor::duration() const {
if (fAnimationInstance) {
return fAnimationInstance->duration();
}
return 0.0f;
}
void NimaActor::setAnimation(uint8_t index) {
if (index < fAnimationNames.size()) {
fAnimationIndex = index;
fAnimationInstance = this->animationInstance(fAnimationNames[fAnimationIndex]);
}
}
void NimaActor::setAnimation(std::string name) {
for (size_t i = 0; i < fAnimationNames.size(); i++)
{
std::string aName = fAnimationNames[i];
if (aName == name)
{
setAnimation(i);
return;
}
}
}
void NimaActor::render(SkCanvas* canvas, uint32_t renderFlags) {
// Render the image nodes.
for (auto& image : fActorImages) {
image.render(canvas, renderFlags);
}
}
void NimaActor::seek(SkScalar t) {
// Apply the animation.
if (fAnimationInstance) {
t = std::fmod(t, fAnimationInstance->max());
fAnimationInstance->time(t);
fAnimationInstance->apply(1.0f);
}
}
// ===================================================================================
NimaActorImage::NimaActorImage(nima::ActorImage* actorImage, SkImage* texture, SkPaint* paint)
: fActorImage(actorImage)
, fTexture(texture)
, fPaint(paint)
, fSkinned(false)
, fPositions()
, fTexs()
, fBoneIdx()
, fBoneWgt()
, fIndices()
, fBones()
, fVertices(nullptr)
, fRenderFlags(0) {
// Update the vertices and bones.
this->updateVertices(true);
this->updateBones();
}
void NimaActorImage::render(SkCanvas* canvas, uint32_t renderFlags) {
bool dirty = renderFlags != fRenderFlags;
fRenderFlags = renderFlags;
bool useImmediate = renderFlags & kImmediate_RenderFlag;
bool useCache = renderFlags & kCache_RenderFlag;
bool drawBounds = renderFlags & kBounds_RenderFlag;
// Don't use the cache if drawing in immediate mode.
useCache &= !useImmediate;
if (fActorImage->doesAnimationVertexDeform() || dirty) {
// These are vertices that transform beyond just bone transforms, so they must be
// updated every frame.
// If the render flags are dirty, reset the vertices object.
this->updateVertices(!useCache);
}
// Update the bones.
this->updateBones();
// Deform the bones in immediate mode.
sk_sp<SkVertices> vertices = fVertices;
if (useImmediate) {
vertices = fVertices->applyBones(fBones.data(), fBones.size());
}
// Draw the vertices object.
this->drawVerticesObject(vertices.get(), canvas, !useImmediate);
// Draw the bounds.
if (drawBounds && fActorImage->renderOpacity() > 0.0f) {
// Get the bounds.
SkRect bounds = vertices->bounds();
// Approximate bounds if not using immediate transforms.
if (!useImmediate) {
const SkRect originalBounds = fBones[0].mapRect(vertices->bounds());
bounds = originalBounds;
for (size_t i = 1; i < fBones.size(); i++) {
const SkVertices::Bone& matrix = fBones[i];
bounds.join(matrix.mapRect(originalBounds));
}
}
// Draw the bounds.
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(0xFFFF0000);
canvas->drawRect(bounds, paint);
}
}
void NimaActorImage::updateVertices(bool isVolatile) {
// Update whether the image is skinned.
fSkinned = fActorImage->connectedBoneCount() > 0;
// Retrieve data from the image.
uint32_t vertexCount = fActorImage->vertexCount();
uint32_t vertexStride = fActorImage->vertexStride();
float* vertexData = fActorImage->vertices();
uint32_t indexCount = fActorImage->triangleCount() * 3;
uint16_t* indexData = fActorImage->triangles();
// Don't render if not visible.
if (!vertexCount || fActorImage->textureIndex() < 0) {
fPositions.clear();
fTexs.clear();
fBoneIdx.clear();
fBoneWgt.clear();
fIndices.clear();
return;
}
// Split the vertex data.
fPositions.resize(vertexCount);
fTexs.resize(vertexCount);
fIndices.resize(indexCount);
if (fSkinned) {
fBoneIdx.resize(vertexCount * 4);
fBoneWgt.resize(vertexCount * 4);
}
for (uint32_t i = 0; i < vertexCount; i ++) {
uint32_t j = i * vertexStride;
// Get the attributes.
float* attrPosition = vertexData + j;
float* attrTex = vertexData + j + 2;
float* attrBoneIdx = vertexData + j + 4;
float* attrBoneWgt = vertexData + j + 8;
// Get deformed positions if necessary.
if (fActorImage->doesAnimationVertexDeform()) {
attrPosition = fActorImage->animationDeformedVertices() + i * 2;
}
// Set the data.
fPositions[i].set(attrPosition[0], attrPosition[1]);
fTexs[i].set(attrTex[0] * fTexture->width(), attrTex[1] * fTexture->height());
if (fSkinned) {
for (uint32_t k = 0; k < 4; k ++) {
fBoneIdx[i][k] = static_cast<uint32_t>(attrBoneIdx[k]);
fBoneWgt[i][k] = attrBoneWgt[k];
}
}
}
memcpy(fIndices.data(), indexData, indexCount * sizeof(uint16_t));
// Update the vertices object.
fVertices = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode,
vertexCount,
fPositions.data(),
fTexs.data(),
nullptr,
fBoneIdx.data(),
fBoneWgt.data(),
fIndices.size(),
fIndices.data(),
isVolatile);
}
void NimaActorImage::updateBones() {
// NIMA matrices are a collection of 6 floats.
constexpr int kNIMAMatrixSize = 6;
// Set up the matrices for the first time.
if (fBones.size() == 0) {
int numMatrices = 1;
if (fSkinned) {
numMatrices = fActorImage->boneInfluenceMatricesLength() / kNIMAMatrixSize;
}
// Initialize all matrices to the identity matrix.
fBones.assign(numMatrices, {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }});
}
if (fSkinned) {
// Update the matrices.
float* matrixData = fActorImage->boneInfluenceMatrices();
memcpy(fBones.data(), matrixData, fBones.size() * kNIMAMatrixSize * sizeof(float));
}
// Set the zero matrix to be the world transform.
memcpy(fBones.data(),
fActorImage->worldTransform().values(),
kNIMAMatrixSize * sizeof(float));
}
void NimaActorImage::drawVerticesObject(SkVertices* vertices, SkCanvas* canvas, bool useBones) const {
// Determine the blend mode.
SkBlendMode blendMode;
switch (fActorImage->blendMode()) {
case nima::BlendMode::Off: {
blendMode = SkBlendMode::kSrc;
break;
}
case nima::BlendMode::Normal: {
blendMode = SkBlendMode::kSrcOver;
break;
}
case nima::BlendMode::Additive: {
blendMode = SkBlendMode::kPlus;
break;
}
case nima::BlendMode::Multiply: {
blendMode = SkBlendMode::kMultiply;
break;
}
case nima::BlendMode::Screen: {
blendMode = SkBlendMode::kScreen;
break;
}
}
// Set the opacity.
fPaint->setAlpha(static_cast<U8CPU>(fActorImage->renderOpacity() * 255));
// Draw the vertices.
if (useBones) {
canvas->drawVertices(vertices, fBones.data(), fBones.size(), blendMode, *fPaint);
} else {
canvas->drawVertices(vertices, blendMode, *fPaint);
}
// Reset the opacity.
fPaint->setAlpha(255);
}

View File

@ -1,133 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef NimaActor_DEFINED
#define NimaActor_DEFINED
#include <nima/Actor.hpp>
#include <nima/ActorImage.hpp>
#include <nima/Vec2D.hpp>
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include <string>
class NimaActor;
class NimaActorImage;
enum RenderFlags {
kImmediate_RenderFlag = 0x1,
kCache_RenderFlag = 0x2,
kBounds_RenderFlag = 0x4,
};
/** \class NimaActor
NimaActor acts as a breidge between Skia and a nima::Actor object.
The Actor object essentially is a set of bones and textures.
NimaActor knows how to draw itself (the Actor) to an SkCanvas
at various time stamps.
NimaActor is also aware of the different animation types the
Actor has and coordinates switching between them. For example,
an animation might have an "idle" and a "jump" animation it can
switch between.
*/
class NimaActor : public nima::Actor {
public:
NimaActor(std::string nimaPath, std::string texturePath);
NimaActor(sk_sp<SkData> nimaBytes, sk_sp<SkData> textureBytes);
~NimaActor() = default;
/**
* Render draws itself to the given canvas, at whatever
* the current time position is (see seek).
*/
void render(SkCanvas* canvas, uint32_t renderFlags = 0);
/**
* Updates the animation state to be at time t.
* This does not re-draw anything, another call to render() is required.
*
* @param t - number of second in (modulo total duration)
*
*/
void seek(SkScalar t);
/**
* Returns the duration of the current Actor's animation in seconds.
*/
SkScalar duration() const;
/**
* Sets the animation type based on the index given. The default
* animation index is 0. If index is invalid, nothing changes.
*/
void setAnimation(uint8_t index);
/**
* Sets the animation type to be one that matches the provided
* name. If the name does not match any of the existing animation
* types, nothing changes.
*/
void setAnimation(std::string name);
/**
* Returns all possible animation names. Use with setAnimation().
*/
const std::vector<std::string>& getAnimationNames() const {
return fAnimationNames;
}
private:
void init();
sk_sp<SkImage> fTexture;
std::vector<NimaActorImage> fActorImages;
std::unique_ptr<SkPaint> fPaint;
std::vector<std::string> fAnimationNames;
nima::ActorAnimationInstance* fAnimationInstance;
uint8_t fAnimationIndex;
typedef nima::Actor INHERITED;
};
// A wrapper class that handles rendering of ActorImages (renderable components NIMA Actors).
class NimaActorImage {
public:
NimaActorImage(nima::ActorImage* actorImage, SkImage* texture, SkPaint* paint);
~NimaActorImage() = default;
void render(SkCanvas* canvas, uint32_t renderFlags);
int drawOrder() const { return fActorImage->drawOrder(); }
private:
nima::ActorImage* fActorImage;
SkImage* fTexture;
SkPaint* fPaint;
bool fSkinned;
std::vector<SkPoint> fPositions;
std::vector<SkPoint> fTexs;
std::vector<SkVertices::BoneIndices> fBoneIdx;
std::vector<SkVertices::BoneWeights> fBoneWgt;
std::vector<uint16_t> fIndices;
std::vector<SkVertices::Bone> fBones;
sk_sp<SkVertices> fVertices;
uint32_t fRenderFlags;
void updateVertices(bool isVolatile);
void updateBones();
void drawVerticesObject(SkVertices* vertices, SkCanvas* canvas, bool useBones) const;
};
#endif

View File

@ -61,7 +61,6 @@ samples_sources = [
"$_samplecode/SampleLitAtlas.cpp",
"$_samplecode/SampleManyRects.cpp",
"$_samplecode/SampleMegaStroke.cpp",
"$_samplecode/SampleNima.cpp",
"$_samplecode/SampleMixer.cpp",
"$_samplecode/SamplePatch.cpp",
"$_samplecode/SamplePath.cpp",
@ -100,7 +99,3 @@ samples_sources = [
"$_samplecode/SampleXfermodesBlur.cpp",
"$_samplecode/vertexdump.cpp",
]
if (is_win && is_clang) {
samples_sources -= [ "$_samplecode/SampleNima.cpp" ]
}

View File

@ -1,73 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "samplecode/Sample.h"
#include "experimental/nima/NimaActor.h"
#include "tools/Resources.h"
#include "tools/timer/AnimTimer.h"
#include <nima/Animation/ActorAnimationInstance.hpp>
#include <cmath>
using namespace nima;
class NimaView : public Sample {
public:
NimaView()
: fActor(nullptr) {
}
protected:
virtual bool onQuery(Sample::Event* evt) override {
if (Sample::TitleQ(*evt)) {
Sample::TitleR(evt, "Nima");
return true;
}
return this->INHERITED::onQuery(evt);
}
void onOnceBeforeDraw() override {
// Create the actor.
std::string nimaPath(GetResourcePath("nima/Robot.nima").c_str());
std::string texturePath(GetResourcePath("nima/Robot.png").c_str());
fActor = std::make_unique<NimaActor>(nimaPath, texturePath);
// Also available: dance, jump, idle
fActor->setAnimation("attack");
}
void onDrawContent(SkCanvas* canvas) override {
canvas->save();
canvas->translate(500, 700);
canvas->scale(1, -1);
// Render the actor.
fActor->render(canvas);
canvas->restore();
}
bool onAnimate(const AnimTimer& timer) override {
if (fActor) {
float time = std::fmod(timer.secs(), fActor->duration());
fActor->seek(time);
}
return true;
}
private:
std::unique_ptr<NimaActor> fActor;
typedef Sample INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_SAMPLE( return new NimaView(); )

View File

@ -1,99 +0,0 @@
# Copyright 2018 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../third_party.gni")
copy("copy-nima-cpp") {
sources = [
"../externals/Nima-Cpp/Source",
]
outputs = [
"$target_gen_dir/Nima-Cpp/nima",
]
}
copy("copy-nima-math-cpp") {
sources = [
"../externals/Nima-Math-Cpp/Source",
]
outputs = [
"$target_gen_dir/Nima-Math-Cpp/nima",
]
}
third_party("Nima-Cpp") {
deps = [
":copy-nima-cpp",
":copy-nima-math-cpp",
]
public_include_dirs = [
"$target_gen_dir/Nima-Cpp",
"$target_gen_dir/Nima-Math-Cpp",
]
configs -= [
"//gn:no_exceptions",
"//gn:no_rtti",
]
sources = [
"../externals/Nima-Cpp/Source/Actor.cpp",
"../externals/Nima-Cpp/Source/ActorBone.cpp",
"../externals/Nima-Cpp/Source/ActorCollider.cpp",
"../externals/Nima-Cpp/Source/ActorComponent.cpp",
"../externals/Nima-Cpp/Source/ActorEvent.cpp",
"../externals/Nima-Cpp/Source/ActorIKTarget.cpp",
"../externals/Nima-Cpp/Source/ActorImage.cpp",
"../externals/Nima-Cpp/Source/ActorInstance.cpp",
"../externals/Nima-Cpp/Source/ActorNode.cpp",
"../externals/Nima-Cpp/Source/ActorNodeSolo.cpp",
"../externals/Nima-Cpp/Source/ActorRenderNode.cpp",
"../externals/Nima-Cpp/Source/ActorRootBone.cpp",
"../externals/Nima-Cpp/Source/ActorStaticMesh.cpp",
"../externals/Nima-Cpp/Source/Animation/ActorAnimation.cpp",
"../externals/Nima-Cpp/Source/Animation/ActorAnimationInstance.cpp",
"../externals/Nima-Cpp/Source/Animation/ComponentAnimation.cpp",
"../externals/Nima-Cpp/Source/Animation/Interpolators/CubicSolver.cpp",
"../externals/Nima-Cpp/Source/Animation/Interpolators/ValueTimeCurveInterpolator.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrame.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameActiveChild.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameCustomProperty.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameDrawOrder.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameIKStrength.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameIsCollisionEnabled.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameLength.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameNumeric.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameOpacity.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFramePosX.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFramePosY.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameRotation.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameScaleX.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameScaleY.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameSequence.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameTrigger.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameVertexDeform.cpp",
"../externals/Nima-Cpp/Source/Animation/KeyFrames/KeyFrameWithInterpolation.cpp",
"../externals/Nima-Cpp/Source/Animation/PropertyAnimation.cpp",
"../externals/Nima-Cpp/Source/BinaryReader.cpp",
"../externals/Nima-Cpp/Source/BlockReader.cpp",
"../externals/Nima-Cpp/Source/CustomProperty.cpp",
"../externals/Nima-Cpp/Source/NestedActorAsset.cpp",
"../externals/Nima-Cpp/Source/NestedActorNode.cpp",
"../externals/Nima-Math-Cpp/Source/Mat2D.cpp",
"../externals/Nima-Math-Cpp/Source/Vec2D.cpp",
]
cflags_cc = []
if (is_win) {
defines = [ "_USE_MATH_DEFINES" ]
cflags_cc += [
"/FI",
"algorithm",
]
}
enabled = !is_win || !is_clang
}

View File

@ -1,178 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/viewer/NIMASlide.h"
#include "src/utils/SkOSPath.h"
#include "tools/Resources.h"
#include "tools/timer/AnimTimer.h"
#include "imgui.h"
#include "experimental/nima/NimaActor.h"
#include <algorithm>
#include <cmath>
using namespace sk_app;
using namespace nima;
// ImGui expects an array of const char* when displaying a ListBox. This function is for an
// overload of ImGui::ListBox that takes a getter so that ListBox works with
// std::vector<std::string>.
static bool vector_getter(void* v, int index, const char** out) {
auto vector = reinterpret_cast<std::vector<std::string>*>(v);
*out = vector->at(index).c_str();
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
NIMASlide::NIMASlide(const SkString& name, const SkString& path)
: fBasePath()
, fActor(nullptr)
, fAnimationIndex(0)
, fPlaying(true)
, fTime(0.0f)
, fRenderFlags(0) {
fName = name;
// Get the path components.
SkString baseName = SkOSPath::Basename(path.c_str());
baseName.resize(baseName.size() - 5);
SkString dirName = SkOSPath::Dirname(path.c_str());
SkString basePath = SkOSPath::Join(dirName.c_str(), baseName.c_str());
// Save the base path.
fBasePath = std::string(basePath.c_str());
}
NIMASlide::~NIMASlide() {}
SkISize NIMASlide::getDimensions() const {
return SkISize::MakeEmpty(); // TODO
}
void NIMASlide::draw(SkCanvas* canvas) {
canvas->save();
for (int i = 0; i < 10; i ++) {
for (int j = 0; j < 10; j ++) {
canvas->save();
canvas->translate(1250 - 250 * i, 1250 - 250 * j);
canvas->scale(0.5, -0.5);
// Render the actor.
fActor->setAnimation(fAnimationIndex);
fActor->render(canvas, fRenderFlags);
canvas->restore();
}
}
canvas->restore();
// Render the GUI.
this->renderGUI();
}
void NIMASlide::load(SkScalar winWidth, SkScalar winHeight) {
this->resetActor();
}
void NIMASlide::unload() {
// Discard resources.
fActor.reset(nullptr);
}
bool NIMASlide::animate(const AnimTimer& timer) {
// Apply the animation.
if (fActor) {
float time = std::fmod(timer.secs(), fActor->duration());
fActor->seek(time);
}
return true;
}
bool NIMASlide::onChar(SkUnichar c) {
return false;
}
bool NIMASlide::onMouse(SkScalar x, SkScalar y, Window::InputState state, uint32_t modifiers) {
return false;
}
void NIMASlide::resetActor() {
// Create the actor.
std::string nimaPath = fBasePath + ".nima";
std::string texturePath = fBasePath + ".png";
fActor = std::make_unique<NimaActor>(nimaPath, texturePath);
}
void NIMASlide::renderGUI() {
ImGui::SetNextWindowSize(ImVec2(300, 0));
ImGui::Begin("NIMA");
// List of animations.
auto animations = const_cast<std::vector<std::string>&>(fActor->getAnimationNames());
ImGui::PushItemWidth(-1);
if (ImGui::ListBox("Animations",
&fAnimationIndex,
vector_getter,
reinterpret_cast<void*>(&animations),
animations.size(),
5)) {
resetActor();
}
// Playback control.
ImGui::Spacing();
if (ImGui::Button("Play")) {
fPlaying = true;
}
ImGui::SameLine();
if (ImGui::Button("Pause")) {
fPlaying = false;
}
// Time slider.
ImGui::PushItemWidth(-1);
ImGui::SliderFloat("Time", &fTime, 0.0f, fActor->duration(), "Time: %.3f");
// Backend control.
int useImmediate = SkToBool(fRenderFlags & kImmediate_RenderFlag);
ImGui::Spacing();
ImGui::RadioButton("Skia Backend", &useImmediate, 0);
ImGui::RadioButton("Immediate Backend", &useImmediate, 1);
if (useImmediate) {
fRenderFlags |= kImmediate_RenderFlag;
} else {
fRenderFlags &= ~kImmediate_RenderFlag;
}
// Cache control.
bool useCache = SkToBool(fRenderFlags & kCache_RenderFlag);
ImGui::Spacing();
ImGui::Checkbox("Cache Vertices", &useCache);
if (useCache) {
fRenderFlags |= kCache_RenderFlag;
} else {
fRenderFlags &= ~kCache_RenderFlag;
}
// Bounding box toggle.
bool drawBounds = SkToBool(fRenderFlags & kBounds_RenderFlag);
ImGui::Spacing();
ImGui::Checkbox("Draw Bounds", &drawBounds);
if (drawBounds) {
fRenderFlags |= kBounds_RenderFlag;
} else {
fRenderFlags &= ~kBounds_RenderFlag;
}
ImGui::End();
}

View File

@ -1,48 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef NIMASlide_DEFINED
#define NIMASlide_DEFINED
#include "tools/viewer/Slide.h"
#include "experimental/nima/NimaActor.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkVertices.h"
class NIMASlide : public Slide {
public:
NIMASlide(const SkString& name, const SkString& path);
~NIMASlide() override;
SkISize getDimensions() const override;
void draw(SkCanvas* canvas) override;
void load(SkScalar winWidth, SkScalar winHeight) override;
void unload() override;
bool animate(const AnimTimer& timer) override;
bool onChar(SkUnichar c) override;
bool onMouse(SkScalar x, SkScalar y, sk_app::Window::InputState state,
uint32_t modifiers) override;
private:
void resetActor();
void renderGUI();
private:
std::string fBasePath;
std::unique_ptr<NimaActor> fActor;
int fAnimationIndex;
bool fPlaying;
float fTime;
uint32_t fRenderFlags;
};
#endif

View File

@ -52,10 +52,6 @@
#include "tools/viewer/SkottieSlide.h"
#endif
#if !(defined(SK_BUILD_FOR_WIN) && defined(__clang__))
#include "tools/viewer/NIMASlide.h"
#endif
class CapturingShaderErrorHandler : public GrContextOptions::ShaderErrorHandler {
public:
void compileError(const char* shader, const char* errors) override {
@ -113,13 +109,11 @@ static DEFINE_string2(match, m, nullptr,
#if defined(SK_BUILD_FOR_ANDROID)
static DEFINE_string(jpgs, "/data/local/tmp/resources", "Directory to read jpgs from.");
static DEFINE_string(nimas, "/data/local/tmp/nimas", "Directory to read NIMA animations from.");
static DEFINE_string(skps, "/data/local/tmp/skps", "Directory to read skps from.");
static DEFINE_string(lotties, "/data/local/tmp/lotties",
"Directory to read (Bodymovin) jsons from.");
#else
static DEFINE_string(jpgs, "jpgs", "Directory to read jpgs from.");
static DEFINE_string(nimas, "nimas", "Directory to read NIMA animations from.");
static DEFINE_string(skps, "skps", "Directory to read skps from.");
static DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from.");
#endif
@ -611,12 +605,6 @@ void Viewer::initSlides() {
[](const SkString& name, const SkString& path) -> sk_sp<Slide> {
return sk_make_sp<SvgSlide>(name, path);}
},
#endif
#if !(defined(SK_BUILD_FOR_WIN) && defined(__clang__))
{ ".nima", "nima-dir", FLAGS_nimas,
[](const SkString& name, const SkString& path) -> sk_sp<Slide> {
return sk_make_sp<NIMASlide>(name, path);}
},
#endif
};