1.1.0 • Published 4 years ago

babylon.simple-animation v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

BABYLON.SimpleAnimation

A collection of helpers to simplify the animation handling.

setup

npm

npm i babylon.simple-animation

ES module

import 'babylon.simple-animation';
import * as BABYLON from 'babylonjs';

Use the tree shaking system.

import {
  SimpleAnimationDelay,
  SimpleParallelAnimationGroup,
  SimplePropertyAnimation,
  SimpleSequentialAnimationGroup,
} from 'babylon.simple-animation/es6';

browser

<script src="https://unpkg.com/babylonjs"></script>
<script src="https://unpkg.com/babylon.simple-animation"></script>

usage

scene.beginSimpleAnimation(
  (new BABYLON.SimpleParallelAnimationGroup()).add(
    new BABYLON.SimplePropertyAnimation({
      target: scene.getMeshByName('box'),
      property: 'scaling.z',
      to: 1/8,
      duration: 2000,
    }),
    (new BABYLON.SimpleSequentialAnimationGroup()).add(
      ...scene.getMeshesByTags('sphere').map(mesh =>
        (new BABYLON.SimpleSequentialAnimationGroup()).add(
          new BABYLON.SimplePropertyAnimation({
            target: mesh,
            property: 'position',
            to: BABYLON.Vector3.Zero(),
            duration: 1000,
            easing: new BABYLON.CircleEase(),
          }),
          new BABYLON.SimpleAnimationDelay(1000),
          new BABYLON.SimplePropertyAnimation({
            target: mesh,
            property: 'visibility',
            to: 0,
            duration: 1000,
          }),          
        )
      )
    ),
  )
);

classes

SimpleAnimation

abstract

instance properties

.onAnimationStartObservable

An instance of Observable. An event is triggered before the animation starts.


.onAnimationEndObservable

An instance of Observable. An event is triggered after the animation ends.

SimplePropertyAnimation

An animated property.

hierarchy

  • SimpleAnimation

constructor

new BABYLON.SimplePropertyAnimation({
  target,
  property,
  type,
  from,
  to,
  duration,
  easing,
})
argumentdescription
targetThe target.
propertyA string as a path to the property.
typeThe type of the animation. If omitted, the starting value of the property is used to guess it.
fromThe starting value of the property. If omitted, the current value of the property is used.
toThe ending value of the property.
durationA number as the duration.
easingAn instance of EasingFunction as the easing function.

instance properties

.target

.property

.type

.from

.to

.duration

.easing

SimpleAnimationDelay

A delay between animations.

hierarchy

  • SimpleAnimation

constructor

new BABYLON.SimpleAnimationDelay(duration)

argumentdescription
durationA number as the duration.

instance properties

.duration

SimpleAnimationGroup

abstract

hierarchy

  • SimpleAnimation

instance properties

.duration

read-only

A number as the duration.

instance functions

.add(...animations)

Adds animations to the group.

argumentdescription
...An instance of SimpleAnimation as the animation to add.

Returns the instance to allow chaining.

SimpleParallelAnimationGroup

A parallel group of animations.

hierarchy

  • SimpleAnimation
  • SimpleAnimationGroup

constructor

new BABYLON.SimpleParallelAnimationGroup()

SimpleSequentialAnimationGroup

A sequential group of animations.

hierarchy

  • SimpleAnimation
  • SimpleAnimationGroup

constructor

new BABYLON.SimpleSequentialAnimationGroup()

SimpleStaggeredAnimationGroup

A staggered group of animations.

hierarchy

  • SimpleAnimation
  • SimpleAnimationGroup

constructor

new BABYLON.SimpleStaggeredAnimationGroup(delay)

argumentdescription
delayA function to calculate the delay between the start times of each animation. The function starts calling from the second animation in the group.

delay(index, length, currentAnimation, previousAnimation)

argumentdescription
indexA number as the index of the current animation in the group.
lengthA number as the count of the animations in the group.
currentAnimationAn instance of SimpleAnimation as the current animation.
previousAnimationAn instance of SimpleAnimation as the previous animation.

Scene

instance functions

.beginSimpleAnimation(animation)

Begins the animation.

argumentdescription
animationAn instance of SimpleAnimation as the animation to begin.