Browse Source

add wrap scheduling. updates to MD2Character, USCCharacter.

Ben Houston 10 năm trước cách đây
mục cha
commit
eec2153e7d

+ 2 - 2
examples/js/MD2Character.js

@@ -52,7 +52,7 @@ THREE.MD2Character = function () {
 			scope.root.add( mesh );
 
 			scope.meshBody = mesh;
-			scope.activeAnimation = geo.firstAnimation;
+			scope.activeAnimationClipName = geo.firstAnimationClip.name;
 
 			checkLoadingComplete();
 
@@ -133,7 +133,7 @@ THREE.MD2Character = function () {
 			activeWeapon.visible = true;
 			this.meshWeapon = activeWeapon;
 
-			activeWeapon.playAnimation( this.activeAnimation, this.animationFPS );
+			activeWeapon.playAnimation( this.activeAnimationClipName, this.animationFPS );
 
 			this.meshWeapon.baseDuration = this.meshWeapon.duration;
 

+ 8 - 6
examples/js/UCSCharacter.js

@@ -1,4 +1,4 @@
-THREE.UCSCharacter = function() {
+THREE.UCSCharacterMixer = function() {
 
 	var scope = this;
 	
@@ -15,6 +15,8 @@ THREE.UCSCharacter = function() {
 	this.materials = [];
 	this.morphs = [];
 
+	this.mixer = new THREE.AnimationMixer( this.root );
+
 	this.onLoadComplete = function () {};
 	
 	this.loadCounter = 0;
@@ -41,10 +43,9 @@ THREE.UCSCharacter = function() {
 
 			geometry.computeBoundingBox();
 			geometry.computeVertexNormals();
-
-			//THREE.AnimationHandler.add( geometry.animation );
-
+			
 			mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial() );
+			mesh.name = config.character;
 			scope.root.add( mesh );
 			
 			var bb = geometry.boundingBox;
@@ -54,8 +55,9 @@ THREE.UCSCharacter = function() {
 			mesh.castShadow = true;
 			mesh.receiveShadow = true;
 
-			animation = new THREE.Animation( mesh, geometry.animation );
-			animation.play();
+			var clipBones = THREE.AnimationClip.FromJSONLoaderAnimation( geometry, mesh.uuid );
+
+			scope.mixer.addAction( new THREE.AnimationAction( clipBones, 0, 1, 1, true ) );
 			
 			scope.setSkin( 0 );
 			

+ 0 - 142
examples/js/UCSCharacterMixer.js

@@ -1,142 +0,0 @@
-THREE.UCSCharacterMixer = function() {
-
-	var scope = this;
-	
-	var mesh;
-
-	this.scale = 1;
-
-	this.root = new THREE.Object3D();
-	
-	this.numSkins;
-	this.numMorphs;
-	
-	this.skins = [];
-	this.materials = [];
-	this.morphs = [];
-
-	this.mixer = new THREE.AnimationMixer( this.root );
-
-	this.onLoadComplete = function () {};
-	
-	this.loadCounter = 0;
-
-	this.loadParts = function ( config ) {
-		
-		this.numSkins = config.skins.length;
-		this.numMorphs = config.morphs.length;
-		
-		// Character geometry + number of skins
-		this.loadCounter = 1 + config.skins.length;
-		
-		// SKINS
-		this.skins = loadTextures( config.baseUrl + "skins/", config.skins );
-		this.materials = createMaterials( this.skins );
-		
-		// MORPHS
-		this.morphs = config.morphs;
-		
-		// CHARACTER
-		var loader = new THREE.JSONLoader();
-		console.log( config.baseUrl + config.character );
-		loader.load( config.baseUrl + config.character, function( geometry ) {
-
-			geometry.computeBoundingBox();
-			geometry.computeVertexNormals();
-			
-			mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial() );
-			mesh.name = config.character;
-			scope.root.add( mesh );
-			
-			var bb = geometry.boundingBox;
-			scope.root.scale.set( config.s, config.s, config.s );
-			scope.root.position.set( config.x, config.y - bb.min.y * config.s, config.z );
-
-			mesh.castShadow = true;
-			mesh.receiveShadow = true;
-
-			var clipBones = THREE.AnimationClip.FromJSONLoaderAnimation( geometry, mesh.uuid );
-
-			scope.mixer.addAction( new THREE.AnimationAction( clipBones, 0, 1, 1, true ) );
-			
-			scope.setSkin( 0 );
-			
-			scope.checkLoadComplete();
-
-		} );
-
-	};
-	
-	this.setSkin = function( index ) {
-
-		if ( mesh && scope.materials ) {
-
-			mesh.material = scope.materials[ index ];
-
-		}
-
-	};
-	
-	this.updateMorphs = function( influences ) {
-
-		if ( mesh ) {
-
-			for ( var i = 0; i < scope.numMorphs; i ++ ) {
-
-				mesh.morphTargetInfluences[ i ] = influences[ scope.morphs[ i ] ] / 100;
-
-			}
-
-		}
-
-	};
-	
-	function loadTextures( baseUrl, textureUrls ) {
-
-		var mapping = THREE.UVMapping;
-		var textures = [];
-
-		for ( var i = 0; i < textureUrls.length; i ++ ) {
-
-			textures[ i ] = THREE.ImageUtils.loadTexture( baseUrl + textureUrls[ i ], mapping, scope.checkLoadComplete );
-			textures[ i ].name = textureUrls[ i ];
-
-		}
-
-		return textures;
-
-	}
-
-	function createMaterials( skins ) {
-
-		var materials = [];
-		
-		for ( var i = 0; i < skins.length; i ++ ) {
-
-			materials[ i ] = new THREE.MeshLambertMaterial( {
-				color: 0xeeeeee,
-				specular: 10.0,
-				map: skins[ i ],
-				skinning: true,
-				morphTargets: true
-			} );
-
-		}
-		
-		return materials;
-
-	}
-
-	this.checkLoadComplete = function () {
-
-		scope.loadCounter -= 1;
-
-		if ( scope.loadCounter === 0 ) {
-
-			scope.onLoadComplete();
-
-		}
-
-	}
-
-};

+ 1 - 1
src/animation/AnimationAction.js

@@ -60,7 +60,7 @@ THREE.AnimationAction.prototype = {
 
 		return clipResults;
 		
-	}
+	},
 
 	getWeightAt: function( time ) {
 

+ 22 - 1
src/animation/AnimationMixer.js

@@ -120,10 +120,31 @@ THREE.AnimationMixer.prototype = {
 
 	},
 
-	crossFade: function( fadeOutAction, faceInAction, duration ) {
+	wrap: function( action, startTimeScale, endTimeScale, duration ) {
+
+		var keys = [];
+		
+		keys.push( { time: this.time, value: startTimeScale } );
+		keys.push( { time: this.time + duration, value: endTimeScale } );
+		
+		action.timeScale = new THREE.KeyframeTrack( "timeScale", keys );
+
+	}
+
+	crossFade: function( fadeOutAction, fadeInAction, duration, wrapTimeScales ) {
 
 		this.fadeOut( fadeOutAction, duration );
 		this.fadeIn( fadeInAction, duration );
+
+		if( wrapTimeScales ) {
+	
+			var startEndRatio = fadeOutAction.duration / fadeInAction.duration;
+			var endStartRatio = 1.0 / startEndRatio;
+
+			this.wrap( fadeOutAction, 1.0, startEndRatio, duration );
+			this.wrap( fadeInAction, endStartRatio, 1.0, duration );
+
+		}
 		
 	},
 

+ 11 - 4
src/animation/PropertyBinding.js

@@ -64,9 +64,16 @@ THREE.PropertyBinding.prototype = {
 
 	unbind: function() {
 
-		if( ! this.setValue ) throw new Error( "can not unbind if not bound in the first place." );
+		if( this.setValue ) {
 
-		this.setValue( this.originalValue );
+			this.setValue( this.originalValue );
+
+			this.setValue = null;
+			this.getValue = null;
+			this.lerp = null;
+			this.triggerDirty = null;
+			
+		}
 	},
 
 	// creates the member functions:
@@ -80,7 +87,7 @@ THREE.PropertyBinding.prototype = {
 		
 		//console.log( "PropertyBinding", this );
 
-		var equalsFunc = THREE.AnimationUtils.getEqualsFunc( this.cumulativeValue );
+		var equalsFunc = THREE.AnimationUtils.getEqualsFunc( this.originalValue );
 
 		var targetObject = this.node;
 
@@ -241,7 +248,7 @@ THREE.PropertyBinding.prototype = {
 
 		this.originalValue = this.getValue();
 
-		this.lerp = THREE.AnimationUtils.getLerpFunc( value, true );
+		this.lerp = THREE.AnimationUtils.getLerpFunc( this.originalValue, true );
 
 	},
 

+ 0 - 10
src/animation/Time.js

@@ -1,10 +0,0 @@
-
-
-time - time since the start of the game
-timeScale - the time scale currently going on, allows for slow motion effects
-deltaTime - the time since the last frame
-
-timeSinceLevelLoad - time since the start of the most recent level
-
-unscaledTime
-unscaledDeltaTime

+ 1 - 1
src/objects/MorphAnimMesh.js

@@ -90,7 +90,7 @@ THREE.MorphAnimMesh.prototype.clone = function () {
 
 THREE.MorphAnimMesh.prototype.copy = function ( source ) {
 
-	this.mixer.copy( source.mixer );
+	this.mixer = new THREE.AnimationMixer( this );
 	this.animationClips = source.animationClips;
 	this.firstAnimationClips = source.firstAnimationClips;