Browse Source

get UCSCharacter working again.

Ben Houston 10 years ago
parent
commit
16ee794138

+ 3 - 2
examples/js/UCSCharacter.js

@@ -1,4 +1,4 @@
-THREE.UCSCharacterMixer = function() {
+THREE.UCSCharacter = function() {
 
 	var scope = this;
 	
@@ -55,7 +55,8 @@ THREE.UCSCharacterMixer = function() {
 			mesh.castShadow = true;
 			mesh.receiveShadow = true;
 
-			var clipBones = THREE.AnimationClip.FromJSONLoaderAnimation( geometry, mesh.uuid );
+			console.log( geometry );
+			var clipBones = THREE.AnimationClip.FromJSONLoaderAnimation( geometry.animation, geometry.bones, mesh.uuid );
 
 			scope.mixer.addAction( new THREE.AnimationAction( clipBones, 0, 1, 1, true ) );
 			

+ 8 - 6
examples/webgl_morphtargets_horse.html

@@ -16,14 +16,14 @@
 	<body>
 
 		<script src="../build/three.min.js"></script>
-
 		<script src="js/libs/stats.min.js"></script>
+		<script src="js/AnimationClipCreator.js"></script>
 
 		<script>
 
 			var container, stats;
 			var camera, scene, projector, renderer;
-			var mesh, animation;
+			var mesh, mixer;
 
 			init();
 			animate();
@@ -66,8 +66,10 @@
 					mesh.scale.set( 1.5, 1.5, 1.5 );
 					scene.add( mesh );
 
-					animation = new THREE.MorphAnimation( mesh );
-					animation.play();
+					mixer = new THREE.AnimationMixer( mesh );
+
+					var clipMorphTargets = THREE.AnimationClipCreator.CreateMorphAnimation( geometry.morphTargets, 1.0 );
+					mixer.addAction( new THREE.AnimationAction( clipMorphTargets, 0, 1, 1, true ) );
 
 				} );
 
@@ -126,11 +128,11 @@
 
 				camera.lookAt( camera.target );
 
-				if ( animation ) {
+				if ( mixer ) {
 
 					var time = Date.now();
 
-					animation.update( time - prevTime );
+					mixer.update( ( time - prevTime ) * 0.001 );
 
 					prevTime = time;
 

+ 0 - 148
examples/webgl_morphtargets_horse_mixer.html

@@ -1,148 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-	<head>
-		<title>three.js webgl - morph targets - horse</title>
-		<meta charset="utf-8">
-		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-		<style>
-			body {
-				font-family: Monospace;
-				background-color: #f0f0f0;
-				margin: 0px;
-				overflow: hidden;
-			}
-		</style>
-	</head>
-	<body>
-
-		<script src="../build/three.min.js"></script>
-		<script src="js/libs/stats.min.js"></script>
-		<script src="js/AnimationClipCreator.js"></script>
-
-		<script>
-
-			var container, stats;
-			var camera, scene, projector, renderer;
-			var mesh, mixer;
-
-			init();
-			animate();
-
-			function init() {
-
-				container = document.createElement( 'div' );
-				document.body.appendChild( container );
-
-				var info = document.createElement( 'div' );
-				info.style.position = 'absolute';
-				info.style.top = '10px';
-				info.style.width = '100%';
-				info.style.textAlign = 'center';
-				info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js</a> webgl - morph targets - horse. model by <a href="http://mirada.com/">mirada</a> from <a href="http://ro.me">rome</a>';
-				container.appendChild( info );
-
-				//
-
-				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
-				camera.position.y = 300;
-				camera.target = new THREE.Vector3( 0, 150, 0 );
-
-				scene = new THREE.Scene();
-
-				//
-
-				var light = new THREE.DirectionalLight( 0xefefff, 2 );
-				light.position.set( 1, 1, 1 ).normalize();
-				scene.add( light );
-
-				var light = new THREE.DirectionalLight( 0xffefef, 2 );
-				light.position.set( -1, -1, -1 ).normalize();
-				scene.add( light );
-
-				var loader = new THREE.JSONLoader();
-				loader.load( "models/animated/horse.js", function( geometry ) {
-
-					mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x606060, morphTargets: true } ) );
-					mesh.scale.set( 1.5, 1.5, 1.5 );
-					scene.add( mesh );
-
-					mixer = new THREE.AnimationMixer( mesh );
-
-					var clipMorphTargets = THREE.AnimationClipCreator.CreateMorphAnimation( geometry.morphTargets, 1.0 );
-					mixer.addAction( new THREE.AnimationAction( clipMorphTargets, 0, 1, 1, true ) );
-
-				} );
-
-				//
-
-				renderer = new THREE.WebGLRenderer();
-				renderer.setClearColor( 0xf0f0f0 );
-				renderer.setPixelRatio( window.devicePixelRatio );
-				renderer.setSize( window.innerWidth, window.innerHeight );
-				container.appendChild(renderer.domElement);
-
-				//
-
-				stats = new Stats();
-				stats.domElement.style.position = 'absolute';
-				stats.domElement.style.top = '0px';
-				container.appendChild( stats.domElement );
-
-				//
-
-				window.addEventListener( 'resize', onWindowResize, false );
-
-			}
-
-			function onWindowResize() {
-
-				camera.aspect = window.innerWidth / window.innerHeight;
-				camera.updateProjectionMatrix();
-
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
-			}
-
-			//
-
-			function animate() {
-
-				requestAnimationFrame( animate );
-
-				render();
-				stats.update();
-
-			}
-
-			var radius = 600;
-			var theta = 0;
-
-			var prevTime = Date.now();
-
-			function render() {
-
-				theta += 0.1;
-
-				camera.position.x = radius * Math.sin( THREE.Math.degToRad( theta ) );
-				camera.position.z = radius * Math.cos( THREE.Math.degToRad( theta ) );
-
-				camera.lookAt( camera.target );
-
-				if ( mixer ) {
-
-					var time = Date.now();
-
-					mixer.update( ( time - prevTime ) * 0.001 );
-
-					prevTime = time;
-
-				}
-
-				renderer.render( scene, camera );
-
-			}
-
-		</script>
-
-	</body>
-</html>

+ 1 - 1
examples/webgl_morphtargets_human.html

@@ -224,7 +224,7 @@
 
 				// update skinning
 
-				THREE.AnimationHandler.update( delta );
+				character.mixer.update( delta );
 
 				renderer.render( scene, camera );
 

+ 0 - 236
examples/webgl_morphtargets_human_mixer.html

@@ -1,236 +0,0 @@
-<!doctype html>
-<html lang="en">
-	<head>
-		<title>three.js webgl - morph target - human</title>
-		<meta charset="utf-8">
-		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-		<style>
-			body {
-				color: #000;
-				font-family:Monospace;
-				font-size:13px;
-				text-align:center;
-
-				background-color: #fff;
-				margin: 0px;
-				overflow: hidden;
-			}
-
-			#info {
-				position: absolute;
-				top: 0px; width: 100%;
-				padding: 5px;
-			}
-
-			a {
-				color: #0af;
-			}
-		</style>
-	</head>
-
-	<body>
-		
-		<div id="container"></div>
-
-		<div id="info">
-		<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl - morph targets - human</a>
-		</div>
-
-		<script src="../build/three.min.js"></script>
-		
-		<script src="js/UCSCharacterMixer.js"></script>
-
-		<script src="js/Detector.js"></script>
-		
-		<script src='js/libs/dat.gui.min.js'></script>
-				
-		<script src="js/controls/OrbitControls.js"></script>
-		
-		<script>
-			
-			var SCREEN_WIDTH = window.innerWidth;
-			var SCREEN_HEIGHT = window.innerHeight;
-
-			var container;
-
-			var camera, scene;
-			var renderer;
-			
-			var mesh;
-
-			var mouseX = 0, mouseY = 0;
-
-			var windowHalfX = window.innerWidth / 2;
-			var windowHalfY = window.innerHeight / 2;
-
-			var clock = new THREE.Clock();
-			
-			var gui, skinConfig, morphConfig;
-				
-			document.addEventListener( 'mousemove', onDocumentMouseMove, false );
-
-			init();
-			animate();
-
-			function init() {
-
-				container = document.getElementById( 'container' );
-
-				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
-				camera.position.set( 2000, 5000, 5000 );
-
-				scene = new THREE.Scene();
-
-				// LIGHTS
-
-				var light = new THREE.DirectionalLight( 0xffffff, 1 );
-				light.position.set( 0, 140, 500 );
-				light.position.multiplyScalar( 1.1 );
-				light.color.setHSL( 0.6, 0.075, 1 );
-				scene.add( light );
-
-				//
-
-				var light = new THREE.DirectionalLight( 0xffffff, 1 );
-				light.position.set( 0, -1, 0 );
-				scene.add( light );
-
-				// RENDERER
-
-				renderer = new THREE.WebGLRenderer( { antialias: true } );
-				renderer.setClearColor( 0xffffff );
-				renderer.setPixelRatio( window.devicePixelRatio );
-				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-				container.appendChild( renderer.domElement );
-
-				// CHARACTER
-
-				character = new THREE.UCSCharacterMixer();
-				character.onLoadComplete = function() {
-					console.log( "Load Complete" );
-					console.log( character.numSkins + " skins and " + character.numMorphs + " morphtargets loaded." );
-					gui = new dat.GUI();
-					setupSkinsGUI();
-					setupMorphsGUI();
-					gui.width = 300;
-					gui.open();
-				};
-				
-				var loader = new THREE.XHRLoader();
-				loader.load("models/skinned/UCS_config.json", function ( text ) {
-
-					var config = JSON.parse( text );
-					character.loadParts( config );
-					scene.add( character.root );
-
-				} );
-
-				window.addEventListener( 'resize', onWindowResize, false );
-				
-				controls = new THREE.OrbitControls( camera, renderer.domElement );
-				controls.center.set( 0, 3000, 0);
-
-				controls.addEventListener( 'change', render );
-
-			}
-			
-			function setupSkinsGUI() {
-			
-				var skinGui = gui.addFolder( "Skins" );
-				
-				skinConfig = {
-					wireframe: false
-				};
-				
-				var skinCallback = function( index ) {
-					return function () {
-						character.setSkin( index );
-					};
-				};
-
-				for ( var i = 0; i < character.numSkins; i++ ) {
-					var name = character.skins[ i ].name;
-					skinConfig[ name ] = skinCallback( i );
-				}
-				
-				for ( var i = 0; i < character.numSkins; i++ ) {
-					skinGui.add( skinConfig, character.skins[i].name );
-				}
-				
-				skinGui.open();
-
-			}
-			
-			function setupMorphsGUI() {
-				
-				var morphGui = gui.addFolder( "Morphs" );
-				
-				morphConfig = {
-				};
-				
-				var morphCallback = function( index ) {
-					return function () {
-						character.updateMorphs( morphConfig );
-					}
-				};
-				
-				for ( var i = 0; i < character.numMorphs; i ++ ) {
-					var morphName = character.morphs[ i ];
-					morphConfig[ morphName ] = 0;
-				}
-				
-				for ( var i = 0; i < character.numMorphs; i ++ ) {
-					morphGui.add( morphConfig, character.morphs[ i ] ).min( 0 ).max( 100 ).onChange( morphCallback( i ) );
-				}
-				
-				morphGui.open();
-			
-			}
-
-			function onWindowResize() {
-
-				windowHalfX = window.innerWidth / 2;
-				windowHalfY = window.innerHeight / 2;
-
-				camera.aspect = window.innerWidth / window.innerHeight;
-				camera.updateProjectionMatrix();
-
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
-			}
-
-			function onDocumentMouseMove( event ) {
-
-				mouseX = ( event.clientX - windowHalfX ) * 10;
-				mouseY = ( event.clientY - windowHalfY ) * 10;
-
-			}
-
-			//
-
-			function animate() {
-
-				requestAnimationFrame( animate );
-
-				controls.update();
-
-				render();
-
-			}
-
-			function render() {
-
-				var delta = 0.75 * clock.getDelta();
-
-				// update skinning
-
-				character.mixer.update( delta );
-
-				renderer.render( scene, camera );
-
-			}
-
-		</script>
-
-	</body>
-</html>

+ 3 - 2
src/animation/PropertyBinding.js

@@ -47,7 +47,7 @@ THREE.PropertyBinding.prototype = {
 		if( this.cumulativeWeight === 0 ) {
 
 			if( weight > 0 ) {
-				
+
 				if( this.cumulativeValue === null ) {
 					this.cumulativeValue = THREE.AnimationUtils.clone( value );
 				}
@@ -94,7 +94,7 @@ THREE.PropertyBinding.prototype = {
 		
 		//console.log( "PropertyBinding", this );
 
-		var targetObject = this.rootNode;
+		var targetObject = this.node;
 
  		// ensure there is a value node
 		if( ! targetObject ) {
@@ -118,6 +118,7 @@ THREE.PropertyBinding.prototype = {
 			else if( this.objectName === "bones" ) {
 				if( ! targetObject.skeleton ) {
 					console.error( '  can not bind to bones as node does not have a skeleton', this );
+					return;
 				}
 				// TODO/OPTIMIZE, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.