File: AnimationClipCreator.js

package info (click to toggle)
three.js 111%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,184 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (125 lines) | stat: -rw-r--r-- 2,833 bytes parent folder | download | duplicates (2)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
 *
 * Creator of typical test AnimationClips / KeyframeTracks
 *
 * @author Ben Houston / http://clara.io/
 * @author David Sarno / http://lighthaus.us/
 */

import {
	AnimationClip,
	BooleanKeyframeTrack,
	ColorKeyframeTrack,
	NumberKeyframeTrack,
	Vector3,
	VectorKeyframeTrack
} from "../../../build/three.module.js";

var AnimationClipCreator = function () {};

AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {

	var times = [ 0, period ], values = [ 0, 360 ];

	axis = axis || 'x';
	var trackName = '.rotation[' + axis + ']';

	var track = new NumberKeyframeTrack( trackName, times, values );

	return new AnimationClip( null, period, [ track ] );

};

AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {

	var times = [ 0, period ], values = [ 0, 1 ];

	axis = axis || 'x';
	var trackName = '.scale[' + axis + ']';

	var track = new NumberKeyframeTrack( trackName, times, values );

	return new AnimationClip( null, period, [ track ] );

};

AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {

	var times = [], values = [], tmp = new Vector3();

	for ( var i = 0; i < duration * 10; i ++ ) {

		times.push( i / 10 );

		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 );

	}

	var trackName = '.position';

	var track = new VectorKeyframeTrack( trackName, times, values );

	return new AnimationClip( null, duration, [ track ] );

};


AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {

	var times = [], values = [], tmp = new Vector3();

	for ( var i = 0; i < duration * 10; i ++ ) {

		times.push( i / 10 );

		var scaleFactor = Math.random() * pulseScale;
		tmp.set( scaleFactor, scaleFactor, scaleFactor ).
			toArray( values, values.length );

	}

	var trackName = '.scale';

	var track = new VectorKeyframeTrack( trackName, times, values );

	return new AnimationClip( null, duration, [ track ] );

};


AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {

	var times = [ 0, duration / 2, duration ], values = [ true, false, true ];

	var trackName = '.visible';

	var track = new BooleanKeyframeTrack( trackName, times, values );

	return new AnimationClip( null, duration, [ track ] );

};


AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {

	var times = [], values = [],
		timeStep = duration / colors.length;

	for ( var i = 0; i <= colors.length; i ++ ) {

		times.push( i * timeStep );
		values.push( colors[ i % colors.length ] );

	}

	var trackName = '.material[0].color';

	var track = new ColorKeyframeTrack( trackName, times, values );

	return new AnimationClip( null, duration, [ track ] );

};

export { AnimationClipCreator };