Forráskód Böngészése

Editor: Material commands clean up.

Mr.doob 8 éve
szülő
commit
a2a9cd232c

+ 13 - 13
editor/js/commands/SetMaterialColorCommand.js

@@ -10,7 +10,7 @@
  * @constructor
  */
 
-var SetMaterialColorCommand = function ( object, attributeName, newValue, slot ) {
+var SetMaterialColorCommand = function ( object, attributeName, newValue, materialSlot ) {
 
 	Command.call( this );
 
@@ -19,30 +19,30 @@ var SetMaterialColorCommand = function ( object, attributeName, newValue, slot )
 	this.updatable = true;
 
 	this.object = object;
-	this.attributeName = attributeName;
-	this.slot = slot;
-
-	var material = this.editor.getObjectMaterial( this.object, this.slot );
+	this.material = this.editor.getObjectMaterial( object, materialSlot );
 
-	this.oldValue = ( material !== undefined ) ? material[ this.attributeName ].getHex() : undefined;
+	this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ].getHex() : undefined;
 	this.newValue = newValue;
-	
+
+	this.attributeName = attributeName;
+
 };
 
 SetMaterialColorCommand.prototype = {
 
 	execute: function () {
-		var material = this.editor.getObjectMaterial( this.object, this.slot )
-		material[ this.attributeName ].setHex( this.newValue );
-		this.editor.signals.materialChanged.dispatch( material );
+
+		this.material[ this.attributeName ].setHex( this.newValue );
+
+		this.editor.signals.materialChanged.dispatch( this.material );
 
 	},
 
 	undo: function () {
-		var material = this.editor.getObjectMaterial( this.object, this.slot )
 
-		material[ this.attributeName ].setHex( this.oldValue );
-		this.editor.signals.materialChanged.dispatch( material );
+		this.material[ this.attributeName ].setHex( this.oldValue );
+
+		this.editor.signals.materialChanged.dispatch( this.material );
 
 	},
 

+ 6 - 13
editor/js/commands/SetMaterialCommand.js

@@ -10,7 +10,7 @@
  */
 
 
-var SetMaterialCommand = function ( object, newMaterial , slot) {
+var SetMaterialCommand = function ( object, newMaterial, materialSlot ) {
 
 	Command.call( this );
 
@@ -18,31 +18,25 @@ var SetMaterialCommand = function ( object, newMaterial , slot) {
 	this.name = 'New Material';
 
 	this.object = object;
+	this.materialSlot = materialSlot;
 
-	this.slot = slot;
-
-	var material = this.editor.getObjectMaterial( this.object, this.slot );
-
-	this.oldMaterial = material;
-
+	this.oldMaterial = this.editor.getObjectMaterial( object, materialSlot );
 	this.newMaterial = newMaterial;
-	
+
 };
 
 SetMaterialCommand.prototype = {
 
 	execute: function () {
-		
-		this.editor.setObjectMaterial( this.object, this.slot, this.newMaterial );
 
+		this.editor.setObjectMaterial( this.object, this.materialSlot, this.newMaterial );
 		this.editor.signals.materialChanged.dispatch( this.newMaterial );
 
 	},
 
 	undo: function () {
-		
-		this.editor.setObjectMaterial( this.object, this.slot, this.oldMaterial );
 
+		this.editor.setObjectMaterial( this.object, this.materialSlot, this.oldMaterial );
 		this.editor.signals.materialChanged.dispatch( this.oldMaterial );
 
 	},
@@ -67,7 +61,6 @@ SetMaterialCommand.prototype = {
 		this.oldMaterial = parseMaterial( json.oldMaterial );
 		this.newMaterial = parseMaterial( json.newMaterial );
 
-
 		function parseMaterial ( json ) {
 
 			var loader = new THREE.ObjectLoader();

+ 7 - 2
editor/js/commands/SetMaterialMapCommand.js

@@ -13,15 +13,18 @@
 var SetMaterialMapCommand = function ( object, mapName, newMap, materialSlot ) {
 
 	Command.call( this );
+
 	this.type = 'SetMaterialMapCommand';
 	this.name = 'Set Material.' + mapName;
 
 	this.object = object;
-	this.mapName = mapName;
-	this.material = ( Array.isArray( object.material ) ) ? object.material[ materialSlot ] : object.material;
+	this.material = this.editor.getObjectMaterial( object, materialSlot );
+
 	this.oldMap = ( object !== undefined ) ? this.material[ mapName ] : undefined;
 	this.newMap = newMap;
 
+	this.mapName = mapName;
+
 };
 
 SetMaterialMapCommand.prototype = {
@@ -30,6 +33,7 @@ SetMaterialMapCommand.prototype = {
 
 		this.material[ this.mapName ] = this.newMap;
 		this.material.needsUpdate = true;
+
 		this.editor.signals.materialChanged.dispatch( this.material );
 
 	},
@@ -38,6 +42,7 @@ SetMaterialMapCommand.prototype = {
 
 		this.material[ this.mapName ] = this.oldMap;
 		this.material.needsUpdate = true;
+
 		this.editor.signals.materialChanged.dispatch( this.material );
 
 	},

+ 13 - 13
editor/js/commands/SetMaterialValueCommand.js

@@ -10,21 +10,20 @@
  * @constructor
  */
 
-var SetMaterialValueCommand = function ( object, attributeName, newValue, slot ) {
+var SetMaterialValueCommand = function ( object, attributeName, newValue, materialSlot ) {
 
 	Command.call( this );
 
 	this.type = 'SetMaterialValueCommand';
 	this.name = 'Set Material.' + attributeName;
 	this.updatable = true;
-	this.slot = slot;
 
 	this.object = object;
+	this.material = this.editor.getObjectMaterial( object, materialSlot );
 
-	var material = this.editor.getObjectMaterial( this.object, this.slot );
-	
-	this.oldValue = ( material !== undefined ) ? material[ attributeName ] : undefined;
+	this.oldValue = ( this.material !== undefined ) ? this.material[ attributeName ] : undefined;
 	this.newValue = newValue;
+
 	this.attributeName = attributeName;
 
 };
@@ -32,21 +31,22 @@ var SetMaterialValueCommand = function ( object, attributeName, newValue, slot )
 SetMaterialValueCommand.prototype = {
 
 	execute: function () {
-		var material = this.editor.getObjectMaterial( this.object, this.slot );
-		material[ this.attributeName ] = this.newValue;
-		material.needsUpdate = true;
+
+		this.material[ this.attributeName ] = this.newValue;
+		this.material.needsUpdate = true;
+
 		this.editor.signals.objectChanged.dispatch( this.object );
-		this.editor.signals.materialChanged.dispatch( material );
+		this.editor.signals.materialChanged.dispatch( this.material );
 
 	},
 
 	undo: function () {
-		var material = this.editor.getObjectMaterial( this.object, this.slot );
 
-		material[ this.attributeName ] = this.oldValue;
-		material.needsUpdate = true;
+		this.material[ this.attributeName ] = this.oldValue;
+		this.material.needsUpdate = true;
+
 		this.editor.signals.objectChanged.dispatch( this.object );
-		this.editor.signals.materialChanged.dispatch( material );
+		this.editor.signals.materialChanged.dispatch( this.material );
 
 	},