AnimationAction.tests.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**
  2. * @author TristanVALCKE / https://github.com/Itee
  3. */
  4. /* global QUnit */
  5. import { AnimationAction } from '../../../../src/animation/AnimationAction';
  6. import { AnimationMixer } from '../../../../src/animation/AnimationMixer';
  7. import { AnimationClip } from '../../../../src/animation/AnimationClip';
  8. import { NumberKeyframeTrack } from '../../../../src/animation/tracks/NumberKeyframeTrack';
  9. import { Object3D } from '../../../../src/core/Object3D';
  10. import { LoopOnce, LoopRepeat, LoopPingPong } from '../../../../src/constants';
  11. function createAnimation(){
  12. var mixer = new AnimationMixer(new Object3D());
  13. var track = new NumberKeyframeTrack( ".rotation[x]", [ 0, 1000 ], [ 0, 360 ] );
  14. var clip = new AnimationClip( "clip1", 1000, [track] );
  15. var animationAction = new AnimationAction( mixer, clip );
  16. return { mixer :mixer,track:track,clip:clip,animationAction:animationAction};
  17. }
  18. export default QUnit.module( 'Animation', () => {
  19. QUnit.module( 'AnimationAction', () => {
  20. // INSTANCING
  21. QUnit.test( "Instancing", ( assert ) => {
  22. var mixer = new AnimationMixer();
  23. var clip = new AnimationClip( "nonname", - 1, [] );
  24. var animationAction = new AnimationAction( mixer, clip );
  25. assert.ok( animationAction, "animationAction instanciated" );
  26. } );
  27. // PUBLIC STUFF
  28. QUnit.test( "play", ( assert ) => {
  29. var {mixer,animationAction} = createAnimation();
  30. var animationAction2 = animationAction.play();
  31. assert.equal( animationAction, animationAction2, "AnimationAction.play can be chained." );
  32. var UserException = function () {
  33. this.message = "AnimationMixer must activate AnimationAction on play.";
  34. };
  35. mixer._activateAction = function ( action ) {
  36. if ( action === animationAction ) {
  37. throw new UserException();
  38. }
  39. };
  40. assert.throws( () => {
  41. animationAction.play();
  42. }, new UserException() );
  43. } );
  44. QUnit.test( "stop", ( assert ) => {
  45. var {mixer,animationAction} = createAnimation();
  46. var animationAction2 = animationAction.stop();
  47. assert.equal( animationAction, animationAction2, "AnimationAction.stop can be chained." );
  48. var UserException = function () {
  49. this.message = "AnimationMixer must deactivate AnimationAction on stop.";
  50. };
  51. mixer._deactivateAction = function ( action ) {
  52. if ( action === animationAction ) {
  53. throw new UserException();
  54. }
  55. };
  56. assert.throws( () => {
  57. animationAction.stop();
  58. }, new UserException() );
  59. } );
  60. QUnit.test( "reset", ( assert ) => {
  61. var {mixer,animationAction} = createAnimation();
  62. var animationAction2 = animationAction.stop();
  63. assert.equal( animationAction, animationAction2, "AnimationAction.reset can be chained." );
  64. assert.equal( animationAction2.paused, false, "AnimationAction.reset() sets paused false" );
  65. assert.equal( animationAction2.enabled, true, "AnimationAction.reset() sets enabled true" );
  66. assert.equal( animationAction2.time, 0, "AnimationAction.reset() resets time." );
  67. assert.equal( animationAction2._loopCount, - 1, "AnimationAction.reset() resets loopcount." );
  68. assert.equal( animationAction2._startTime, null, "AnimationAction.reset() removes starttime." );
  69. } );
  70. QUnit.test( "isRunning", ( assert ) => {
  71. var {mixer,animationAction} = createAnimation();
  72. assert.notOk( animationAction.isRunning(), "When an animation is just made, it is not running." );
  73. animationAction.play();
  74. assert.ok( animationAction.isRunning(), "When an animation is started, it is running." );
  75. animationAction.stop();
  76. assert.notOk( animationAction.isRunning(), "When an animation is stopped, it is not running." );
  77. animationAction.play();
  78. animationAction.paused = true;
  79. assert.notOk( animationAction.isRunning(), "When an animation is paused, it is not running." );
  80. animationAction.paused = false;
  81. animationAction.enabled = false;
  82. assert.notOk( animationAction.isRunning(), "When an animation is not enabled, it is not running." );
  83. animationAction.enabled = true;
  84. assert.ok( animationAction.isRunning(), "When an animation is enabled, it is running." );
  85. } );
  86. QUnit.test( "isScheduled", ( assert ) => {
  87. var {mixer,animationAction} = createAnimation();
  88. assert.notOk( animationAction.isScheduled(), "When an animation is just made, it is not scheduled." );
  89. animationAction.play();
  90. assert.ok( animationAction.isScheduled(), "When an animation is started, it is scheduled." );
  91. mixer.update(1);
  92. assert.ok( animationAction.isScheduled(), "When an animation is updated, it is scheduled." );
  93. animationAction.stop();
  94. assert.notOk( animationAction.isScheduled(), "When an animation is stopped, it isn't scheduled anymore." );
  95. } );
  96. QUnit.test( "startAt", ( assert ) => {
  97. var {mixer,animationAction} = createAnimation();
  98. animationAction.startAt(2);
  99. animationAction.play();
  100. assert.notOk( animationAction.isRunning(), "When an animation is started at a specific time, it is not running." );
  101. assert.ok( animationAction.isScheduled(), "When an animation is started at a specific time, it is scheduled." );
  102. mixer.update(1);
  103. assert.notOk( animationAction.isRunning(), "When an animation is started at a specific time and the interval is not passed, it is not running." );
  104. assert.ok( animationAction.isScheduled(), "When an animation is started at a specific time and the interval is not passed, it is scheduled." );
  105. mixer.update(1);
  106. assert.ok( animationAction.isRunning(), "When an animation is started at a specific time and the interval is passed, it is running." );
  107. assert.ok( animationAction.isScheduled(), "When an animation is started at a specific time and the interval is passed, it is scheduled." );
  108. animationAction.stop();
  109. assert.notOk( animationAction.isRunning(), "When an animation is stopped, it is not running." );
  110. assert.notOk( animationAction.isScheduled(), "When an animation is stopped, it is not scheduled." );
  111. } );
  112. QUnit.test( "setLoop LoopOnce", ( assert ) => {
  113. var {mixer,animationAction} = createAnimation();
  114. animationAction.setLoop(LoopOnce);
  115. animationAction.play();
  116. assert.ok( animationAction.isRunning(), "When an animation is started, it is running." );
  117. mixer.update(500);
  118. assert.ok( animationAction.isRunning(), "When an animation is in the first loop, it is running." );
  119. mixer.update(500);
  120. assert.notOk( animationAction.isRunning(), "When an animation is ended, it is not running." );
  121. mixer.update(500);
  122. assert.notOk( animationAction.isRunning(), "When an animation is ended, it is not running." );
  123. } );
  124. QUnit.test( "setLoop LoopRepeat", ( assert ) => {
  125. var {mixer,animationAction} = createAnimation();
  126. animationAction.setLoop(LoopRepeat,3);
  127. animationAction.play();
  128. assert.ok( animationAction.isRunning(), "When an animation is started, it is running." );
  129. mixer.update(500);
  130. assert.ok( animationAction.isRunning(), "When an animation is in the first loop, it is running." );
  131. mixer.update(1000);
  132. assert.ok( animationAction.isRunning(), "When an animation is in second loop when in looprepeat 3 times, it is running." );
  133. mixer.update(1000);
  134. assert.ok( animationAction.isRunning(), "When an animation is in third loop when in looprepeat 3 times, it is running." );
  135. mixer.update(1000);
  136. assert.notOk( animationAction.isRunning(), "When an animation ended his third loop when in looprepeat 3 times, it is not running anymore." );
  137. mixer.update(1000);
  138. assert.notOk( animationAction.isRunning(), "When an animation ended his third loop when in looprepeat 3 times, it stays not running anymore." );
  139. } );
  140. QUnit.todo( "setEffectiveWeight", ( assert ) => {
  141. assert.ok( false, "everything's gonna be alright" );
  142. } );
  143. QUnit.todo( "getEffectiveWeight", ( assert ) => {
  144. assert.ok( false, "everything's gonna be alright" );
  145. } );
  146. QUnit.todo( "fadeIn", ( assert ) => {
  147. assert.ok( false, "everything's gonna be alright" );
  148. } );
  149. QUnit.todo( "fadeOut", ( assert ) => {
  150. assert.ok( false, "everything's gonna be alright" );
  151. } );
  152. QUnit.todo( "crossFadeFrom", ( assert ) => {
  153. assert.ok( false, "everything's gonna be alright" );
  154. } );
  155. QUnit.todo( "crossFadeTo", ( assert ) => {
  156. assert.ok( false, "everything's gonna be alright" );
  157. } );
  158. QUnit.todo( "stopFading", ( assert ) => {
  159. assert.ok( false, "everything's gonna be alright" );
  160. } );
  161. QUnit.todo( "setEffectiveTimeScale", ( assert ) => {
  162. assert.ok( false, "everything's gonna be alright" );
  163. } );
  164. QUnit.todo( "getEffectiveTimeScale", ( assert ) => {
  165. assert.ok( false, "everything's gonna be alright" );
  166. } );
  167. QUnit.todo( "setDuration", ( assert ) => {
  168. assert.ok( false, "everything's gonna be alright" );
  169. } );
  170. QUnit.todo( "syncWith", ( assert ) => {
  171. assert.ok( false, "everything's gonna be alright" );
  172. } );
  173. QUnit.todo( "halt", ( assert ) => {
  174. assert.ok( false, "everything's gonna be alright" );
  175. } );
  176. QUnit.todo( "warp", ( assert ) => {
  177. assert.ok( false, "everything's gonna be alright" );
  178. } );
  179. QUnit.todo( "stopWarping", ( assert ) => {
  180. assert.ok( false, "everything's gonna be alright" );
  181. } );
  182. QUnit.todo( "getMixer", ( assert ) => {
  183. assert.ok( false, "everything's gonna be alright" );
  184. } );
  185. QUnit.todo( "getClip", ( assert ) => {
  186. assert.ok( false, "everything's gonna be alright" );
  187. } );
  188. QUnit.todo( "getRoot", ( assert ) => {
  189. assert.ok( false, "everything's gonna be alright" );
  190. } );
  191. } );
  192. } );
粤ICP备19079148号