소스 검색

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.warpSchedule = [];
+	this.mixer;
 
 	this.load = function ( url, onLoad ) {
 
 		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
-			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 ] );
 
 			}
 

BIN
examples/models/skinned/marine/marine_anims.blend


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 10 - 0
examples/models/skinned/marine/marine_anims.json


BIN
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 );
 
 				blendMesh = new THREE.BlendCharacter();
-				blendMesh.load( "models/skinned/marine/marine_anims.js", start );
+				blendMesh.load( "models/skinned/marine/marine_anims.json", start );
 
 			}
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.