浏览代码

Updated example to use the ObjectLoader rather than the deprecated JSONLoader for the BlendCharacter.
Updated the exported files and the original blend files to the latest versions (compatible with ObjectLoader).

Michael Guerrero 9 年之前
父节点
当前提交
82c165e989

+ 29 - 9
examples/js/BlendCharacter.js

@@ -6,26 +6,46 @@ THREE.BlendCharacter = function () {
 
 
 	this.weightSchedule = [];
 	this.weightSchedule = [];
 	this.warpSchedule = [];
 	this.warpSchedule = [];
+	this.mixer;
 
 
 	this.load = function ( url, onLoad ) {
 	this.load = function ( url, onLoad ) {
 
 
 		var scope = this;
 		var scope = this;
 
 
-		var loader = new THREE.JSONLoader();
-		loader.load( url, function( geometry, materials ) {
+		var loader = new THREE.ObjectLoader();
+		loader.load( url, function( loadedObject ) {
 
 
-			var originalMaterial = materials[ 0 ];
-			originalMaterial.skinning = true;
+			// The exporter does not currently allow exporting a skinned mesh by itself
+			// so we must fish it out of the hierarchy it is embedded in (scene)
+			loadedObject.traverse( function( object ) {
 
 
-			THREE.SkinnedMesh.call( scope, geometry, originalMaterial );
+				if ( object instanceof THREE.SkinnedMesh ) {
 
 
-			var mixer = new THREE.AnimationMixer( scope );
-			scope.mixer = mixer;
+					scope.skinnedMesh = object;
+
+				}
+
+			} );
+
+			THREE.SkinnedMesh.call( scope, scope.skinnedMesh.geometry, scope.skinnedMesh.material );
+
+			// If we didn't successfully find the mesh, bail out
+			if ( scope.skinnedMesh == undefined ) {
+
+				console.log( 'unable to find skinned mesh in ' + url );
+				return;
+
+			}
+
+			scope.material.skinning = true;
+
+			scope.mixer = new THREE.AnimationMixer( scope );
+			scope.mixer = scope.mixer;
 
 
 			// Create the animations
 			// Create the animations
-			for ( var i = 0; i < geometry.animations.length; ++ i ) {
+			for ( var i = 0; i < scope.geometry.animations.length; ++ i ) {
 
 
-				mixer.clipAction( geometry.animations[ i ] );
+				scope.mixer.clipAction( scope.geometry.animations[ i ] );
 
 
 			}
 			}
 
 

二进制
examples/models/skinned/marine/marine_anims.blend


文件差异内容过多而无法显示
+ 10 - 0
examples/models/skinned/marine/marine_anims.json


二进制
examples/models/skinned/marine/marine_ik.blend


+ 1 - 1
examples/webgl_animation_skinning_blending.html

@@ -98,7 +98,7 @@
 				window.addEventListener( 'toggle-show-model', onShowModel );
 				window.addEventListener( 'toggle-show-model', onShowModel );
 
 
 				blendMesh = new THREE.BlendCharacter();
 				blendMesh = new THREE.BlendCharacter();
-				blendMesh.load( "models/skinned/marine/marine_anims.js", start );
+				blendMesh.load( "models/skinned/marine/marine_anims.json", start );
 
 
 			}
 			}
 
 

部分文件因为文件数量过多而无法显示