Skip to content

Commit 82c165e

Browse files
committed
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).
1 parent 8461fd4 commit 82c165e

5 files changed

Lines changed: 191058 additions & 10 deletions

File tree

examples/js/BlendCharacter.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,46 @@ THREE.BlendCharacter = function () {
66

77
this.weightSchedule = [];
88
this.warpSchedule = [];
9+
this.mixer;
910

1011
this.load = function ( url, onLoad ) {
1112

1213
var scope = this;
1314

14-
var loader = new THREE.JSONLoader();
15-
loader.load( url, function( geometry, materials ) {
15+
var loader = new THREE.ObjectLoader();
16+
loader.load( url, function( loadedObject ) {
1617

17-
var originalMaterial = materials[ 0 ];
18-
originalMaterial.skinning = true;
18+
// The exporter does not currently allow exporting a skinned mesh by itself
19+
// so we must fish it out of the hierarchy it is embedded in (scene)
20+
loadedObject.traverse( function( object ) {
1921

20-
THREE.SkinnedMesh.call( scope, geometry, originalMaterial );
22+
if ( object instanceof THREE.SkinnedMesh ) {
2123

22-
var mixer = new THREE.AnimationMixer( scope );
23-
scope.mixer = mixer;
24+
scope.skinnedMesh = object;
25+
26+
}
27+
28+
} );
29+
30+
THREE.SkinnedMesh.call( scope, scope.skinnedMesh.geometry, scope.skinnedMesh.material );
31+
32+
// If we didn't successfully find the mesh, bail out
33+
if ( scope.skinnedMesh == undefined ) {
34+
35+
console.log( 'unable to find skinned mesh in ' + url );
36+
return;
37+
38+
}
39+
40+
scope.material.skinning = true;
41+
42+
scope.mixer = new THREE.AnimationMixer( scope );
43+
scope.mixer = scope.mixer;
2444

2545
// Create the animations
26-
for ( var i = 0; i < geometry.animations.length; ++ i ) {
46+
for ( var i = 0; i < scope.geometry.animations.length; ++ i ) {
2747

28-
mixer.clipAction( geometry.animations[ i ] );
48+
scope.mixer.clipAction( scope.geometry.animations[ i ] );
2949

3050
}
3151

4.62 MB
Binary file not shown.

examples/models/skinned/marine/marine_anims.json

Lines changed: 191028 additions & 0 deletions
Large diffs are not rendered by default.
2.79 MB
Binary file not shown.

examples/webgl_animation_skinning_blending.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
window.addEventListener( 'toggle-show-model', onShowModel );
9999

100100
blendMesh = new THREE.BlendCharacter();
101-
blendMesh.load( "models/skinned/marine/marine_anims.js", start );
101+
blendMesh.load( "models/skinned/marine/marine_anims.json", start );
102102

103103
}
104104

0 commit comments

Comments
 (0)