2
0

TestNestedDoUndoRedo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @author lxxxvi / https://github.com/lxxxvi
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. module( "NestedDoUndoRedo" );
  6. test( "Test nested Do's, Undo's and Redo's", function() {
  7. var editor = new Editor();
  8. var mesh = aBox( 'One box unlike all others' );
  9. var initPosX = 2 ;
  10. var initPosY = 3 ;
  11. var initPosZ = 4 ;
  12. var initRotationX = 12 ;
  13. var initRotationY = 13 ;
  14. var initRotationZ = 14 ;
  15. var initScaleX = 22 ;
  16. var initScaleY = 23 ;
  17. var initScaleZ = 24 ;
  18. mesh.position.x = initPosX ;
  19. mesh.position.y = initPosY ;
  20. mesh.position.z = initPosZ ;
  21. mesh.rotation.x = initRotationX ;
  22. mesh.rotation.y = initRotationY ;
  23. mesh.rotation.z = initRotationZ ;
  24. mesh.scale.x = initScaleX ;
  25. mesh.scale.y = initScaleY ;
  26. mesh.scale.z = initScaleZ ;
  27. // let's begin
  28. editor.execute( new AddObjectCommand( mesh ) );
  29. var newPos = new THREE.Vector3( initPosX + 100, initPosY, initPosZ );
  30. editor.execute( new SetPositionCommand( mesh, newPos ) );
  31. var newRotation = new THREE.Euler( initRotationX, initRotationY + 1000, initRotationZ );
  32. editor.execute( new SetRotationCommand( mesh, newRotation ) );
  33. var newScale = new THREE.Vector3( initScaleX, initScaleY, initScaleZ + 10000 );
  34. editor.execute( new SetScaleCommand( mesh, newScale ) );
  35. /* full check */
  36. ok( mesh.position.x == 102, "OK, X position is correct " );
  37. ok( mesh.position.y == 3, "OK, Y position is correct " );
  38. ok( mesh.position.z == 4, "OK, Z position is correct " );
  39. ok( mesh.rotation.x == 12, "OK, X rotation is correct " );
  40. ok( mesh.rotation.y == 1013, "OK, Y rotation is correct " );
  41. ok( mesh.rotation.z == 14, "OK, Z rotation is correct " );
  42. ok( mesh.scale.x == 22, "OK, X scale is correct " );
  43. ok( mesh.scale.y == 23, "OK, Y scale is correct " );
  44. ok( mesh.scale.z == 10024, "OK, Z scale is correct " );
  45. editor.undo(); // rescaling undone
  46. editor.undo(); // rotation undone
  47. editor.undo(); // translation undone
  48. /* full check */
  49. ok( mesh.position.x == 2, "OK, X position is correct " );
  50. ok( mesh.position.y == 3, "OK, Y position is correct " );
  51. ok( mesh.position.z == 4, "OK, Z position is correct " );
  52. ok( mesh.rotation.x == 12, "OK, X rotation is correct " );
  53. ok( mesh.rotation.y == 13, "OK, Y rotation is correct " );
  54. ok( mesh.rotation.z == 14, "OK, Z rotation is correct " );
  55. ok( mesh.scale.x == 22, "OK, X scale is correct " );
  56. ok( mesh.scale.y == 23, "OK, Y scale is correct " );
  57. ok( mesh.scale.z == 24, "OK, Z scale is correct " );
  58. editor.redo(); // translation redone
  59. editor.redo(); // rotation redone
  60. editor.execute( new RemoveObjectCommand( mesh ) );
  61. ok( editor.scene.children.length == 0, "OK, object removal was successful" );
  62. editor.undo(); // removal undone
  63. ok( mesh.rotation.y == 1013, "OK, Y rotation is correct " );
  64. editor.undo(); // rotation undone (expected!)
  65. /* full check */
  66. ok( mesh.position.x == 102, "OK, X position is correct " );
  67. ok( mesh.position.y == 3, "OK, Y position is correct " );
  68. ok( mesh.position.z == 4, "OK, Z position is correct " );
  69. ok( mesh.rotation.x == 12, "OK, X rotation is correct " );
  70. ok( mesh.rotation.y == 13, "OK, Y rotation is correct " );
  71. ok( mesh.rotation.z == 14, "OK, Z rotation is correct " );
  72. ok( mesh.scale.x == 22, "OK, X scale is correct " );
  73. ok( mesh.scale.y == 23, "OK, Y scale is correct " );
  74. ok( mesh.scale.z == 24, "OK, Z scale is correct " );
  75. } );