2
0

SetMaterialColorCommand.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, slot ) {
  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.slot = slot | 0;
  19. var material = this.editor.getObjectMaterial( this.object, this.slot );
  20. //this.oldValue = ( object !== undefined ) ? this.object.material[ this.attributeName ].getHex() : undefined;
  21. this.oldValue = ( material !== undefined ) ? material[ this.attributeName ].getHex() : undefined;
  22. this.newValue = newValue;
  23. };
  24. SetMaterialColorCommand.prototype = {
  25. execute: function () {
  26. var material = this.editor.getObjectMaterial( this.object, this.slot )
  27. material[ this.attributeName ].setHex( this.newValue );
  28. this.editor.signals.materialChanged.dispatch( material );
  29. },
  30. undo: function () {
  31. var material = this.editor.getObjectMaterial( this.object, this.slot )
  32. material[ this.attributeName ].setHex( this.oldValue );
  33. this.editor.signals.materialChanged.dispatch( material );
  34. },
  35. update: function ( cmd ) {
  36. this.newValue = cmd.newValue;
  37. },
  38. toJSON: function () {
  39. var output = Command.prototype.toJSON.call( this );
  40. output.objectUuid = this.object.uuid;
  41. output.attributeName = this.attributeName;
  42. output.oldValue = this.oldValue;
  43. output.newValue = this.newValue;
  44. return output;
  45. },
  46. fromJSON: function ( json ) {
  47. Command.prototype.fromJSON.call( this, json );
  48. this.object = this.editor.objectByUuid( json.objectUuid );
  49. this.attributeName = json.attributeName;
  50. this.oldValue = json.oldValue;
  51. this.newValue = json.newValue;
  52. }
  53. };