-
Notifications
You must be signed in to change notification settings - Fork 24
/
EmitterParticleFade.js
63 lines (58 loc) · 2.23 KB
/
EmitterParticleFade.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// In this script we show how to fade out particles from
// a emitter.
//
// Original post was created by Josh Beckwith
// URL: https://www.facebook.com/groups/SparkARcommunity/permalink/683989935346385/
//
//
// Include modules
//
const Scene = require('Scene');
const Animation = require('Animation');
// Load 'emitter0' object.
Scene.root.findFirst('emitter0').then(emitter => {
// emitter0 loaded and ready to be used.
// Animate per channel in a HSVA color model.
// We specify a easing functions for the
// rate of change of a channel over time.
// More info per under channel.
//
// Read more about HSV color model here:
// https://en.wikipedia.org/wiki/HSL_and_HSV
//
// Read more about easing functions here:
// https://easings.net/en
emitter.hsvaColorModulationModifier = Animation.samplers.HSVA([
// H for hue.
// Here we tell the Hue channel should have a constant
// value of 1 during the lifespan of a particle.
// So the Hue vil always stay 1 from start to finish.
Animation.samplers.constant(1),
// S for saturation.
// Here we use contsant again.
Animation.samplers.constant(1),
// V for value.
// And the same here.
Animation.samplers.constant(1),
// A for alpha.
// Here we use a easeInQuad easing function to gradually
// change the Alpha channel value for the particle over time.
// The value will transition from 1 (100% visible) to 0
// (0% visible) with a non-linear speed.
//
// Read more about easeInQuad here:
// https://easings.net/en#easeInQuad
Animation.samplers.easeInQuad(1, 0)
]);
// The same rules can be applied to other particle properties
// such as size. Here we are trying out the easeInCirc easing
// function. All available easing functions in Spark AR
// can be found here:
// https://sparkar.facebook.com/ar-studio/learn/documentation/reference/classes/animationmodule.samplerfactory/
emitter.sizeModifier = Animation.samplers.easeInCirc(0, 0.01);
// Other particle properties that can be modified include
// positionModifier and velocityModifier.
// More information is specified here:
// https://sparkar.facebook.com/ar-studio/learn/documentation/reference/classes/scenemodule.particlesystem
});