Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Unit Tests for Animation #25409

Merged
merged 17 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 125 additions & 50 deletions test/unit/src/animation/AnimationAction.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global QUnit */

import { AnimationAction } from '../../../../src/animation/AnimationAction.js';

import { AnimationMixer } from '../../../../src/animation/AnimationMixer.js';
import { AnimationClip } from '../../../../src/animation/AnimationClip.js';
import { NumberKeyframeTrack } from '../../../../src/animation/tracks/NumberKeyframeTrack.js';
Expand All @@ -10,12 +11,12 @@ import { LoopOnce, LoopRepeat, LoopPingPong } from '../../../../src/constants.js

function createAnimation() {

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 ] );
const root = new Object3D();
const mixer = new AnimationMixer( root );
const track = new NumberKeyframeTrack( '.rotation[x]', [ 0, 1000 ], [ 0, 360 ] );
const clip = new AnimationClip( 'clip1', 1000, [ track ] );

var animationAction = mixer.clipAction( clip );
const animationAction = mixer.clipAction( clip );
return {
root: root,
mixer: mixer,
Expand All @@ -28,15 +29,15 @@ 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 );
const root = new Object3D();
const mixer = new AnimationMixer( root );
const track = new NumberKeyframeTrack( '.rotation[x]', [ 0, 1000 ], [ 0, 360 ] );
const clip = new AnimationClip( 'clip1', 1000, [ track ] );
const 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 );
const track2 = new NumberKeyframeTrack( '.rotation[y]', [ 0, 1000 ], [ 0, 360 ] );
const clip2 = new AnimationClip( 'clip2', 1000, [ track ] );
const animationAction2 = mixer.clipAction( clip2 );

return {
root: root,
Expand All @@ -59,22 +60,89 @@ export default QUnit.module( 'Animation', () => {
// INSTANCING
QUnit.test( 'Instancing', ( assert ) => {

var mixer = new AnimationMixer();
var clip = new AnimationClip( 'nonname', - 1, [] );
const mixer = new AnimationMixer();
const clip = new AnimationClip( 'nonname', - 1, [] );

var animationAction = new AnimationAction( mixer, clip );
const animationAction = new AnimationAction( mixer, clip );
assert.ok( animationAction, 'animationAction instanciated' );

} );

// PROPERTIES
QUnit.todo( 'blendMode', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'loop', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'time', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'timeScale', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'weight', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'repetitions', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'paused', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'enabled', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'clampWhenFinished', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'zeroSlopeAtStart', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'zeroSlopeAtEnd', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

// PUBLIC STUFF
QUnit.test( 'play', ( assert ) => {

var { mixer, animationAction } = createAnimation();
var animationAction2 = animationAction.play();
const { mixer, animationAction } = createAnimation();
const animationAction2 = animationAction.play();
assert.equal( animationAction, animationAction2, 'AnimationAction.play can be chained.' );

var UserException = function () {
const UserException = function () {

this.message = 'AnimationMixer must activate AnimationAction on play.';

Expand All @@ -100,11 +168,11 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'stop', ( assert ) => {

var { mixer, animationAction } = createAnimation();
var animationAction2 = animationAction.stop();
const { mixer, animationAction } = createAnimation();
const animationAction2 = animationAction.stop();
assert.equal( animationAction, animationAction2, 'AnimationAction.stop can be chained.' );

var UserException = function () {
const UserException = function () {

this.message = 'AnimationMixer must deactivate AnimationAction on stop.';

Expand All @@ -130,8 +198,8 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'reset', ( assert ) => {

var { animationAction } = createAnimation();
var animationAction2 = animationAction.stop();
const { animationAction } = createAnimation();
const animationAction2 = animationAction.stop();
assert.equal( animationAction, animationAction2, 'AnimationAction.reset can be chained.' );
assert.equal( animationAction2.paused, false, 'AnimationAction.reset() sets paused false' );
assert.equal( animationAction2.enabled, true, 'AnimationAction.reset() sets enabled true' );
Expand All @@ -143,7 +211,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'isRunning', ( assert ) => {

var { animationAction } = createAnimation();
const { animationAction } = createAnimation();
assert.notOk( animationAction.isRunning(), 'When an animation is just made, it is not running.' );
animationAction.play();
assert.ok( animationAction.isRunning(), 'When an animation is started, it is running.' );
Expand All @@ -162,7 +230,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'isScheduled', ( assert ) => {

var { mixer, animationAction } = createAnimation();
const { mixer, animationAction } = createAnimation();
assert.notOk( animationAction.isScheduled(), 'When an animation is just made, it is not scheduled.' );
animationAction.play();
assert.ok( animationAction.isScheduled(), 'When an animation is started, it is scheduled.' );
Expand All @@ -176,7 +244,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'startAt', ( assert ) => {

var { mixer, animationAction } = createAnimation();
const { mixer, animationAction } = createAnimation();
animationAction.startAt( 2 );
animationAction.play();
assert.notOk( animationAction.isRunning(), 'When an animation is started at a specific time, it is not running.' );
Expand All @@ -196,7 +264,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'setLoop LoopOnce', ( assert ) => {

var { mixer, animationAction } = createAnimation();
const { mixer, animationAction } = createAnimation();
animationAction.setLoop( LoopOnce );
animationAction.play();
assert.ok( animationAction.isRunning(), 'When an animation is started, it is running.' );
Expand All @@ -211,7 +279,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'setLoop LoopRepeat', ( assert ) => {

var { root, mixer, animationAction } = createAnimation();
const { root, mixer, animationAction } = createAnimation();
animationAction.setLoop( LoopRepeat, 3 );
animationAction.play();
assert.ok( animationAction.isRunning(), 'When an animation is started, it is running.' );
Expand All @@ -232,7 +300,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'setLoop LoopPingPong', ( assert ) => {

var { root, mixer, animationAction } = createAnimation();
const { root, mixer, animationAction } = createAnimation();
animationAction.setLoop( LoopPingPong, 3 );
animationAction.play();
assert.ok( animationAction.isRunning(), 'When an animation is started, it is running.' );
Expand All @@ -253,20 +321,26 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'setEffectiveWeight', ( assert ) => {

var { animationAction } = createAnimation();
const { 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();
QUnit.test( 'setEffectiveWeight - disabled', ( assert ) => {

const { 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(), 0, 'When EffectiveWeight is set to 0.3 when disabled , EffectiveWeight is 0.' );

} );

QUnit.test( 'setEffectiveWeight - over duration', ( assert ) => {

var { root, mixer, animationAction } = createAnimation();
const { root, mixer, animationAction } = createAnimation();
animationAction.setEffectiveWeight( 0.5 );
animationAction.play();
mixer.update( 500 );
Expand All @@ -278,13 +352,13 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'getEffectiveWeight', ( assert ) => {

var { animationAction } = createAnimation();
let { 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();
( { animationAction } = createAnimation() );
assert.equal( animationAction.getEffectiveWeight(), 1, 'When an animation is created, EffectiveWeight is 1.' );
animationAction.enabled = false;
animationAction.setEffectiveWeight( 0.3 );
Expand All @@ -294,7 +368,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'fadeIn', ( assert ) => {

var { mixer, animationAction } = createAnimation();
const { mixer, animationAction } = createAnimation();
animationAction.fadeIn( 1000 );
animationAction.play();
assert.equal( animationAction.getEffectiveWeight(), 1, 'When an animation fadeIn is started, EffectiveWeight is 1.' );
Expand All @@ -311,7 +385,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'fadeOut', ( assert ) => {

var { mixer, animationAction } = createAnimation();
const { mixer, animationAction } = createAnimation();
animationAction.fadeOut( 1000 );
animationAction.play();
assert.equal( animationAction.getEffectiveWeight(), 1, 'When an animation fadeOut is started, EffectiveWeight is 1.' );
Expand All @@ -328,7 +402,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'crossFadeFrom', ( assert ) => {

var { mixer, animationAction, animationAction2 } = createTwoAnimations();
const { mixer, animationAction, animationAction2 } = createTwoAnimations();
animationAction.crossFadeFrom( animationAction2, 1000, false );
animationAction.play();
animationAction2.play();
Expand All @@ -351,7 +425,7 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'crossFadeTo', ( assert ) => {

var { mixer, animationAction, animationAction2 } = createTwoAnimations();
const { mixer, animationAction, animationAction2 } = createTwoAnimations();
animationAction2.crossFadeTo( animationAction, 1000, false );
animationAction.play();
animationAction2.play();
Expand Down Expand Up @@ -422,36 +496,37 @@ export default QUnit.module( 'Animation', () => {

QUnit.test( 'getMixer', ( assert ) => {

var { mixer, animationAction } = createAnimation();
var mixer2 = animationAction.getMixer();
const { mixer, animationAction } = createAnimation();
const mixer2 = animationAction.getMixer();
assert.equal( mixer, mixer2, 'mixer should be returned by getMixer.' );

} );

QUnit.test( 'getClip', ( assert ) => {

var { clip, animationAction } = createAnimation();
var clip2 = animationAction.getClip();
const { clip, animationAction } = createAnimation();
const clip2 = animationAction.getClip();
assert.equal( clip, clip2, 'clip should be returned by getClip.' );

} );

QUnit.test( 'getRoot', ( assert ) => {

var { root, animationAction } = createAnimation();
var root2 = animationAction.getRoot();
const { root, animationAction } = createAnimation();
const root2 = animationAction.getRoot();
assert.equal( root, root2, 'root should be returned by getRoot.' );

} );

// OTHERS
QUnit.test( 'StartAt when already executed once', ( assert ) => {

var root = new Object3D();
var mixer = new AnimationMixer( root );
var track = new NumberKeyframeTrack( '.rotation[x]', [ 0, 750 ], [ 0, 270 ] );
var clip = new AnimationClip( 'clip1', 750, [ track ] );
const root = new Object3D();
const mixer = new AnimationMixer( root );
const track = new NumberKeyframeTrack( '.rotation[x]', [ 0, 750 ], [ 0, 270 ] );
const clip = new AnimationClip( 'clip1', 750, [ track ] );

var animationAction = mixer.clipAction( clip );
const animationAction = mixer.clipAction( clip );
animationAction.setLoop( LoopOnce );
animationAction.clampWhenFinished = true;
animationAction.play();
Expand Down
Loading