SetMaterialColorCommand.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 object THREE.Object3D
  7. * @param attributeName string
  8. * @param newValue integer representing a hex color value
  9. * @constructor
  10. */
  11. var SetMaterialColorCommand = function ( object, attributeName, newValue ) {
  12. Command.call( this );
  13. this.type = 'SetMaterialColorCommand';
  14. this.name = 'Set Material.' + attributeName;
  15. this.updatable = true;
  16. this.object = object;
  17. this.attributeName = attributeName;
  18. this.oldValue = ( object !== undefined ) ? this.object.material[ this.attributeName ].getHex() : undefined;
  19. this.newValue = newValue;
  20. };
  21. SetMaterialColorCommand.prototype = {
  22. execute: function () {
  23. this.object.material[ this.attributeName ].setHex( this.newValue );
  24. this.editor.signals.materialChanged.dispatch( this.object.material );
  25. },
  26. undo: function () {
  27. this.object.material[ this.attributeName ].setHex( this.oldValue );
  28. this.editor.signals.materialChanged.dispatch( this.object.material );
  29. },
  30. update: function ( cmd ) {
  31. this.newValue = cmd.newValue;
  32. },
  33. toJSON: function () {
  34. var output = Command.prototype.toJSON.call( this );
  35. output.objectUuid = this.object.uuid;
  36. output.attributeName = this.attributeName;
  37. output.oldValue = this.oldValue;
  38. output.newValue = this.newValue;
  39. return output;
  40. },
  41. fromJSON: function ( json ) {
  42. Command.prototype.fromJSON.call( this, json );
  43. this.object = this.editor.objectByUuid( json.objectUuid );
  44. this.attributeName = json.attributeName;
  45. this.oldValue = json.oldValue;
  46. this.newValue = json.newValue;
  47. }
  48. };