|
@@ -11,10 +11,10 @@ CmdSetMaterialMap = function ( object, mapName, newMap ) {
|
|
|
|
|
|
this.object = object;
|
|
this.object = object;
|
|
this.mapName = mapName;
|
|
this.mapName = mapName;
|
|
- this.oldMap = object !== undefined ? object.material[ mapName ] : undefined;
|
|
|
|
|
|
+ this.oldMap = ( object !== undefined ) ? object.material[ mapName ] : undefined;
|
|
this.newMap = newMap;
|
|
this.newMap = newMap;
|
|
- this.objectUuid = object !== undefined ? object.uuid : undefined;
|
|
|
|
|
|
|
|
|
|
+ this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
|
|
this.newMapJSON = serializeMap( this.newMap );
|
|
this.newMapJSON = serializeMap( this.newMap );
|
|
this.oldMapJSON = serializeMap( this.oldMap );
|
|
this.oldMapJSON = serializeMap( this.oldMap );
|
|
|
|
|
|
@@ -63,8 +63,46 @@ CmdSetMaterialMap = function ( object, mapName, newMap ) {
|
|
|
|
|
|
CmdSetMaterialMap.prototype = {
|
|
CmdSetMaterialMap.prototype = {
|
|
|
|
|
|
|
|
+ init: function () {
|
|
|
|
+
|
|
|
|
+ if ( this.object === undefined ) {
|
|
|
|
+
|
|
|
|
+ this.object = this.editor.objectByUuid( this.objectUuid );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if ( this.oldMap === undefined ) {
|
|
|
|
+
|
|
|
|
+ this.oldMap = parseTexture( this.oldMapJSON );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if ( this.newMap === undefined ) {
|
|
|
|
+
|
|
|
|
+ this.newMap = parseTexture( this.newMapJSON );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function parseTexture ( json ) {
|
|
|
|
+
|
|
|
|
+ var map = null;
|
|
|
|
+ if ( json !== null ) {
|
|
|
|
+
|
|
|
|
+ var loader = new THREE.ObjectLoader();
|
|
|
|
+ var images = loader.parseImages( json.images );
|
|
|
|
+ var textures = loader.parseTextures( [ json ], images );
|
|
|
|
+ map = textures[ json.uuid ];
|
|
|
|
+ map.sourceFile = json.sourceFile;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
execute: function () {
|
|
execute: function () {
|
|
|
|
|
|
|
|
+ this.init();
|
|
|
|
+
|
|
this.object.material[ this.mapName ] = this.newMap;
|
|
this.object.material[ this.mapName ] = this.newMap;
|
|
this.object.material.needsUpdate = true;
|
|
this.object.material.needsUpdate = true;
|
|
this.editor.signals.materialChanged.dispatch( this.object.material );
|
|
this.editor.signals.materialChanged.dispatch( this.object.material );
|
|
@@ -73,6 +111,8 @@ CmdSetMaterialMap.prototype = {
|
|
|
|
|
|
undo: function () {
|
|
undo: function () {
|
|
|
|
|
|
|
|
+ this.init();
|
|
|
|
+
|
|
this.object.material[ this.mapName ] = this.oldMap;
|
|
this.object.material[ this.mapName ] = this.oldMap;
|
|
this.object.material.needsUpdate = true;
|
|
this.object.material.needsUpdate = true;
|
|
this.editor.signals.materialChanged.dispatch( this.object.material );
|
|
this.editor.signals.materialChanged.dispatch( this.object.material );
|
|
@@ -85,7 +125,6 @@ CmdSetMaterialMap.prototype = {
|
|
|
|
|
|
output.objectUuid = this.objectUuid;
|
|
output.objectUuid = this.objectUuid;
|
|
output.mapName = this.mapName;
|
|
output.mapName = this.mapName;
|
|
-
|
|
|
|
output.oldMap = this.oldMapJSON;
|
|
output.oldMap = this.oldMapJSON;
|
|
output.newMap = this.newMapJSON;
|
|
output.newMap = this.newMapJSON;
|
|
|
|
|
|
@@ -99,32 +138,9 @@ CmdSetMaterialMap.prototype = {
|
|
|
|
|
|
this.objectUuid = json.objectUuid;
|
|
this.objectUuid = json.objectUuid;
|
|
this.mapName = json.mapName;
|
|
this.mapName = json.mapName;
|
|
-
|
|
|
|
- this.object = this.editor.objectByUuid( json.objectUuid );
|
|
|
|
-
|
|
|
|
this.oldMapJSON = json.oldMap;
|
|
this.oldMapJSON = json.oldMap;
|
|
this.newMapJSON = json.newMap;
|
|
this.newMapJSON = json.newMap;
|
|
|
|
|
|
- this.oldMap = parseTexture( json.oldMap );
|
|
|
|
- this.newMap = parseTexture( json.newMap );
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- function parseTexture ( json ) {
|
|
|
|
-
|
|
|
|
- var map = null;
|
|
|
|
- if ( json !== null ) {
|
|
|
|
-
|
|
|
|
- var loader = new THREE.ObjectLoader();
|
|
|
|
- var images = loader.parseImages( json.images );
|
|
|
|
- var textures = loader.parseTextures( [ json ], images );
|
|
|
|
- map = textures[ json.uuid ];
|
|
|
|
- map.sourceFile = json.sourceFile;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return map;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
};
|
|
};
|