Skip to content

Commit a081bfc

Browse files
committed
animation component, removes a-animation (fixes #1927)
1 parent 2055922 commit a081bfc

File tree

45 files changed

+1989
-2791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1989
-2791
lines changed

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22
.cache
3-
*.swp
3+
*.sw*
44
build
55
firefox/
66
tests/coverage/

‎docs/components/animation.md‎

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
---
2+
title: Animation
3+
type: components
4+
layout: docs
5+
parent_section: components
6+
source_code: src/components/animation.js
7+
examples:
8+
- title: Generated Animations
9+
src: https://glitch.com/~aframe-shooting-stars
10+
---
11+
12+
[animationtimeline]: https://www.npmjs.com/package/aframe-animation-timeline-component
13+
14+
The animation component lets us animate and tween values including:
15+
16+
- Component values (e.g., `position`, `visible`)
17+
- Component property values (e.g., `light.intensity`)
18+
19+
We can also tween values directly for better performance versus going through
20+
`.setAttribute`, such as by animating values:
21+
22+
- On the `object3D` (e.g., `object3D.position.y`, `object3D.rotation.z`)
23+
- Directly within a component (e.g., `components.material.material.color`, `components.text.material.uniforms.opacity.value`),
24+
25+
For example, translating a box:
26+
27+
```html
28+
<a-box position="0 1.6 0" animation="property: position; to: 5 1.6 0; dur: 1500; easing: linear"></a-box>
29+
```
30+
31+
Or orbiting a sphere in a 5-meter radius:
32+
33+
```html
34+
<a-entity rotation="0 0 0" animation="property: rotation; to: 0 360 0; loop: true; dur: 10000">
35+
<a-entity position="5 0 0"></a-entity>
36+
</a-entity>
37+
```
38+
39+
Read more below for additional options and discovering how to properly animate
40+
different types of values.
41+
42+
<!--toc-->
43+
44+
## API
45+
46+
### Properties
47+
48+
| Property | Description | Default Value | Values |
49+
| -------- | ----------- | ------------- | ------ |
50+
| property | Property to animate. Can be a component name, a dot-delimited property of a component (e.g., `material.color`), or a plain attribute. | | |
51+
| isRawProperty | Flag to animate an arbitrary object property outside of A-Frame components for better performance. If set to true, for example, we can set `property` to like `components.material.material.opacity`. If `property` starts with `components` or `object3D`, this will be inferred to `true`. | false | |
52+
| from | Initial value at start of animation. If not specified, the current property value of the entity will be used (will be sampled on each animation start). It is best to specify a `from` value when possible for stability. | null | |
53+
| to | Target value at end of animation. | null | |
54+
| type | Right now only supports `color` for tweening `isRawProperty` color XYZ/RGB vector values. | '' | |
55+
| delay | How long (milliseconds) to wait before starting. | 0 | |
56+
| dir | Which dir to go from `from` to `to`. | normal | alternate, reverse |
57+
| dur | How long (milliseconds) each cycle of the animation is. | 1000 | |
58+
| easing | Easing function of animation. To ease in, ease out, ease in and out. | easeInQuad | See [easings](#easings) |
59+
| elasticity | How much to bounce (higher is stronger). | 400 | |
60+
| loop | How many times the animation should repeat. If the value is `true`, the animation will repeat infinitely. | 0 | |
61+
| round | Whether to round values. | false | |
62+
| startEvents | Comma-separated list of events to listen to trigger a restart and play. Animation will not autoplay if specified. `startEvents` will **restart** the animation, use `pauseEvents` to resume it. If there are other animation components on the entity animating the same property, those animations will be automatically paused to not conflict. | null | |
63+
| pauseEvents | Comma-separated list of events to listen to trigger pause. Can be resumed with `resumeEvents`. | null | |
64+
| resumeEvents | Comma-separated list of events to listen to trigger resume after pausing. | null | |
65+
| autoplay | Whether or not the animation should `autoplay`. Should be specified if the animation is defined for the [`animation-timeline` component][animationtimeline]. | null | |
66+
| enabled | If disabled, animation will stop and startEvents will not trigger animation start. | true |
67+
68+
### Multiple Animations
69+
70+
The component's base name is `animation`. We can attach multiple animations to
71+
one entity by name-spacing the component with double underscores (`__`):
72+
73+
```html
74+
<a-entity animation="property: rotation"
75+
animation__2="property: position"
76+
animation__color="property: material.color"></a-entity>
77+
```
78+
79+
### Easings
80+
81+
Easings define the accelerations and speed throughout the cycle of the
82+
animation.
83+
84+
| easeIn | easeOut | easeInOut | Others |
85+
|---------------|----------------|------------------|--------|
86+
| easeInQuad | easeOutQuad | easeInOutQuad | linear |
87+
| easeInCubic | easeOutCubic | easeInOutCubic | |
88+
| easeInQuart | easeOutQuart | easeInOutQuart | |
89+
| easeInQuint | easeOutQuint | easeInOutQuint | |
90+
| easeInSine | easeOutSine | easeInOutSine | |
91+
| easeInExpo | easeOutExpo | easeInOutExpo | |
92+
| easeInCirc | easeOutCirc | easeInOutCirc | |
93+
| easeInBack | easeOutBack | easeInOutBack | |
94+
| easeInElastic | easeOutElastic | easeInOutElastic | |
95+
96+
### Events
97+
98+
| Property | Description |
99+
| -------- | ----------- |
100+
| animationbegin | Animation began. Event detail contains `name` of animation. |
101+
| animationcomplete | Animation completed. Event detail contains `name` of animation. |
102+
103+
### Members
104+
105+
Accessed as `el.components.animation.<MEMBER>`.
106+
107+
| Member | Description |
108+
|-----------|----------------------------|
109+
| animation | anime.js object. |
110+
| config | Config passed to anime.js. |
111+
112+
## Animating Different Types of Values
113+
114+
We'll go over different cases of animating different types of values.
115+
116+
### Component Values
117+
118+
We can animate a single-property component value (e.g., `property: visible`,
119+
we'll go over booleans in a bit) or animate a property of a multi-property
120+
component using a dot `.` as a separator (e.g., `property: light.intensity`,
121+
`property: material.color`).
122+
123+
If the property is a `vec3`, that is also supported (e.g., `property:
124+
someComponent.vec3Value; to: 5 5 5`).
125+
126+
However, animating component values this way is not the most optimal way as it
127+
will invoke `.setAttribute` on each frame of the animation. For an animation
128+
here or there, it won't be a big deal, but we can save time and memory by
129+
animating values directly.
130+
131+
A special note to try not to animate values of the `geometry` component as that
132+
will recreate the geometry on each tick. Rather animate `scale` if we want to
133+
animate the size.
134+
135+
### Boolean Values
136+
137+
We can "animate" boolean values where the `to` value will be applied at the end
138+
of the animation. Like `property: visible; from: false; to: true; dur: 1`.
139+
140+
### Direct Values through `object3D` and `components`
141+
142+
The animation component supports animating values directly through `object3D`
143+
or `components`.
144+
145+
For example, we can animate values on `object3D` like `property:
146+
object3D.position.z; to: 5` which will tween the entity's `object3D.position.z`
147+
value directly without calling `.setAttribute`; it's the most direct way and
148+
lets us animate a single axis at a time. Note, for `object3D.rotation`, degrees
149+
are used.
150+
151+
Or we can animate values by reaching into `components`. For example, rather than
152+
animating `property: material.opacity` which would call `.setAttribute` on each
153+
frame, we can animate the opacity value directly with `property:
154+
components.material.material.opacity`. We use a dot-delimited path to walk the
155+
object tree to find the value we want to animate, and the animation process
156+
under the hood reduces down to changing a number.
157+
158+
#### Direct Color Values
159+
160+
We can animate three.js color values directly, but we'll need to specify `type:
161+
color`. So rather than animating `property: material.color`, we can do
162+
`property: components.material.material.color; type: color`.
163+
164+
A note on color values, we can specify color values using hex, color names,
165+
hsl, or rgb (e.g., `from: red; to: #FFCCAA` or `from: rgb(100, 100, 100); to:
166+
hsl(213, 100%, 70%)`)..
167+
168+
## Using anime.js Directly
169+
170+
anime is a popular and powerful animation engine. The component prefers to do
171+
just basic tweening and touches the surface of what anime can do (e.g.,
172+
timelines, motion paths, progress, seeking). If we need more animation
173+
features, create a separate component that invokes anime.js directly. anime is
174+
accessible via **`AFRAME.ANIME`**.
175+
176+
Read through and explore the [anime.js
177+
documentation](https://github.com/juliangarnier/anime) and
178+
[website](https://animejs.com).
179+
180+
## See Also
181+
182+
- [animation-timeline component][animationtimeline]

‎docs/components/cursor.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ interactions is that it requires the user to turn their head a lot.
160160

161161
## Adding Visual Feedback
162162

163-
[animation]: ../core/animations.md
163+
[animation]: ./animation.md
164164

165165
To add visual feedback to the cursor to show when the cursor is clicking or
166166
fusing, we can use the [animation system][animation]. When the cursor

0 commit comments

Comments
 (0)