|
@@ -21,6 +21,8 @@ THREE.MD2Character = function () {
|
|
|
|
|
|
this.activeAnimation = null;
|
|
|
|
|
|
+ this.mixer = null;
|
|
|
+
|
|
|
this.onLoadComplete = function () {};
|
|
|
|
|
|
this.loadCounter = 0;
|
|
@@ -52,7 +54,11 @@ THREE.MD2Character = function () {
|
|
|
scope.root.add( mesh );
|
|
|
|
|
|
scope.meshBody = mesh;
|
|
|
- scope.activeAnimationClipName = mesh.firstAnimationClip.name;
|
|
|
+
|
|
|
+ scope.meshBody.clipOffset = 0;
|
|
|
+ scope.activeAnimationClipName = mesh.geometry.clips[0].name;
|
|
|
+
|
|
|
+ scope.mixer = new THREE.AnimationMixer( mesh );
|
|
|
|
|
|
checkLoadingComplete();
|
|
|
|
|
@@ -91,8 +97,12 @@ THREE.MD2Character = function () {
|
|
|
|
|
|
this.setPlaybackRate = function ( rate ) {
|
|
|
|
|
|
- if ( this.meshBody ) this.meshBody.duration = this.meshBody.baseDuration / rate;
|
|
|
- if ( this.meshWeapon ) this.meshWeapon.duration = this.meshWeapon.baseDuration / rate;
|
|
|
+ if( rate !== 0 ) {
|
|
|
+ this.mixer.timeScale = 1 / rate;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.mixer.timeScale = 0;
|
|
|
+ }
|
|
|
|
|
|
};
|
|
|
|
|
@@ -133,51 +143,67 @@ THREE.MD2Character = function () {
|
|
|
activeWeapon.visible = true;
|
|
|
this.meshWeapon = activeWeapon;
|
|
|
|
|
|
- activeWeapon.playAnimation( this.activeAnimationClipName, this.animationFPS );
|
|
|
-
|
|
|
- this.meshWeapon.baseDuration = this.meshWeapon.duration;
|
|
|
-
|
|
|
- this.meshWeapon.time = this.meshBody.time;
|
|
|
- this.meshWeapon.duration = this.meshBody.duration;
|
|
|
+ scope.syncWeaponAnimation();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.setAnimation = function ( animationName ) {
|
|
|
+ this.setAnimation = function ( clipName ) {
|
|
|
|
|
|
if ( this.meshBody ) {
|
|
|
|
|
|
- this.meshBody.playAnimation( animationName, this.animationFPS );
|
|
|
- this.meshBody.baseDuration = this.meshBody.duration;
|
|
|
+ if( this.meshBody.activeAction ) {
|
|
|
+ scope.mixer.removeAction( this.meshBody.activeAction );
|
|
|
+ this.meshBody.activeAction = null;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ var clip = THREE.AnimationClip.findByName( this.meshBody.geometry.clips, clipName );
|
|
|
+ if( clip ) {
|
|
|
|
|
|
- if ( this.meshWeapon ) {
|
|
|
+ var action = new THREE.AnimationAction( clip, this.mixer.time ).setLocalRoot( this.meshBody );
|
|
|
+ scope.mixer.addAction( action );
|
|
|
|
|
|
- this.meshWeapon.playAnimation( animationName, this.animationFPS );
|
|
|
- this.meshWeapon.baseDuration = this.meshWeapon.duration;
|
|
|
- this.meshWeapon.time = this.meshBody.time;
|
|
|
+ this.meshBody.activeAction = action;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.activeAnimation = animationName;
|
|
|
+ scope.activeClipName = clipName;
|
|
|
+
|
|
|
+ scope.syncWeaponAnimation();
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.update = function ( delta ) {
|
|
|
+ this.syncWeaponAnimation = function() {
|
|
|
|
|
|
- if ( this.meshBody ) {
|
|
|
+ var clipName = scope.activeClipName;
|
|
|
|
|
|
- this.meshBody.updateAnimation( 1000 * delta );
|
|
|
+ if ( scope.meshWeapon ) {
|
|
|
|
|
|
- }
|
|
|
+ if( this.meshWeapon.activeAction ) {
|
|
|
+ scope.mixer.removeAction( this.meshWeapon.activeAction );
|
|
|
+ this.meshWeapon.activeAction = null;
|
|
|
+ }
|
|
|
|
|
|
- if ( this.meshWeapon ) {
|
|
|
+ var clip = THREE.AnimationClip.findByName( this.meshWeapon.geometry.clips, clipName );
|
|
|
+ if( clip ) {
|
|
|
|
|
|
- this.meshWeapon.updateAnimation( 1000 * delta );
|
|
|
+ var action = new THREE.AnimationAction( clip, this.meshBody.activeAction.startTime ).setLocalRoot( this.meshWeapon );
|
|
|
+ scope.mixer.addAction( action );
|
|
|
+
|
|
|
+ this.meshWeapon.activeAction = action;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.update = function ( delta ) {
|
|
|
+
|
|
|
+ if( this.mixer ) this.mixer.update( delta );
|
|
|
|
|
|
};
|
|
|
|
|
@@ -204,7 +230,7 @@ THREE.MD2Character = function () {
|
|
|
|
|
|
//
|
|
|
|
|
|
- var mesh = new THREE.MorphAnimMesh( geometry, materialTexture );
|
|
|
+ var mesh = new THREE.Mesh( geometry, materialTexture );
|
|
|
mesh.rotation.y = - Math.PI / 2;
|
|
|
|
|
|
mesh.castShadow = true;
|
|
@@ -214,14 +240,7 @@ THREE.MD2Character = function () {
|
|
|
|
|
|
mesh.materialTexture = materialTexture;
|
|
|
mesh.materialWireframe = materialWireframe;
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- mesh.parseAnimations();
|
|
|
-
|
|
|
- mesh.playAnimation( mesh.firstAnimationClip.name, scope.animationFPS );
|
|
|
- mesh.baseDuration = mesh.duration;
|
|
|
-
|
|
|
+
|
|
|
return mesh;
|
|
|
|
|
|
}
|