Browse Source

more minor bug fixing with Animation.

Ben Houston 10 years ago
parent
commit
b67cca3636

+ 6 - 2
examples/webgl_animation_track_clip_mixer.html

@@ -258,9 +258,13 @@
 
 
 				mixer = new THREE.AnimationMixer( mesh );
 				mixer = new THREE.AnimationMixer( mesh );
 
 
-				var rotateClip = THREE.AnimationClip.CreateRotationAnimation( 10 );
+				//var clip = THREE.AnimationClip.CreateShakeAnimation( 10, new THREE.Vector3( 10, 10, 10 ) );
+				//var clip = THREE.AnimationClip.CreatePulsationAnimation( 10, 100 );
+				//var clip = THREE.AnimationClip.CreateRotationAnimation( 10, 'x' );
+				var clip = THREE.AnimationClip.CreateScaleAxisAnimation( 10, 'x' );
 
 
-				mixer.addAction( new THREE.AnimationAction( rotateClip, 0, 1, 1, true ) );
+
+				mixer.addAction( new THREE.AnimationAction( clip, 0, 1, 1, true ) );
 
 
 			}
 			}
 
 

+ 21 - 4
src/animation/AnimationClip.js

@@ -211,6 +211,23 @@ THREE.AnimationClip.CreateRotationAnimation = function( period, axis ) {
 	return clip;
 	return clip;
 };
 };
 
 
+THREE.AnimationClip.CreateScaleAxisAnimation = function( period, axis ) {
+
+	var keys = [];
+	keys.push( { time: 0, value: 0 } );
+	keys.push( { time: period, value: 360 } );
+
+	axis = axis || 'x';
+	var trackName = '.scale[' + axis + ']';
+
+	var track = new THREE.KeyframeTrack( trackName, keys );
+
+	var clip = new THREE.AnimationClip( 'scale.x', 10, [ track ] );
+	console.log( 'scaleClip', clip );
+
+	return clip;
+};
+
 THREE.AnimationClip.CreateShakeAnimation = function( duration, shakeScale ) {
 THREE.AnimationClip.CreateShakeAnimation = function( duration, shakeScale ) {
 
 
 	var keys = [];
 	var keys = [];
@@ -228,14 +245,14 @@ THREE.AnimationClip.CreateShakeAnimation = function( duration, shakeScale ) {
 
 
 	var track = new THREE.KeyframeTrack( trackName, keys );
 	var track = new THREE.KeyframeTrack( trackName, keys );
 
 
-	var clip = new THREE.AnimationClip( 'shake' + duration, trackName, [ track ] );
+	var clip = new THREE.AnimationClip( 'shake' + duration, duration, [ track ] );
 	console.log( 'shakeClip', clip );
 	console.log( 'shakeClip', clip );
 
 
 	return clip;
 	return clip;
 };
 };
 
 
 
 
-THREE.AnimationClip.CreatePulsationAnimation = function( node, duration, pulseScale ) {
+THREE.AnimationClip.CreatePulsationAnimation = function( duration, pulseScale ) {
 
 
 	var keys = [];
 	var keys = [];
 
 
@@ -249,11 +266,11 @@ THREE.AnimationClip.CreatePulsationAnimation = function( node, duration, pulseSc
 
 
 	}
 	}
 
 
-	var trackName = node.name + '.scale';
+	var trackName = '.scale';
 
 
 	var track = new THREE.KeyframeTrack( trackName, keys );
 	var track = new THREE.KeyframeTrack( trackName, keys );
 
 
-	var clip = new THREE.AnimationClip( 'scale' + duration, trackName, [ track ] );
+	var clip = new THREE.AnimationClip( 'scale' + duration, duration, [ track ] );
 	console.log( 'scaleClip', clip );
 	console.log( 'scaleClip', clip );
 
 
 	return clip;
 	return clip;

+ 2 - 1
src/animation/KeyframeTrack.js

@@ -14,7 +14,7 @@ THREE.KeyframeTrack = function ( name, keys ) {
 	this.keys = keys || [];	// time in seconds, value as value
 	this.keys = keys || [];	// time in seconds, value as value
 
 
 	// TODO: sort keys via their times
 	// TODO: sort keys via their times
-	this.keys.sort( function( a, b ) { return a.time < b.time; } );
+	//this.keys.sort( function( a, b ) { return a.time < b.time; } );
 
 
 };
 };
 
 
@@ -27,6 +27,7 @@ THREE.KeyframeTrack.prototype = {
 
 
 		if( this.keys.length == 0 ) throw new Error( "no keys in track named " + this.name );
 		if( this.keys.length == 0 ) throw new Error( "no keys in track named " + this.name );
 		
 		
+		console.log( "keys", this.keys );
 		// before the start of the track, return the first key value
 		// before the start of the track, return the first key value
 		if( this.keys[0].time >= time ) {
 		if( this.keys[0].time >= time ) {
 
 

+ 4 - 4
src/animation/PropertyBinding.js

@@ -17,7 +17,7 @@ THREE.PropertyBinding = function ( rootNode, trackName ) {
 	this.nodeName = parseResults.nodeName;
 	this.nodeName = parseResults.nodeName;
 	this.material = parseResults.material;
 	this.material = parseResults.material;
 	this.propertyName = parseResults.propertyName || null;
 	this.propertyName = parseResults.propertyName || null;
-	this.propertyArrayIndex = parseResults.propertyArrayIndex || -1;
+	this.propertySubElement = parseResults.propertySubElement || -1;
 
 
 	this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName );
 	this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName );
 
 
@@ -51,9 +51,9 @@ THREE.PropertyBinding.prototype = {
 		}
 		}
 
 
 		// access a sub element of the property array (only primitives are supported right now)
 		// access a sub element of the property array (only primitives are supported right now)
-		if( this.propertyArrayIndex >= 0 ) {
-			console.log( '  update property array ' + this.propertyName + '[' + this.propertyArrayIndex + '] via assignment.' );				
-			nodeProperty[ this.propertyArrayIndex ] = value;
+		if( ( this.propertySubElement.length && this.propertySubElement.length > 0 ) || this.propertySubElement >= 0 ) {
+			console.log( '  update property array ' + this.propertyName + '[' + this.propertySubElement + '] via assignment.' );				
+			nodeProperty[ this.propertySubElement ] = value;
 		}
 		}
 		// must use copy for Object3D.Euler/Quaternion		
 		// must use copy for Object3D.Euler/Quaternion		
 		else if( nodeProperty.copy ) {
 		else if( nodeProperty.copy ) {