Skip to content

Commit 69f31f5

Browse files
committed
代码提交
1 parent 243ec3f commit 69f31f5

29 files changed

+10879
-0
lines changed

njs/AnimationClipCreator.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
*
3+
* Creator of typical test AnimationClips / KeyframeTracks
4+
*
5+
* @author Ben Houston / http://clara.io/
6+
* @author David Sarno / http://lighthaus.us/
7+
*/
8+
9+
THREE.AnimationClipCreator = function () {};
10+
11+
THREE.AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
12+
13+
var times = [ 0, period ], values = [ 0, 360 ];
14+
15+
axis = axis || 'x';
16+
var trackName = '.rotation[' + axis + ']';
17+
18+
var track = new THREE.NumberKeyframeTrack( trackName, times, values );
19+
20+
return new THREE.AnimationClip( null, period, [ track ] );
21+
22+
};
23+
24+
THREE.AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
25+
26+
var times = [ 0, period ], values = [ 0, 1 ];
27+
28+
axis = axis || 'x';
29+
var trackName = '.scale[' + axis + ']';
30+
31+
var track = new THREE.NumberKeyframeTrack( trackName, times, values );
32+
33+
return new THREE.AnimationClip( null, period, [ track ] );
34+
35+
};
36+
37+
THREE.AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
38+
39+
var times = [], values = [], tmp = new THREE.Vector3();
40+
41+
for ( var i = 0; i < duration * 10; i ++ ) {
42+
43+
times.push( i / 10 );
44+
45+
tmp.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+
49+
}
50+
51+
var trackName = '.position';
52+
53+
var track = new THREE.VectorKeyframeTrack( trackName, times, values );
54+
55+
return new THREE.AnimationClip( null, duration, [ track ] );
56+
57+
};
58+
59+
60+
THREE.AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
61+
62+
var times = [], values = [], tmp = new THREE.Vector3();
63+
64+
for ( var i = 0; i < duration * 10; i ++ ) {
65+
66+
times.push( i / 10 );
67+
68+
var scaleFactor = Math.random() * pulseScale;
69+
tmp.set( scaleFactor, scaleFactor, scaleFactor ).
70+
toArray( values, values.length );
71+
72+
}
73+
74+
var trackName = '.scale';
75+
76+
var track = new THREE.VectorKeyframeTrack( trackName, times, values );
77+
78+
return new THREE.AnimationClip( null, duration, [ track ] );
79+
80+
};
81+
82+
83+
THREE.AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
84+
85+
var times = [ 0, duration / 2, duration ], values = [ true, false, true ];
86+
87+
var trackName = '.visible';
88+
89+
var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
90+
91+
return new THREE.AnimationClip( null, duration, [ track ] );
92+
93+
};
94+
95+
96+
THREE.AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
97+
98+
var times = [], values = [],
99+
timeStep = duration / colors.length;
100+
101+
for ( var i = 0; i <= colors.length; i ++ ) {
102+
103+
times.push( i * timeStep );
104+
values.push( colors[ i % colors.length ] );
105+
106+
}
107+
108+
var trackName = '.material[0].color';
109+
110+
var track = new THREE.ColorKeyframeTrack( trackName, times, values );
111+
112+
return new THREE.AnimationClip( null, duration, [ track ] );
113+
114+
};

0 commit comments

Comments
 (0)