浏览代码

Ported AnimationClipCreator.

tschw 9 年之前
父节点
当前提交
22d94d8578
共有 1 个文件被更改,包括 33 次插入57 次删除
  1. 33 57
      examples/js/AnimationClipCreator.js

+ 33 - 57
examples/js/AnimationClipCreator.js

@@ -1,7 +1,7 @@
 /**
  *
  * Creator of typical test AnimationClips / KeyframeTracks
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -11,73 +11,64 @@ THREE.AnimationClipCreator = function() {
 
 THREE.AnimationClipCreator.CreateRotationAnimation = function( period, axis ) {
 
-	var keys = [];
-	keys.push( { time: 0, value: 0 } );
-	keys.push( { time: period, value: 360 } );
+	var times = [ 0, period ], values = [ 0, 360 ];
 
 	axis = axis || 'x';
 	var trackName = '.rotation[' + axis + ']';
 
-	var track = new THREE.NumberKeyframeTrack( trackName, keys );
+	var track = new THREE.NumberKeyframeTrack( trackName, times, values );
 
-	var clip = new THREE.AnimationClip( 'rotate.x', 10, [ track ] );
-	//console.log( 'rotateClip', clip );
+	return new THREE.AnimationClip( null, period, [ track ] );
 
-	return clip;
 };
 
 THREE.AnimationClipCreator.CreateScaleAxisAnimation = function( period, axis ) {
 
-	var keys = [];
-	keys.push( { time: 0, value: 0 } );
-	keys.push( { time: period, value: 360 } );
+	var times = [ 0, period ], values = [ 0, 1 ];
 
 	axis = axis || 'x';
 	var trackName = '.scale[' + axis + ']';
 
-	var track = new THREE.NumberKeyframeTrack( trackName, keys );
+	var track = new THREE.NumberKeyframeTrack( trackName, times, values );
 
-	var clip = new THREE.AnimationClip( 'scale.x', 10, [ track ] );
-	//console.log( 'scaleClip', clip );
+	return new THREE.AnimationClip( null, period, [ track ] );
 
-	return clip;
 };
 
 THREE.AnimationClipCreator.CreateShakeAnimation = function( duration, shakeScale ) {
 
-	var keys = [];
+	var times = [], values = [], tmp = new THREE.Vector3();
 
 	for( var i = 0; i < duration * 10; i ++ ) {
 
-		keys.push( { 
-			time: ( i / 10.0 ),
-			value: new THREE.Vector3( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale )
-		} );
+		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 THREE.VectorKeyframeTrack( trackName, keys );
+	var track = new THREE.VectorKeyframeTrack( trackName, times, values );
 
-	var clip = new THREE.AnimationClip( 'shake' + duration, duration, [ track ] );
-	//console.log( 'shakeClip', clip );
+	return new THREE.AnimationClip( null, duration, [ track ] );
 
-	return clip;
 };
 
 
 THREE.AnimationClipCreator.CreatePulsationAnimation = function( duration, pulseScale ) {
 
-	var keys = [];
+	var times = [], values = [], tmp = new THREE.Vector3();
 
 	for( var i = 0; i < duration * 10; i ++ ) {
 
+		times.push( i / 10 );
+
 		var scaleFactor = Math.random() * pulseScale;
-		keys.push( {
-			time: ( i / 10.0 ),
-			value: new THREE.Vector3( scaleFactor, scaleFactor, scaleFactor )
-		} );
+		tmp.set( scaleFactor, scaleFactor, scaleFactor ).
+			toArray( values, values.length );
 
 	}
 
@@ -85,55 +76,40 @@ THREE.AnimationClipCreator.CreatePulsationAnimation = function( duration, pulseS
 
 	var track = new THREE.VectorKeyframeTrack( trackName, keys );
 
-	var clip = new THREE.AnimationClip( 'scale' + duration, duration, [ track ] );
-	//console.log( 'scaleClip', clip );
+	return new THREE.AnimationClip( null, duration, [ track ] );
 
-	return clip;
 };
 
 
 THREE.AnimationClipCreator.CreateVisibilityAnimation = function( duration ) {
 
-	var keys = [];
-	keys.push( {
-		time: 0,
-		value: true
-	} );
-	keys.push( {
-		time: duration - 1,
-		value: false
-	} );
-	keys.push( {
-		time: duration,
-		value: true
-	} );
+	var times = [ 0, duration / 2, duration ], values = [ true, false, true ];
 
 	var trackName = '.visible';
 
-	var track = new THREE.BooleanKeyframeTrack( trackName, keys );
+	var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
 
-	var clip = new THREE.AnimationClip( 'visible' + duration, duration, [ track ] );
-	//console.log( 'scaleClip', clip );
+	return new THREE.AnimationClip( null, duration, [ track ] );
 
-	return clip;
 };
 
 
 THREE.AnimationClipCreator.CreateMaterialColorAnimation = function( duration, colors, loop ) {
 
-	var timeStep = duration / colors.length;
-	var keys = [];
+	var times = [], values = [],
+		timeStep = duration / colors.length;
+
 	for( var i = 0; i <= colors.length; i ++ ) {
-		keys.push( { time: i * timeStep, value: colors[ i % colors.length ] } );
+
+		timees.push( i * timeStep );
+		values.push( colors[ i % colors.length ] );
+
 	}
 
 	var trackName = '.material[0].color';
 
-	var track = new THREE.ColorKeyframeTrack( trackName, keys );
+	var track = new THREE.ColorKeyframeTrack( trackName, times, values );
 
-	var clip = new THREE.AnimationClip( 'colorDiffuse', 10, [ track ] );
-	//console.log( 'diffuseClip', clip );
+	return new THREE.AnimationClip( null, duration, [ track ] );
 
-	return clip;
 };
-