CmdSetPosition.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. this.objectUuid = object !== undefined ? object.uuid : undefined;
  11. if (object !== undefined && newPositionVector !== undefined) {
  12. this.oldPosition = object.position.clone();
  13. this.newPosition = newPositionVector.clone();
  14. }
  15. if (oldPositionVector !== undefined) {
  16. this.oldPosition = oldPositionVector.clone();
  17. }
  18. };
  19. CmdSetPosition.prototype = {
  20. execute: function () {
  21. this.object.position.copy( this.newPosition );
  22. this.object.updateMatrixWorld( true );
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. },
  25. undo: function () {
  26. this.object.position.copy( this.oldPosition );
  27. this.object.updateMatrixWorld( true );
  28. this.editor.signals.objectChanged.dispatch( this.object );
  29. },
  30. update: function ( command ) {
  31. this.newPosition.copy( command.newPosition );
  32. },
  33. toJSON: function () {
  34. var output = Cmd.prototype.toJSON.call( this );
  35. output.objectUuid = this.objectUuid;
  36. output.oldPosition = this.oldPosition.toArray();
  37. output.newPosition = this.newPosition.toArray();
  38. return output;
  39. },
  40. fromJSON: function ( json ) {
  41. Cmd.prototype.fromJSON.call( this, json );
  42. this.object = this.editor.objectByUuid( json.objectUuid );
  43. this.objectUuid = json.objectUuid;
  44. this.oldPosition = new THREE.Vector3().fromArray(json.oldPosition);
  45. this.newPosition = new THREE.Vector3().fromArray(json.newPosition);
  46. }
  47. };