提交 8485ffd4 编写于 作者: G gero3

Add crossFadeFrom & crossFadeTo

上级 afe2eec9
......@@ -29,6 +29,32 @@ function createAnimation(){
}
function createTwoAnimations(){
var root = new Object3D();
var mixer = new AnimationMixer(root);
var track = new NumberKeyframeTrack( ".rotation[x]", [ 0, 1000 ], [ 0, 360 ] );
var clip = new AnimationClip( "clip1", 1000, [track] );
var animationAction = mixer.clipAction( clip );
var track2 = new NumberKeyframeTrack( ".rotation[y]", [ 0, 1000 ], [ 0, 360 ] );
var clip2 = new AnimationClip( "clip2", 1000, [track] );
var animationAction2 = mixer.clipAction( clip2 );
return {
root: root,
mixer: mixer,
track: track,
clip: clip,
animationAction: animationAction,
track2: track2,
clip2: clip2,
animationAction2: animationAction2
};
}
export default QUnit.module( 'Animation', () => {
QUnit.module( 'AnimationAction', () => {
......@@ -233,20 +259,20 @@ export default QUnit.module( 'Animation', () => {
QUnit.test( "setEffectiveWeight", ( assert ) => {
var {animationAction} = createAnimation();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 0.3 , "When EffectiveWeight is set to 0.3 , EffectiveWeight is 0.3." );
var {animationAction} = createAnimation();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.enabled = false;
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.enabled = false;
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 0 , "When EffectiveWeight is set to 0.3 when disabled , EffectiveWeight is 0." );
var { root, mixer,animationAction } = createAnimation();
animationAction.setEffectiveWeight(0.5);
animationAction.setEffectiveWeight(0.5);
animationAction.play();
mixer.update(500);
assert.equal( root.rotation.x, 90 , "When an animation has weight 0.5 and runs half through the animation, it has changed to 1/4." );
......@@ -259,26 +285,26 @@ export default QUnit.module( 'Animation', () => {
QUnit.test( "getEffectiveWeight", ( assert ) => {
var {animationAction} = createAnimation();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.setEffectiveWeight(0.3);
var {animationAction} = createAnimation();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 0.3 , "When EffectiveWeight is set to 0.3 , EffectiveWeight is 0.3." );
var {animationAction} = createAnimation();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.enabled = false;
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation is created, EffectiveWeight is 1." );
animationAction.enabled = false;
animationAction.setEffectiveWeight(0.3);
assert.equal( animationAction.getEffectiveWeight(), 0 , "When EffectiveWeight is set to 0.3 when disabled , EffectiveWeight is 0." );
} );
QUnit.test( "fadeIn", ( assert ) => {
var {mixer, animationAction} = createAnimation();
animationAction.fadeIn(1000);
var {mixer, animationAction} = createAnimation();
animationAction.fadeIn(1000);
animationAction.play();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation fadeIn is started, EffectiveWeight is 1." );
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation fadeIn is started, EffectiveWeight is 1." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.25, "When an animation fadeIn happened 1/4, EffectiveWeight is 0.25." );
mixer.update(250);
......@@ -293,9 +319,9 @@ export default QUnit.module( 'Animation', () => {
QUnit.test( "fadeOut", ( assert ) => {
var {mixer, animationAction} = createAnimation();
animationAction.fadeOut(1000);
animationAction.fadeOut(1000);
animationAction.play();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation fadeOut is started, EffectiveWeight is 1." );
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation fadeOut is started, EffectiveWeight is 1." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.75, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
mixer.update(250);
......@@ -307,15 +333,49 @@ export default QUnit.module( 'Animation', () => {
} );
QUnit.todo( "crossFadeFrom", ( assert ) => {
QUnit.test( "crossFadeFrom", ( assert ) => {
assert.ok( false, "everything's gonna be alright" );
var {mixer, animationAction, animationAction2} = createTwoAnimations();
animationAction.crossFadeFrom(animationAction2, 1000, false);
animationAction.play();
animationAction2.play();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation crossFadeFrom is started, EffectiveWeight is 1." );
assert.equal( animationAction2.getEffectiveWeight(), 1 , "When an animation crossFadeFrom is started, EffectiveWeight is 1." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.25, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0.75, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.5, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0.5, "When an animation fadeOut is halfway , EffectiveWeight is 0.5." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.75, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0.25, "When an animation fadeOut is happened 3/4 , EffectiveWeight is 0.25." );
mixer.update(500);
assert.equal( animationAction.getEffectiveWeight(), 1, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0, "When an animation fadeOut is ended , EffectiveWeight is 0." );
} );
QUnit.todo( "crossFadeTo", ( assert ) => {
QUnit.test( "crossFadeTo", ( assert ) => {
assert.ok( false, "everything's gonna be alright" );
var {mixer, animationAction, animationAction2} = createTwoAnimations();
animationAction2.crossFadeTo(animationAction, 1000, false);
animationAction.play();
animationAction2.play();
assert.equal( animationAction.getEffectiveWeight(), 1 , "When an animation crossFadeFrom is started, EffectiveWeight is 1." );
assert.equal( animationAction2.getEffectiveWeight(), 1 , "When an animation crossFadeFrom is started, EffectiveWeight is 1." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.25, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0.75, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.5, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0.5, "When an animation fadeOut is halfway , EffectiveWeight is 0.5." );
mixer.update(250);
assert.equal( animationAction.getEffectiveWeight(), 0.75, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0.25, "When an animation fadeOut is happened 3/4 , EffectiveWeight is 0.25." );
mixer.update(500);
assert.equal( animationAction.getEffectiveWeight(), 1, "When an animation fadeOut happened 1/4, EffectiveWeight is 0.75." );
assert.equal( animationAction2.getEffectiveWeight(), 0, "When an animation fadeOut is ended , EffectiveWeight is 0." );
} );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册