Просмотр исходного кода

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 10 лет назад
Родитель
Сommit
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 ] );
 
 
 			}
 			}
 
 

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 );
 				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 );
 
 
 			}
 			}
 
 

Некоторые файлы не были показаны из-за большого количества измененных файлов

粤ICP备19079148号