All Projects → MaciejWWojcik → three-plain-animator

MaciejWWojcik / three-plain-animator

Licence: MIT license
Three-Plain-Animator is a package for threejs developers to support 2D animations.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to three-plain-animator

building-editor
3D model editor for building/architecture
Stars: ✭ 24 (-57.14%)
Mutual labels:  threejs
three-strip
Generate strip geometry for three.js. Supports taper, twist, dasharray and uvgen.
Stars: ✭ 15 (-73.21%)
Mutual labels:  threejs
three-mithril-ts
THREE.js, Mithril.js, TypeScript starter project
Stars: ✭ 34 (-39.29%)
Mutual labels:  threejs
three-vue-pattern
A biofeedback visualization made with Three.js, Vue, and LUIS (cognitive services), made with Brian Holt
Stars: ✭ 97 (+73.21%)
Mutual labels:  threejs
icosa-viewer
3D Viewer component for Tilt Brush / Open Brush, Google Blocks files and their derivatives
Stars: ✭ 24 (-57.14%)
Mutual labels:  threejs
home
Community for parametric furniture designs.
Stars: ✭ 44 (-21.43%)
Mutual labels:  threejs
cuber
优美而强大的网页魔方
Stars: ✭ 32 (-42.86%)
Mutual labels:  threejs
tycho
🪐 A real-time, WebGL-based interactive simulation of our solar system.
Stars: ✭ 90 (+60.71%)
Mutual labels:  threejs
codrops-texture-projection
Article about Texture Projection in Three.js
Stars: ✭ 75 (+33.93%)
Mutual labels:  threejs
Photo-Sphere-Viewer
A JavaScript library to display Photo Sphere panoramas.
Stars: ✭ 1,198 (+2039.29%)
Mutual labels:  threejs
DepthKit-A-Frame
🎥 An A-Frame component for rendering DepthKit volumetric videos in WebVR
Stars: ✭ 34 (-39.29%)
Mutual labels:  threejs
react-with-threejs-example
An example project integrating React with three.js
Stars: ✭ 27 (-51.79%)
Mutual labels:  threejs
Big-Data-Demo
基于Vue、three.js、echarts,数据可视化展示项目,包含三维模型导入交互、三维模型标注等功能
Stars: ✭ 146 (+160.71%)
Mutual labels:  threejs
frontend-park
哈喽大家好~我是荣顶!这是一个有趣的前端趣味知识公园~该项目是我平时捣鼓前端相关技术的一些案例集合。
Stars: ✭ 66 (+17.86%)
Mutual labels:  threejs
three-to-cannon
Convert a THREE.Mesh to a CANNON.Shape.
Stars: ✭ 207 (+269.64%)
Mutual labels:  threejs
detect-gpu
Classifies GPUs based on their 3D rendering benchmark score allowing the developer to provide sensible default settings for graphically intensive applications.
Stars: ✭ 749 (+1237.5%)
Mutual labels:  threejs
gamedex
👾 The code for my game dev + computer graphics experiments on YouTube.
Stars: ✭ 165 (+194.64%)
Mutual labels:  threejs
vuletube
Starter project for vue in combination with typescript. Getting response for youtube search. Call server part for saving videos. Use videos in three.js 3d port view. Control vuletube site with hands (NUI) also with voice command.
Stars: ✭ 12 (-78.57%)
Mutual labels:  threejs
generative
Creative coding experiments
Stars: ✭ 71 (+26.79%)
Mutual labels:  threejs
WebGL-Billiards
ThreeJS based 8-ball pool
Stars: ✭ 28 (-50%)
Mutual labels:  threejs

Welcome to three-plain-animator

Three-Plain-Animator is a package for threejs developers to support 2D animations.

npm version TypeScript

Example

Installation

The package is available via npm: three-plain-animator

npm i three-plain-animator

Usage

There are two main classes to work with:

  • PlainAnimator
  • PlainSingularAnimator

The first one is for continuous animations like walking. The second one is for animation that should run only once and then stop on the last frame of the animation.

Example

This is a simple example with Homer Simpson animation gif for reference. I assume that creating a basic scene using threejs is not a part of this example. So I will show only unnecessary code just to not mess around.

I converted gif to sprite and uploaded this on imgur.

The first step is to create texture just like every texture using threejs.

const texturePath =  'https://i.imgur.com/Oj6RJV9.png';
const spriteTexture = new  THREE.TextureLoader().load(texturePath)

Next step is about creating the animator object:

 const animator =  new  PlainAnimator(spriteTexture, 4, 4, 10, 15);

These magic numbers are the follows: |value| description | |--|--| | 4 | number of frames horizontally | | 4 | number of frames vertically | | 10 | total number of frames | | 15 | frames per second (fps) |

Then the final texture could be get using init() method:

const texture = animator.init();

To animate texture it's required to animate texture in the main loop of rendering

animator.animate();

So for instance, you can use it as follows:

function animate() {
  renderer.render(scene, camera);
  animator.animate(); // update the animation
  requestAnimationFrame(animate);
}

animate();

Full code:

const texturePath =  'https://i.imgur.com/Oj6RJV9.png';
const spriteTexture = new  THREE.TextureLoader().load(texturePath)
const animator =  new  PlainAnimator(spriteTexture, 4, 4, 10, 15);

const texture = animator.init();    

const geometry =  new  THREE.PlaneGeometry(512,  512);
const material =  new  THREE.MeshBasicMaterial({ map: texture, transparent:  true  });

let mesh =  new  THREE.Mesh(geometry, material)

There is working code on stackblitz with this example:

Docs

Read docs here.

Requierments

The package requires threejs library

Support

The package supports TypeScript and contains typescript definitions.

Future work & TODO

  1. GIF files support
  2. Tests

Feel free to ask any questions. Post on GitHub or write to me: [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].