-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiview.js
66 lines (56 loc) · 1.81 KB
/
multiview.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
function setup() {
var head = document.head;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'rlottie-wasm.js';
head.appendChild(script);
script.onload = _ => {
Module.onRuntimeInitialized = _ => {
entry = new MainEntry();
var updater = function() {
entry.render();
window.requestAnimationFrame( updater ); // for subsequent frames
};
window.requestAnimationFrame( updater );
};
};
}
setup();
class RLottieView {
constructor(canvasId) {
this.canvasId = canvasId;
this.canvas = document.getElementById(canvasId);
this.context = this.canvas.getContext('2d');
this.lottieHandle = new Module.RlottieWasm();
console.log(this.lottieHandle);
this.frameCount = this.lottieHandle.frames();
this.curFrame = 0;
this.render();
}
render() {
if (this.canvas.width == 0 || this.canvas.height == 0) return;
console.log("render stage ");
if (this.curFrame >= this.frameCount) this.curFrame = 0;
var bufferPointer = this.lottieHandle.render(this.curFrame, 100, 100);
var result = Uint8ClampedArray.from(bufferPointer);
var imageData = new ImageData(result, 100, 100);
this.context.putImageData(imageData, 0, 0);
this.curFrame = this.curFrame + 1;
}
}
class MainEntry {
render() {
this.lottieView1.render();
this.lottieView2.render();
this.lottieView3.render();
this.lottieView4.render();
this.lottieView5.render();
}
constructor() {
this.lottieView1 = new RLottieView("myCanvas");
this.lottieView2 = new RLottieView("myCanvas1");
this.lottieView3 = new RLottieView("myCanvas2");
this.lottieView4 = new RLottieView("myCanvas3");
this.lottieView5 = new RLottieView("myCanvas4");
}
}