-
Notifications
You must be signed in to change notification settings - Fork 24
/
Async_Await_boomboxExample.js
99 lines (70 loc) · 3.15 KB
/
Async_Await_boomboxExample.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// How to load in modules
const Animation = require('Animation');
const Scene = require('Scene');
const TouchGestures = require('TouchGestures');
// Use export keyword to make a symbol available in scripting debug console
export const Diagnostics = require('Diagnostics');
export const sceneRoot = Scene.root;
// Enables async/await in JS [part 1]
(async function() {
// To access scene objects
const [base_jnt,speaker_left_jnt,speaker_right_jnt,planeTracker0,placer] = await Promise.all([
sceneRoot.findFirst('base_jnt'),
sceneRoot.findFirst('speaker_left_jnt'),
sceneRoot.findFirst('speaker_right_jnt'),
sceneRoot.findFirst('planeTracker0'),
sceneRoot.findFirst('placer')
]);
const baseDriverParameters = {
durationMilliseconds: 400,
loopCount: Infinity,
mirror: true
};
const baseDriver = Animation.timeDriver(baseDriverParameters);
baseDriver.start();
const baseSampler = Animation.samplers.easeInQuint(0.9, 1);
const baseAnimation = await Animation.animate(baseDriver,baseSampler);
const baseTransform = await base_jnt.transform;
baseTransform.scaleX = await baseAnimation;
baseTransform.scaleY = await baseAnimation;
baseTransform.scaleZ = await baseAnimation;
const speakerDriverParameters = {
durationMilliseconds: 200,
loopCount: Infinity,
mirror: true
};
const speakerDriver = Animation.timeDriver(speakerDriverParameters);
speakerDriver.start();
const speakerSampler = Animation.samplers.easeOutElastic(0.7, 0.85);
const speakerAnimation = await Animation.animate(speakerDriver,speakerSampler);
const speakerLeftTransform = await speaker_left_jnt.transform;
speakerLeftTransform.scaleX = await speakerAnimation;
speakerLeftTransform.scaleY = await speakerAnimation;
speakerLeftTransform.scaleZ = await speakerAnimation;
const speakerRightTransform = await speaker_right_jnt.transform;
speakerRightTransform.scaleX = await speakerAnimation;
speakerRightTransform.scaleY = await speakerAnimation;
speakerRightTransform.scaleZ = await speakerAnimation;
TouchGestures.onPan().subscribe(function(gesture) {
planeTracker0.trackPoint(gesture.location, gesture.state);
});
const placerTransform = await placer.transform;
TouchGestures.onPinch().subscribeWithSnapshot( {
'lastScaleX' : placerTransform.scaleX,
'lastScaleY' : placerTransform.scaleY,
'lastScaleZ' : placerTransform.scaleZ
}, function (gesture, snapshot) {
placerTransform.scaleX = gesture.scale.mul(snapshot.lastScaleX);
placerTransform.scaleY = gesture.scale.mul(snapshot.lastScaleY);
placerTransform.scaleZ = gesture.scale.mul(snapshot.lastScaleZ);
});
TouchGestures.onRotate().subscribeWithSnapshot( {
'lastRotationY' : placerTransform.rotationY,
}, function (gesture, snapshot) {
const correctRotation = gesture.rotation.mul(-1);
placerTransform.rotationY = correctRotation.add(snapshot.lastRotationY);
});
// To log messages to the console
Diagnostics.log('success.');
// Enables async/await in JS [part 2]
})();