• This repository has been archived on 10/Jan/2020
  • Stars
    star
    5,343
  • Rank 7,732 (Top 0.2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library for converting Adobe AE shape based animations to a data format and playing it back on Android and iOS devices.

Keyframes

Version Version Carthage compatible License

Keyframes

Keyframes is a combination of (1) an ExtendScript script that extracts image animation data from an After Effects file and (2) a corresponding rendering library for Android and iOS. Keyframes can be used to export and render high quality, vector based animations with complex shape and path curves, all with minimal file footprint.

Usage

Developing Animations in After Effects

For a detailed list of constraints for developing animations to use with the Keyframes library, please refer to the Keyframes After Effects Guidelines.

Image Data Extraction

Use of the extraction script requires an installation of Adobe After Effects as well as Adobe ExtendScript Toolkit. If Keyframes JSON files are already available, only the corresponding iOS and Android libraries are needed.

For detailed steps on running the ExtendScript script on your AE comp, please refer to the instructions detailed here.

iOS Rendering

Installation

CocoaPods

Keyframes is available on CocoaPods. Add the following to your Podfile:

target 'MyApp' do
  pod "keyframes"
end

Quit Xcode completely before running

pod install

in the project directory in terminal.

Carthage

Keyframes is also available through Carthage.

Add the following to your Cartfile to get the latest release branch:

github "facebookincubator/Keyframes"

Or, to get the master branch:

github "facebookincubator/Keyframes" "master"

Run

> carthage update

In Xcode, on your application targetsโ€™ "General" settings tab, in the "Linked Frameworks and Libraries" section, drag and drop the framework from the Carthage/Build folder.

Rendering Setup

Use the provided deserializers on the generated JSON blob from the Image Data Extraction step to create a KFVector model object. If your JSON blob lives in the assets directory, this might look like:

NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"asset_name" ofType:@"json" inDirectory:nil];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSDictionary *vectorDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
KFVector *vector = KFVectorFromDictionary(vectorDictionary);

Then a KFVectorLayer can be created using this KFVector, KFVectorLayer can be used as normal CALayer.

KFVectorLayer *layer = [KFVectorLayer layer];
// Set a non-zero layer frame before setting the KFVector is required.
layer.frame = $AnyNonZeroCGRect$;
layer.faceModel = vector;

If you don't want the control of animation and prefer a UIView, KFVectorView can also be created using KFVector.

KFVectorView *view = [[KFVectorView alloc] initWithFrame:$AnyNonZeroCGRect$ faceVector:vector];

Play!

Use startAnimation, pauseAnimation, resumeAnimation and seekToProgress on KFVectorLayer to control the animation.

// Animation will start from beginning.
[layer startAnimation];

// Pause the animation at current progress.
[layer pauseAnimation];

// Resume the animation from where we paused last time.
[layer resumeAnimation];

// Seek to a given progress in range [0, 1]
[layer seekToProgress:0.5]; // seek to the mid point of the animation

Android Rendering

Download

Download the latest JARs or grab via Gradle:

compile 'com.facebook.keyframes:keyframes:1.0'

or Maven:

<dependency>
  <groupId>com.facebook.keyframes</groupId>
  <artifactId>keyframes</artifactId>
  <version>1.0</version>
</dependency>

Rendering setup

Use the provided deserializers on the generated JSON blob from the Image Data Extraction step to create a KFImage model object. If your JSON blob lives in the assets directory, this might look like:

InputStream stream = getResources().getAssets().open("asset_name");
KFImage kfImage = KFImageDeserializer.deserialize(stream);

A KeyframesDrawable object can be created now using this KFImage, and this drawable can be used as a normal drawable. It is highly recommended to use the software layer on any views displaying Keyframes animations.

KeyframesDrawable kfDrawable = new KeyframesDrawableBuilder().withImage(kfImage).build();

ImageView imageView = (ImageView) findViewById(R.id.some_image_view);
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
imageView.setImageDrawable(kfDrawable);
imageView.setImageAlpha(0);

Play!

Use the start and stop animations on the drawable when appropriate to begin playback of the animation or end it after the end of the current loop.

// Starts a loop that progresses animation from the beginning and invalidates the drawable.
kfDrawable.startAnimation();

// Pause the animation at current progress.
kfDrawable.pauseAnimation();

// Resume the animation from where we paused last time.
kfDrawable.resumeAnimation();

// Stops the animation.
kfDrawable.stopAnimation();

// Stops the animation when the current animation ends.
kfDrawable.stopAnimationAtLoopEnd();

// Starts the animation and plays it once. Will stop at the end
kfDrawable.playOnce();

Mobile Frameworks

Existing implementations for mobile frameworks:

Framework Platform Author Link
React Native (imperative api) Android/IOS Tomas Roos https://github.com/ptomasroos/react-native-keyframes/
Appcelerator Titanium iOS Hans Knoechel https://github.com/hansemannn/ti.keyframes
Appcelerator Titanium Android Michael Gangolf https://github.com/m1ga/ti.keyframes
React Native Android/iOS Underscope https://github.com/underscopeio/react-native-facebook-keyframes
NativeScript Android/IOS Eddy Verbruggen https://github.com/EddyVerbruggen/nativescript-keyframes

Understanding Keyframes Model Objects

Image

An Image in Keyframes consists of a number of important fields, which together, describe an animated and scalable image. At the top level, an image contains information about how to scale (canvas_size) an image, as well as how to play back an animation at the correct speed (frame_rate, frame_count). The animation itself is not bound to the discrete frame_rate that the image was extracted at, as the Keyframes rendering library supports fractional frames. In addition to these global parameters of an Image, an Image also contains a number of Features, which describe different shapes to be drawn, as well as Animation Groups, which describe transforms that can be applied to multiple Features or even other Animation Groups at once.

Let's break down this simple image of a star against a circle scaling up and down. The animation was exported at 24FPS, and the frame number is shown in the top left corner as well as the scale of the star on the bottom.

Star, Real Time

Let's slow that down a bit, frame by frame.

Star, Slowwwww

Features

A Feature is any independent visual object of the image. Most important, it includes shape drawing commands, presented very similary to SVG type commands, which describe the Feature's shape at any given time. A Feature may belong to a larger Animation Group, as well as contain features specific animations of its own, including a specialized STROKE_WIDTH animation. The shape of a Feature can also change over time, using the same Keyframe and Interpolator pattern described below.

Shape

A shape is any list of line drawing commands, which strung together, describe a continuous line or closed shape that can be filled or stroked. The commands are given as a series of Move, Line, Quadratic, and Cubic commands, one after another.

Here are the important shapes for the above image, along with vertices (squares) and control points (circles), if relevant.

Circle Shape Star Shape

Animations

Transforms

The Keyframes rendering library includes support for the common matrix based transform operations, SCALE, ROTATE, and TRANSLATE. For Features specifically, an additional non-matrix STROKE_WIDTH is available. Animations may belong to specific Features, or as part of a larger Animation Group.

Animation Progression

The values of a transform of an animation and how they change during the playback of an animation are determined by two key fields, Keyframes and Timing Curves. Using the combination of the two fields, we can calculate back a value for a transform at any specified time in the animation.

Keyframes are specific frames in the animation that have specific target values. For example, in scaling a shape up and back down over 10 frames, we will want to start and end at 100% scale at the 0th and 10th frame, and hit our max scale of 150% on the 7th frame. In this example, our key frames for the SCALE transform for this shape would be [0, 7, 10] with the values [100%, 150%, 100% respectively.

Timing Curves describe the pace with which a transform changes between each keyframe. Each timing curve is modeled as a cubic bezier curve from point [0, 0] to [1, 1], where the X value is the progression in time from the origin keyframe to the destination keyframe, and the Y value describes the amount of change in the value at a given time: origValue + (destValue - origValue) * Y.

For our scaling star image, the graph of scale change over time looks like this, with vertices and timing curve in/out values shown.

Scale Animation Curve

Tying it all together

With these fields from an Image object, as well as a progress value, we can build back all of the shapes of the Image at a given time, as well as any transformations to apply to the shapes, and draw back the Image at that frame. Because the animations are driven by flexible timing_curves, a Keyframes Image is not limited to discrete integer frames for playback, but it is important to note that all progress values are given in relation to the frame count. This means a 10 frame animation accepts all values in the range [0..10].

Contributing

See CONTRIBUTING.md for how to help us by improving this library!

More Repositories

1

draft-js

A React framework for building text editors.
JavaScript
22,506
star
2

pop

An extensible iOS and OS X animation library, useful for physics-based interactions.
Objective-C++
19,716
star
3

flux

Application Architecture for Building User Interfaces
JavaScript
17,397
star
4

prepack

A JavaScript bundle optimizer.
JavaScript
14,271
star
5

AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.
Objective-C++
13,447
star
6

stetho

Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.
Java
12,653
star
7

Shimmer

An easy way to add a simple, shimmering effect to any view in an iOS app.
Objective-C
9,375
star
8

react-360

Create amazing 360 and VR content using React
JavaScript
8,702
star
9

caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
Shell
8,420
star
10

nuclide

An open IDE for web and native mobile development, built on top of Atom
JavaScript
7,816
star
11

KVOController

Simple, modern, thread-safe key-value observing for iOS and OS X.
Objective-C
7,359
star
12

three20

Three20 is an Objective-C library for iPhone developers
Objective-C
7,265
star
13

xctool

An extension for Apple's xcodebuild that makes it easier to test iOS and macOS apps.
Objective-C
6,954
star
14

fbctf

Platform to host Capture the Flag competitions
Hack
6,495
star
15

rebound

A Java library that models spring dynamics and adds real world physics to your app.
Java
5,444
star
16

shimmer-android

An easy, flexible way to add a shimmering effect to any view in an Android app.
Java
5,265
star
17

grace

Graceful restart & zero downtime deploy for Go servers.
Go
4,899
star
18

Tweaks

An easy way to fine-tune, and adjust parameters for iOS apps in development.
Objective-C
4,751
star
19

augmented-traffic-control

Augmented Traffic Control: A tool to simulate network conditions
Python
4,331
star
20

fixed-data-table

A React table component designed to allow presenting thousands of rows of data.
JavaScript
4,314
star
21

WebDriverAgent

A WebDriver server for iOS that runs inside the Simulator.
Objective-C
4,096
star
22

huxley

A testing system for catching visual regressions in Web applications.
Python
4,086
star
23

codemod

Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.
Python
4,069
star
24

scribe

Scribe is a server for aggregating log data streamed in real time from a large number of servers.
C++
3,932
star
25

FBMemoryProfiler

iOS tool that helps with profiling iOS Memory usage.
Objective-C
3,417
star
26

mention-bot

Automatically mention potential reviewers on pull requests.
JavaScript
3,371
star
27

facebook-php-sdk

This SDK is deprecated. Find the new SDK here: https://github.com/facebook/facebook-php-sdk-v4
PHP
3,289
star
28

origami

A Quartz Composer framework that enables interactive design prototyping without programming.
Objective-C
3,280
star
29

RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
HTML
3,211
star
30

network-connection-class

Listen to current network traffic in the app and categorize the quality of the network.
Java
3,178
star
31

beringei

Beringei is a high performance, in-memory storage engine for time series data.
C++
3,159
star
32

php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
PHP
3,146
star
33

react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
Java
2,993
star
34

python-instagram

Python Client for Instagram API
Python
2,966
star
35

conceal

Conceal provides easy Android APIs for performing fast encryption and authentication of data.
C++
2,966
star
36

webscalesql-5.6

WebScaleSQL, Version 5.6, based upon the MySQL-5.6 community releases.
C++
2,954
star
37

ios-snapshot-test-case

Snapshot view unit tests for iOS
Objective-C
2,674
star
38

device-year-class

A library that analyzes an Android device's specifications and calculates which year the device would be considered "high endโ€.
Java
2,581
star
39

BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2,497
star
40

pfff

Tools for code analysis, visualizations, or style-preserving source transformation.
OCaml
2,439
star
41

fb.resnet.torch

Torch implementation of ResNet from http://arxiv.org/abs/1512.03385 and training scripts
Lua
2,243
star
42

redux-react-hook

React Hook for accessing state and dispatch from a Redux store
TypeScript
2,164
star
43

Surround360

Surround360 is Facebook's open source hardware and software for capturing stereoscopic 3D 360 video for VR. The repo contains hardware designs, as well as software for camera control and rendering.
C++
2,153
star
44

xcbuild

Xcode-compatible build tool.
C++
2,000
star
45

LogDevice

Distributed storage for sequential data
C++
1,888
star
46

MemNN

Memory Networks implementations
Lua
1,757
star
47

rebound-js

Spring dynamics in JavaScript.
JavaScript
1,754
star
48

redis-faina

A query analyzer that parses Redis' MONITOR command for counter/timing stats about query patterns
Python
1,749
star
49

fb-flo

A Chrome extension that lets you modify running apps without reloading them.
JavaScript
1,692
star
50

planout

PlanOut is a library and interpreter for designing online experiments.
JavaScript
1,664
star
51

libphenom

An eventing framework for building high performance and high scalability systems in C.
C
1,662
star
52

flashcache

A general purpose, write-back block cache for Linux.
C
1,601
star
53

python-nubia

A command-line and interactive shell framework.
Python
1,595
star
54

profilo

A library for performance traces from production.
C
1,577
star
55

facebook-swift-sdk

Integrate your iOS apps in Swift with Facebook Platform.
Swift
1,519
star
56

instagram-ruby-gem

The official gem for the Instagram API
Ruby
1,461
star
57

inject

Package inject provides a reflect based injector.
Go
1,393
star
58

Flicks

A unit of time defined in C++.
C++
1,388
star
59

duckling_old

Deprecated in favor of https://github.com/facebook/duckling
Clojure
1,322
star
60

connect-js

Legacy JavaScript SDK
JavaScript
1,237
star
61

atom-in-orbit

Putting Atom in the browser
JavaScript
1,183
star
62

phpsh

A read-eval-print-loop for php
Emacs Lisp
1,160
star
63

C3D

C3D is a modified version of BVLC caffe to support 3D ConvNets.
Jupyter Notebook
1,159
star
64

sublime-react

Sublime Text helpers for React. Syntax highlighting DEPRECATED in favor of babel/babel-sublime
JavaScript
1,144
star
65

fb-adb

A better shell for Android devices
C
1,139
star
66

iTorch

IPython kernel for Torch with visualization and plotting
Jupyter Notebook
1,104
star
67

FBAllocationTracker

iOS library that helps tracking all allocated Objective-C objects
Objective-C++
1,094
star
68

fbcunn

Facebook's extensions to torch/cunn.
Lua
1,069
star
69

emitter

A JS EventEmitter foundation for evented code
JavaScript
1,041
star
70

bistro

Bistro is a flexible distributed scheduler, a high-performance framework supporting multiple paradigms while retaining ease of configuration, management, and monitoring.
C++
1,040
star
71

relay-starter-kit

Barebones starting point for a Relay application.
JavaScript
1,017
star
72

torchnet

Torch on steroids
Lua
992
star
73

react-meteor

React rendering for Meteor apps
JavaScript
953
star
74

atom-ide-ui

A collection of user interfaces for Atom IDE.
JavaScript
936
star
75

NAMAS

Neural Attention Model for Abstractive Summarization
Lua
910
star
76

nifty

Thrift on Netty
Java
899
star
77

swift

An annotation-based Java library for creating Thrift serializable types and services.
Java
889
star
78

bAbI-tasks

Task generation for testing text understanding and reasoning
Lua
886
star
79

hadoop-20

Facebook's Realtime Distributed FS based on Apache Hadoop 0.20-append
Java
876
star
80

loop

A method to generate speech across multiple speakers
Python
872
star
81

IGInterfaceDataTable

A category on WKInterfaceTable that makes configuring tables with multi-dimensional data easier.
Objective-C
837
star
82

mononoke

A Mercurial source control server, specifically designed to support large monorepos.
822
star
83

react-page

Easy Application Development with React JavaScript
JavaScript
795
star
84

f8DeveloperConferenceApp

[Archive] f8 2014 Conference App
HTML
761
star
85

nailgun

Nailgun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead.
Java
734
star
86

WEASEL

DNS covert channel implant for Red Teams.
Python
725
star
87

RiftDK1

Firmware, Schematics, and Mechanicals for the Oculus Rift Development Kit 1
C
688
star
88

jcommon

concurrency, collections, stats/analytics, config, testing, etc
Java
677
star
89

proguard

A fork of ProGuard.
Java
661
star
90

bootstrapped

Generate bootstrapped confidence intervals for A/B testing in Python.
Python
631
star
91

ig-lazy-module-loader

Library that implements module lazy loading.
Java
630
star
92

opencompute

A community of engineers whose mission is to design and enable the delivery of the most efficient server, storage and data center hardware designs for scalable computing.
TeX
624
star
93

flint

An open-source lint program for C++ developed by, and formerly used at Facebook.
D
622
star
94

fblualib

Facebook libraries and utilities for Lua
Lua
615
star
95

remodel

Remodel is a tool that helps iOS and OS X developers avoid repetitive code by generating Objective-C models that support coding, value comparison, and immutability.
TypeScript
609
star
96

eyescream

natural image generation using ConvNets
Lua
599
star
97

react-python

Python bridge to JSX & the React JavaScript library.
Python
576
star
98

spacetime

Experimental iOS library for live transformations on parts of layers.
Objective-C
528
star
99

warp

A fast preprocessor for C and C++
D
521
star
100

FBNotifications

Facebook Analytics In-App Notifications Framework
Objective-C
494
star