@@ -7,98 +7,98 @@ import {
7
7
VectorKeyframeTrack ,
8
8
} from 'three'
9
9
10
- const AnimationClipCreator = ( ) => { }
10
+ class AnimationClipCreator {
11
+ static CreateRotationAnimation ( period , axis = 'x' ) {
12
+ const times = [ 0 , period ] ,
13
+ values = [ 0 , 360 ]
11
14
12
- AnimationClipCreator . CreateRotationAnimation = ( period , axis ) => {
13
- const times = [ 0 , period ] ,
14
- values = [ 0 , 360 ]
15
+ const trackName = '.rotation[' + axis + ']'
15
16
16
- axis = axis || 'x'
17
- const trackName = `.rotation[${ axis } ]`
17
+ const track = new NumberKeyframeTrack ( trackName , times , values )
18
18
19
- const track = new NumberKeyframeTrack ( trackName , times , values )
19
+ return new AnimationClip ( null , period , [ track ] )
20
+ }
20
21
21
- return new AnimationClip ( null , period , [ track ] )
22
- }
22
+ static CreateScaleAxisAnimation ( period , axis = 'x' ) {
23
+ const times = [ 0 , period ] ,
24
+ values = [ 0 , 1 ]
23
25
24
- AnimationClipCreator . CreateScaleAxisAnimation = ( period , axis ) => {
25
- const times = [ 0 , period ] ,
26
- values = [ 0 , 1 ]
26
+ const trackName = '.scale[' + axis + ']'
27
27
28
- axis = axis || 'x'
29
- const trackName = `.scale[${ axis } ]`
28
+ const track = new NumberKeyframeTrack ( trackName , times , values )
30
29
31
- const track = new NumberKeyframeTrack ( trackName , times , values )
30
+ return new AnimationClip ( null , period , [ track ] )
31
+ }
32
32
33
- return new AnimationClip ( null , period , [ track ] )
34
- }
33
+ static CreateShakeAnimation ( duration , shakeScale ) {
34
+ const times = [ ] ,
35
+ values = [ ] ,
36
+ tmp = new Vector3 ( )
35
37
36
- AnimationClipCreator . CreateShakeAnimation = ( duration , shakeScale ) => {
37
- const times = [ ] ,
38
- values = [ ] ,
39
- tmp = new Vector3 ( )
38
+ for ( let i = 0 ; i < duration * 10 ; i ++ ) {
39
+ times . push ( i / 10 )
40
40
41
- for ( let i = 0 ; i < duration * 10 ; i ++ ) {
42
- times . push ( i / 10 )
41
+ tmp
42
+ . set ( Math . random ( ) * 2.0 - 1.0 , Math . random ( ) * 2.0 - 1.0 , Math . random ( ) * 2.0 - 1.0 )
43
+ . multiply ( shakeScale )
44
+ . toArray ( values , values . length )
45
+ }
43
46
44
- tmp
45
- . set ( Math . random ( ) * 2.0 - 1.0 , Math . random ( ) * 2.0 - 1.0 , Math . random ( ) * 2.0 - 1.0 )
46
- . multiply ( shakeScale )
47
- . toArray ( values , values . length )
48
- }
47
+ const trackName = '.position'
49
48
50
- const trackName = '.position'
49
+ const track = new VectorKeyframeTrack ( trackName , times , values )
51
50
52
- const track = new VectorKeyframeTrack ( trackName , times , values )
51
+ return new AnimationClip ( null , duration , [ track ] )
52
+ }
53
53
54
- return new AnimationClip ( null , duration , [ track ] )
55
- }
54
+ static CreatePulsationAnimation ( duration , pulseScale ) {
55
+ const times = [ ] ,
56
+ values = [ ] ,
57
+ tmp = new Vector3 ( )
56
58
57
- AnimationClipCreator . CreatePulsationAnimation = ( duration , pulseScale ) => {
58
- const times = [ ] ,
59
- values = [ ] ,
60
- tmp = new Vector3 ( )
59
+ for ( let i = 0 ; i < duration * 10 ; i ++ ) {
60
+ times . push ( i / 10 )
61
61
62
- for ( let i = 0 ; i < duration * 10 ; i ++ ) {
63
- times . push ( i / 10 )
62
+ const scaleFactor = Math . random ( ) * pulseScale
63
+ tmp . set ( scaleFactor , scaleFactor , scaleFactor ) . toArray ( values , values . length )
64
+ }
64
65
65
- const scaleFactor = Math . random ( ) * pulseScale
66
- tmp . set ( scaleFactor , scaleFactor , scaleFactor ) . toArray ( values , values . length )
67
- }
66
+ const trackName = '.scale'
68
67
69
- const trackName = '.scale'
68
+ const track = new VectorKeyframeTrack ( trackName , times , values )
70
69
71
- const track = new VectorKeyframeTrack ( trackName , times , values )
70
+ return new AnimationClip ( null , duration , [ track ] )
71
+ }
72
72
73
- return new AnimationClip ( null , duration , [ track ] )
74
- }
73
+ static CreateVisibilityAnimation ( duration ) {
74
+ const times = [ 0 , duration / 2 , duration ] ,
75
+ values = [ true , false , true ]
75
76
76
- AnimationClipCreator . CreateVisibilityAnimation = ( duration ) => {
77
- const times = [ 0 , duration / 2 , duration ] ,
78
- values = [ true , false , true ]
77
+ const trackName = '.visible'
79
78
80
- const trackName = '.visible'
79
+ const track = new BooleanKeyframeTrack ( trackName , times , values )
81
80
82
- const track = new BooleanKeyframeTrack ( trackName , times , values )
81
+ return new AnimationClip ( null , duration , [ track ] )
82
+ }
83
83
84
- return new AnimationClip ( null , duration , [ track ] )
85
- }
84
+ static CreateMaterialColorAnimation ( duration , colors ) {
85
+ const times = [ ] ,
86
+ values = [ ] ,
87
+ timeStep = duration / colors . length
86
88
87
- AnimationClipCreator . CreateMaterialColorAnimation = ( duration , colors ) => {
88
- const times = [ ] ,
89
- values = [ ] ,
90
- timeStep = duration / colors . length
89
+ for ( let i = 0 ; i < colors . length ; i ++ ) {
90
+ times . push ( i * timeStep )
91
91
92
- for ( let i = 0 ; i <= colors . length ; i ++ ) {
93
- times . push ( i * timeStep )
94
- values . push ( colors [ i % colors . length ] )
95
- }
92
+ const color = colors [ i ]
93
+ values . push ( color . r , color . g , color . b )
94
+ }
96
95
97
- const trackName = '.material[0] .color'
96
+ const trackName = '.material.color'
98
97
99
- const track = new ColorKeyframeTrack ( trackName , times , values )
98
+ const track = new ColorKeyframeTrack ( trackName , times , values )
100
99
101
- return new AnimationClip ( null , duration , [ track ] )
100
+ return new AnimationClip ( null , duration , [ track ] )
101
+ }
102
102
}
103
103
104
104
export { AnimationClipCreator }
0 commit comments