SetMaterialVectorCommand.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. var SetMaterialVectorCommand = function ( editor, object, attributeName, newValue, materialSlot ) {
  6. Command.call( this, editor );
  7. this.type = 'SetMaterialColorCommand';
  8. this.name = 'Set Material.' + attributeName;
  9. this.updatable = true;
  10. this.object = object;
  11. this.material = this.editor.getObjectMaterial( object, materialSlot );
  12. this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].toArray() : undefined;
  13. this.newValue = newValue;
  14. this.attributeName = attributeName;
  15. };
  16. SetMaterialVectorCommand.prototype = {
  17. execute: function () {
  18. this.material[ this.attributeName ].fromArray( this.newValue );
  19. this.editor.signals.materialChanged.dispatch( this.material );
  20. },
  21. undo: function () {
  22. this.material[ this.attributeName ].fromArray( this.oldValue );
  23. this.editor.signals.materialChanged.dispatch( this.material );
  24. },
  25. update: function ( cmd ) {
  26. this.newValue = cmd.newValue;
  27. },
  28. toJSON: function () {
  29. var output = Command.prototype.toJSON.call( this );
  30. output.objectUuid = this.object.uuid;
  31. output.attributeName = this.attributeName;
  32. output.oldValue = this.oldValue;
  33. output.newValue = this.newValue;
  34. return output;
  35. },
  36. fromJSON: function ( json ) {
  37. Command.prototype.fromJSON.call( this, json );
  38. this.object = this.editor.objectByUuid( json.objectUuid );
  39. this.attributeName = json.attributeName;
  40. this.oldValue = json.oldValue;
  41. this.newValue = json.newValue;
  42. }
  43. };