CmdSetPosition.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Created by Daniel on 23.07.15.
  3. */
  4. CmdSetPosition = function ( object, newPositionVector, oldPositionVector ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetPosition';
  7. this.name = 'Set Position';
  8. this.updatable = true;
  9. this.object = object;
  10. if ( object !== undefined && newPositionVector !== undefined ) {
  11. this.oldPosition = object.position.clone();
  12. this.newPosition = newPositionVector.clone();
  13. }
  14. if ( oldPositionVector !== undefined ) {
  15. this.oldPosition = oldPositionVector.clone();
  16. }
  17. };
  18. CmdSetPosition.prototype = {
  19. execute: function () {
  20. this.object.position.copy( this.newPosition );
  21. this.object.updateMatrixWorld( true );
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. },
  24. undo: function () {
  25. this.object.position.copy( this.oldPosition );
  26. this.object.updateMatrixWorld( true );
  27. this.editor.signals.objectChanged.dispatch( this.object );
  28. },
  29. update: function ( command ) {
  30. this.newPosition.copy( command.newPosition );
  31. },
  32. toJSON: function () {
  33. var output = Cmd.prototype.toJSON.call( this );
  34. output.objectUuid = this.object.uuid;
  35. output.oldPosition = this.oldPosition.toArray();
  36. output.newPosition = this.newPosition.toArray();
  37. return output;
  38. },
  39. fromJSON: function ( json ) {
  40. Cmd.prototype.fromJSON.call( this, json );
  41. this.object = this.editor.objectByUuid( json.objectUuid );
  42. this.oldPosition = new THREE.Vector3().fromArray( json.oldPosition );
  43. this.newPosition = new THREE.Vector3().fromArray( json.newPosition );
  44. }
  45. };