-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththree-animation.component.ts
96 lines (81 loc) · 2.18 KB
/
three-animation.component.ts
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
import {
Component,
Input,
OnDestroy,
AfterViewInit,
ViewChild,
ElementRef,
Renderer2, Output, EventEmitter,
} from '@angular/core';
import { AnimationService } from './services/animation.service';
@Component({
selector: 'app-three-animation',
templateUrl: './three-animation.component.html',
styleUrls: ['./three-animation.component.css']
})
export class ThreeAnimationComponent implements OnDestroy, AfterViewInit {
@Input() animation: AnimationService;
// tslint:disable-next-line:no-output-on-prefix
@Output() onStart = new EventEmitter<any>();
// tslint:disable-next-line:no-output-on-prefix
@Output() onUpdate = new EventEmitter<any>();
// tslint:disable-next-line:no-output-on-prefix
@Output() onFrameChange = new EventEmitter<any>();
// tslint:disable-next-line:no-output-on-prefix
@Output() onEnd = new EventEmitter<any>();
// tslint:disable-next-line:variable-name
constructor(public elementRef: ElementRef, public renderer2: Renderer2) {
}
@ViewChild('animationContainer', {static: false}) containerElement: ElementRef;
container;
ngOnDestroy() {
this.animation.destroy();
}
ngAfterViewInit() {
this.init();
this.animation.init();
this.container = this.containerElement.nativeElement;
this.animation.setupAnimationContainer(this.container, this.renderer2);
this.animation.onStart((e) => {
this.triggerStart(e);
});
this.animation.onFrameChange((e) => {
this.triggerFrameChange(e);
});
this.animation.onUpdate((e) => {
this.triggerUpdate(e);
});
this.animation.onUpdate((e) => {
this.triggerEnd(e);
});
}
onKeyDown(event) {
this.animation.onKeyDown(event);
}
onKeyUp(event) {
this.animation.onKeyUp(event);
}
triggerStart(event) {
this.start();
this.onStart.emit(event);
}
triggerFrameChange(event) {
this.frameChange();
this.onFrameChange.emit(event);
}
triggerUpdate(event) {
this.onUpdate.emit(event);
}
triggerEnd(event) {
this.onEnd.emit(event);
}
init() {
// stuff before starting animation
}
start() {
// stuff when animation scene ready
}
frameChange() {
// stuff for every frame
}
}