SetRotationCommand.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @author dforrer / https://github.com/dforrer
  3. * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
  4. */
  5. /**
  6. * @param editor Editor
  7. * @param object THREE.Object3D
  8. * @param newRotation THREE.Euler
  9. * @param optionalOldRotation THREE.Euler
  10. * @constructor
  11. */
  12. var SetRotationCommand = function ( editor, object, newRotation, optionalOldRotation ) {
  13. Command.call( this, editor );
  14. this.type = 'SetRotationCommand';
  15. this.name = 'Set Rotation';
  16. this.updatable = true;
  17. this.object = object;
  18. if ( object !== undefined && newRotation !== undefined ) {
  19. this.oldRotation = object.rotation.clone();
  20. this.newRotation = newRotation.clone();
  21. }
  22. if ( optionalOldRotation !== undefined ) {
  23. this.oldRotation = optionalOldRotation.clone();
  24. }
  25. };
  26. SetRotationCommand.prototype = {
  27. execute: function () {
  28. this.object.rotation.copy( this.newRotation );
  29. this.object.updateMatrixWorld( true );
  30. this.editor.signals.objectChanged.dispatch( this.object );
  31. },
  32. undo: function () {
  33. this.object.rotation.copy( this.oldRotation );
  34. this.object.updateMatrixWorld( true );
  35. this.editor.signals.objectChanged.dispatch( this.object );
  36. },
  37. update: function ( command ) {
  38. this.newRotation.copy( command.newRotation );
  39. },
  40. toJSON: function () {
  41. var output = Command.prototype.toJSON.call( this );
  42. output.objectUuid = this.object.uuid;
  43. output.oldRotation = this.oldRotation.toArray();
  44. output.newRotation = this.newRotation.toArray();
  45. return output;
  46. },
  47. fromJSON: function ( json ) {
  48. Command.prototype.fromJSON.call( this, json );
  49. this.object = this.editor.objectByUuid( json.objectUuid );
  50. this.oldRotation = new THREE.Euler().fromArray( json.oldRotation );
  51. this.newRotation = new THREE.Euler().fromArray( json.newRotation );
  52. }
  53. };