Răsfoiți Sursa

removing MorphAnimMesh from various examples.

Ben Houston 10 ani în urmă
părinte
comite
e6795ff363

+ 14 - 14
examples/webgl_lights_hemisphere.html

@@ -95,7 +95,7 @@
 			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
 
 			var camera, scene, renderer, dirLight, hemiLight;
-			var morphs = [];
+			var mixers = [];
 			var stats;
 
 			var clock = new THREE.Clock();
@@ -204,20 +204,21 @@
 					morphColorsToFaceColors( geometry );
 
 					var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 20, morphTargets: true, vertexColors: THREE.FaceColors, shading: THREE.FlatShading } );
-					var meshAnim = new THREE.MorphAnimMesh( geometry, material );
-
-					meshAnim.duration = 1000;
+					var mesh = new THREE.Mesh( geometry, material );
 
 					var s = 0.35;
-					meshAnim.scale.set( s, s, s );
-					meshAnim.position.y = 15;
-					meshAnim.rotation.y = -1;
+					mesh.scale.set( s, s, s );
+					mesh.position.y = 15;
+					mesh.rotation.y = -1;
+
+					mesh.castShadow = true;
+					mesh.receiveShadow = true;
 
-					meshAnim.castShadow = true;
-					meshAnim.receiveShadow = true;
+					scene.add( mesh );
 
-					scene.add( meshAnim );
-					morphs.push( meshAnim );
+					var mixer = new THREE.AnimationMixer( mesh );
+					mixer.addAction( new THREE.AnimationAction( geometry.clips[0] ).warpToDuration( 5 ) );
+					mixers.push( mixer );
 
 				} );
 
@@ -307,10 +308,9 @@
 
 				//controls.update();
 
-				for ( var i = 0; i < morphs.length; i ++ ) {
+				for ( var i = 0; i < mixers.length; i ++ ) {
 
-					morph = morphs[ i ];
-					morph.updateAnimation( 1000 * delta );
+					mixers[ i ].update( delta );
 
 				}
 

+ 18 - 20
examples/webgl_loader_json_blender.html

@@ -56,7 +56,7 @@
 			var dae;
 
 			var clock = new THREE.Clock();
-			var morphs = [];
+			var mixers = [];
 
 			// Collada model
 
@@ -121,28 +121,26 @@
 
 						if ( Math.abs( x ) < 2 && Math.abs( z ) < 2 ) continue;
 
-						morph = new THREE.MorphAnimMesh( geometry, faceMaterial );
-
-						// one second duration
-
-						morph.duration = 1000;
-
-						// random animation offset
-
-						morph.time = 1000 * Math.random();
+						mesh = new THREE.Mesh( geometry, faceMaterial );
 
 						var s = THREE.Math.randFloat( 0.00075, 0.001 );
-						morph.scale.set( s, s, s );
+						mesh.scale.set( s, s, s );
+
+						mesh.position.set( x, 0, z );
+						mesh.rotation.y = THREE.Math.randFloat( -0.25, 0.25 );
 
-						morph.position.set( x, 0, z );
-						morph.rotation.y = THREE.Math.randFloat( -0.25, 0.25 );
+						mesh.matrixAutoUpdate = false;
+						mesh.updateMatrix();
 
-						morph.matrixAutoUpdate = false;
-						morph.updateMatrix();
+						scene.add( mesh );
+						
+						var mixer = new THREE.AnimationMixer( mesh );
+						mixer.addAction( new THREE.AnimationAction( geometry.clips[0] ).wrapToDuration( 1000 ) );
 
-						scene.add( morph );
+						// random animation offset
+						mixer.update( 1000 * Math.random() );
 
-						morphs.push( morph );
+						mixers.push( mixer );
 
 					}
 
@@ -202,13 +200,13 @@
 
 				THREE.AnimationHandler.update( delta );
 
-				if ( morphs.length ) {
+				for ( var i = 0; i < mixers.length; i ++ ) {
 
-					for ( var i = 0; i < morphs.length; i ++ )
-						morphs[ i ].updateAnimation( 1000 * delta );
+					mixers[ i ].update( delta );
 
 				}
 
+
 				render();
 				stats.update();
 

+ 10 - 15
examples/webgl_loader_scene.html

@@ -125,11 +125,12 @@
 
 			var mouseX = 0, mouseY = 0;
 
+			var mixers = [];
+
 			var windowHalfX = window.innerWidth / 2;
 			var windowHalfY = window.innerHeight / 2;
 
 			var rotatingObjects = [];
-			var morphAnimatedObjects = [];
 
 			var clock = new THREE.Clock();
 
@@ -204,18 +205,13 @@
 
 						}
 
-						if ( object instanceof THREE.MorphAnimMesh ) {
-
-							morphAnimatedObjects.push( object );
-
-						}
-
-						if ( object instanceof THREE.SkinnedMesh ) {
+						if ( object instanceof THREE.Mesh ) {
 
-							if ( object.geometry.animation ) {
+							if( object.geometry && object.geometry.clips && object.geometry.clips.length > 0 ) {
 
-								var animation = new THREE.Animation( object, object.geometry.animation );
-								animation.play();
+								var mixer = new THREE.AnimationMixer( object );
+								mixer.addAction( new THREE.AnimationAction( object.geometry.clips[0] ) );
+								mixers.push( mixer );
 
 							}
 
@@ -361,11 +357,10 @@
 
 				}
 
-				for ( var i = 0; i < morphAnimatedObjects.length; i ++ ) {
-
-					var object = morphAnimatedObjects[ i ];
+				
+				for ( var i = 0; i < mixers.length; i ++ ) {
 
-					object.updateAnimation( 1000 * delta );
+					mixers[ i ].update( delta );
 
 				}
 

+ 3 - 4
examples/webgl_morphnormals.html

@@ -102,7 +102,7 @@
 					scene1.add( mesh );
 
 					var mixer = new THREE.AnimationMixer( mesh );
-					mixer.addAction( new THREE.AnimationAction( geometry.clips[ 0 ] ) );
+					mixer.addAction( new THREE.AnimationAction( geometry.clips[ 0 ] ).wrapToDuration( 5000 ) );
 
 					mixers.push( mixer );
 
@@ -123,7 +123,7 @@
 					scene2.add( mesh );
 
 					var mixer = new THREE.AnimationMixer( mesh );
-					mixer.addAction( new THREE.AnimationAction( geometry.clips[ 0 ] ) );
+					mixer.addAction( new THREE.AnimationAction( geometry.clips[ 0 ] ).wrapToDuration( 5000 ) );
 
 					mixers.push( mixer );
 
@@ -210,8 +210,7 @@
 
 				var delta = clock.getDelta();
 
-   				console.log( mixers );
-				for ( var i = 0; i < mixers.length; i ++ ) {
+   				for ( var i = 0; i < mixers.length; i ++ ) {
 					mixers[ i ].update( delta );
 
 				}

+ 1 - 1
examples/webgl_morphtargets_horse.html

@@ -69,7 +69,7 @@
 					mixer = new THREE.AnimationMixer( mesh );
 
 					var clip = THREE.AnimationClip.CreateFromMorphTargetSequence( 'gallop', geometry.morphTargets, 30 );
-					mixer.addAction( new THREE.AnimationAction( clip, 0, 1, 1, true ) );
+					mixer.addAction( new THREE.AnimationAction( clip ).wrapToDuration( 3000 ) );
 
 				} );
 

+ 7 - 7
examples/webgl_shading_physical.html

@@ -74,7 +74,7 @@
 
 			var sunLight, pointLight, ambientLight;
 
-			var morph, mixer;
+			var mixer;
 
 			var parameters, tweenDirection, tweenDay, tweenNight;
 
@@ -272,23 +272,23 @@
 
 					var morphMaterial = new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0xff9900, shininess: 50, morphTargets: true, side: THREE.DoubleSide, shading: THREE.FlatShading } );
 
-					morph = new THREE.MorphAnimMesh( geometry, morphMaterial );
+					mesh = new THREE.Mesh( geometry, morphMaterial );
 
-					mixer = new THREE.AnimationMixer( morph );
+					mixer = new THREE.AnimationMixer( mesh );
 
 					var clipMorphTargets = THREE.AnimationClipCreator.CreateMorphAnimation( geometry.morphTargets, 8.0 );
 					mixer.addAction( new THREE.AnimationAction( clipMorphTargets, 0, 1, 1, true ) );
 
 					var s = 200;
-					morph.scale.set( s, s, s );
+					mesh.scale.set( s, s, s );
 
 					//morph.duration = 8000;
 					//morph.mirroredLoop = true;
 
-					morph.castShadow = true;
-					morph.receiveShadow = true;
+					mesh.castShadow = true;
+					mesh.receiveShadow = true;
 
-					scene.add( morph );
+					scene.add( mesh );
 
 				} );
 

+ 26 - 21
examples/webgl_shadowmap.html

@@ -62,7 +62,7 @@
 
 			var sceneHUD, cameraOrtho, hudMesh;
 
-			var morph, morphs = [];
+			var morphs = [];
 
 			var light;
 
@@ -315,21 +315,26 @@
 
 					}
 
-					var meshAnim = new THREE.MorphAnimMesh( geometry, material );
+					var mesh = new THREE.Mesh( geometry, material );
 
-					meshAnim.speed = speed;
-					meshAnim.duration = duration;
-					meshAnim.time = 600 * Math.random();
+					mesh.speed = speed;
 
-					meshAnim.position.set( x, y, z );
-					meshAnim.rotation.y = Math.PI/2;
+					var mixer = new THREE.AnimationMixer( mesh );
+					mixer.addAction( new THREE.AnimationAction( geometry.clips[0] ).warpToDuration( duration ) );
+					console.log( mixer );
+					mixer.update( 600 * Math.random() );
 
-					meshAnim.castShadow = true;
-					meshAnim.receiveShadow = true;
+					mesh.position.set( x, y, z );
+					mesh.rotation.y = Math.PI/2;
 
-					scene.add( meshAnim );
+					mesh.castShadow = true;
+					mesh.receiveShadow = true;
 
-					morphs.push( meshAnim );
+					mesh.mixer = mixer;
+
+					scene.add( mesh );
+
+					morphs.push( mesh );
 
 				}
 
@@ -355,34 +360,34 @@
 
 					morphColorsToFaceColors( geometry );
 
-					addMorph( geometry, 550, 1000, 100 - Math.random() * 1000, FLOOR, 300, true );
-					addMorph( geometry, 550, 1000, 100 - Math.random() * 1000, FLOOR, 450, true );
-					addMorph( geometry, 550, 1000, 100 - Math.random() * 1000, FLOOR, 600, true );
+					addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, 300, true );
+					addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, 450, true );
+					addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, 600, true );
 
-					addMorph( geometry, 550, 1000, 100 - Math.random() * 1000, FLOOR, -300, true );
-					addMorph( geometry, 550, 1000, 100 - Math.random() * 1000, FLOOR, -450, true );
-					addMorph( geometry, 550, 1000, 100 - Math.random() * 1000, FLOOR, -600, true );
+					addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, -300, true );
+					addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, -450, true );
+					addMorph( geometry, 550, 1, 100 - Math.random() * 1000, FLOOR, -600, true );
 
 				} );
 
 				loader.load( "models/animated/flamingo.js", function( geometry ) {
 
 					morphColorsToFaceColors( geometry );
-					addMorph( geometry, 500, 1000, 500 - Math.random() * 500, FLOOR + 350, 40 );
+					addMorph( geometry, 500, 1, 500 - Math.random() * 500, FLOOR + 350, 40 );
 
 				} );
 
 				loader.load( "models/animated/stork.js", function( geometry ) {
 
 					morphColorsToFaceColors( geometry );
-					addMorph( geometry, 350, 1000, 500 - Math.random() * 500, FLOOR + 350, 340 );
+					addMorph( geometry, 350, 1, 500 - Math.random() * 500, FLOOR + 350, 340 );
 
 				} );
 
 				loader.load( "models/animated/parrot.js", function( geometry ) {
 
 					morphColorsToFaceColors( geometry );
-					addMorph( geometry, 450, 500, 500 - Math.random() * 500, FLOOR + 300, 700 );
+					addMorph( geometry, 450, 0.5, 500 - Math.random() * 500, FLOOR + 300, 700 );
 
 				} );
 
@@ -405,7 +410,7 @@
 
 					morph = morphs[ i ];
 
-					morph.updateAnimation( 1000 * delta );
+					morph.mixer.update( delta );
 
 					morph.position.x += morph.speed * delta;
 

+ 9 - 0
src/animation/AnimationAction.js

@@ -90,10 +90,19 @@ THREE.AnimationAction.prototype = {
 
 	},
 
+	warpToDuration: function( duration ) {
+
+		this.timeScale = this.clip.duration / duration;
+
+		return this;
+	},
+
 	init: function( time ) {
 
 		this.clipTime = time - this.startTime;
 
+		return this;
+
 	},
 
 	update: function( clipDeltaTime ) {

+ 1 - 0
src/loaders/JSONLoader.js

@@ -519,6 +519,7 @@ THREE.JSONLoader.prototype = {
 			// parse implicit morph animations
 			if( geometry.morphTargets ) {
 
+				// TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
 				var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
 				geometry.clips = geometry.clips.concat( morphAnimationClips );