Skip to content

Commit 4f4bf13

Browse files
takahiroxmrdoob
authored andcommitted
Clean Up MMDLoader morph animation (mrdoob#8964)
1 parent c2a5c1f commit 4f4bf13

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

examples/js/loaders/MMDLoader.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,15 +2694,15 @@ THREE.MMDLoader.prototype.createAnimation = function ( mesh, vmd, name ) {
26942694

26952695
}
26962696

2697-
if ( mesh.geometry.animations === undefined ) {
2697+
var clip = THREE.AnimationClip.parseAnimation( animation, mesh.geometry.bones );
26982698

2699-
mesh.geometry.animations = [];
2699+
if ( clip !== null ) {
27002700

2701-
}
2701+
if ( mesh.geometry.animations === undefined ) {
27022702

2703-
var clip = THREE.AnimationClip.parseAnimation( animation, mesh.geometry.bones );
2703+
mesh.geometry.animations = [];
27042704

2705-
if ( clip !== null ) {
2705+
}
27062706

27072707
mesh.geometry.animations.push( clip );
27082708

@@ -2747,6 +2747,8 @@ THREE.MMDLoader.prototype.createAnimation = function ( mesh, vmd, name ) {
27472747

27482748
}
27492749

2750+
// TODO: should we use THREE.AnimationClip.CreateFromMorphTargetSequence() instead?
2751+
27502752
var tracks = [];
27512753

27522754
for ( var i = 0; i < orderedMorphs.length; i++ ) {
@@ -2767,13 +2769,13 @@ THREE.MMDLoader.prototype.createAnimation = function ( mesh, vmd, name ) {
27672769

27682770
if ( clip !== null ) {
27692771

2770-
if ( mesh.geometry.morphAnimations === undefined ) {
2772+
if ( mesh.geometry.animations === undefined ) {
27712773

2772-
mesh.geometry.morphAnimations = [];
2774+
mesh.geometry.animations = [];
27732775

27742776
}
27752777

2776-
mesh.geometry.morphAnimations.push( clip );
2778+
mesh.geometry.animations.push( clip );
27772779

27782780
}
27792781

@@ -4139,45 +4141,48 @@ THREE.MMDHelper.prototype = {
41394141

41404142
setAnimation: function ( mesh ) {
41414143

4142-
if ( mesh.geometry.animations !== undefined || mesh.geometry.morphAnimations !== undefined ) {
4144+
if ( mesh.geometry.animations !== undefined ) {
41434145

41444146
mesh.mixer = new THREE.AnimationMixer( mesh );
41454147

4146-
}
4147-
4148-
if ( mesh.geometry.animations !== undefined ) {
4148+
var foundAnimation = false;
4149+
var foundMorphAnimation = false;
41494150

41504151
for ( var i = 0; i < mesh.geometry.animations.length; i++ ) {
41514152

4152-
var action = mesh.mixer.clipAction( mesh.geometry.animations[ i ] );
4153+
var clip = mesh.geometry.animations[ i ];
41534154

4154-
if ( i === 0 ) {
4155+
var action = mesh.mixer.clipAction( clip );
41554156

4156-
action.play();
4157+
if ( clip.tracks[ 0 ].name.indexOf( '.morphTargetInfluences' ) === 0 ) {
41574158

4158-
}
4159+
if ( ! foundMorphAnimation ) {
41594160

4160-
}
4161+
action.play();
4162+
foundMorphAnimation = true;
41614163

4162-
mesh.ikSolver = new THREE.CCDIKSolver( mesh );
4164+
}
41634165

4164-
if ( mesh.geometry.grants !== undefined ) {
4166+
} else {
41654167

4166-
mesh.grantSolver = new THREE.MMDGrantSolver( mesh );
4168+
if ( ! foundAnimation ) {
41674169

4168-
}
4170+
action.play();
4171+
foundAnimation = true;
41694172

4170-
}
4173+
}
41714174

4172-
if ( mesh.geometry.morphAnimations !== undefined ) {
4175+
}
4176+
4177+
}
41734178

4174-
for ( var i = 0; i < mesh.geometry.morphAnimations.length; i++ ) {
4179+
if ( foundAnimation ) {
41754180

4176-
var action = mesh.mixer.clipAction( mesh.geometry.morphAnimations[ i ] );
4181+
mesh.ikSolver = new THREE.CCDIKSolver( mesh );
41774182

4178-
if ( i === 0 ) {
4183+
if ( mesh.geometry.grants !== undefined ) {
41794184

4180-
action.play();
4185+
mesh.grantSolver = new THREE.MMDGrantSolver( mesh );
41814186

41824187
}
41834188

0 commit comments

Comments
 (0)