CmdSetPosition.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.updatable = true;
  8. this.object = object;
  9. this.objectUuid = object !== undefined ? object.uuid : undefined;
  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.objectUuid;
  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.objectUuid = json.objectUuid;
  43. this.oldPosition = new THREE.Vector3().fromArray(json.oldPosition);
  44. this.newPosition = new THREE.Vector3().fromArray(json.newPosition);
  45. }
  46. };