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