Browse Source

experimental

tested to see if it made sense to separate fromJSON and initialization
of references like this.object

**pro:** serialized attribute no longer needed

**con:** fromJSON is more limited because you can’t search for objects
with objectByUuid when they don’t exist yet.
Daniel 9 years ago
parent
commit
cf5cbfbfaf

+ 0 - 1
editor/js/Cmd.js

@@ -5,7 +5,6 @@
 Cmd = function () {
 
 	this.id = -1;
-	this.serialized = false;
 	this.updatable = false;
 	this.type = '';
 	this.name = '';

+ 19 - 8
editor/js/CmdAddObject.js

@@ -59,14 +59,33 @@ CmdAddObject = function ( object ) {
 
 CmdAddObject.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectJSON.object.uuid );
+
+		}
+
+		if ( this.object === undefined ) {
+
+			var loader = new THREE.ObjectLoader();
+			this.object = loader.parse( this.objectJSON );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
 		this.editor.addObject( this.object );
 
 	},
 
 	undo: function () {
 
+		this.init();
 		this.editor.removeObject( this.object );
 		this.editor.deselect();
 
@@ -87,14 +106,6 @@ CmdAddObject.prototype = {
 		Cmd.prototype.fromJSON.call( this, json );
 
 		this.objectJSON = json.object;
-		this.object = this.editor.objectByUuid( json.object.object.uuid );
-
-		if ( this.object === undefined ) {
-
-			var loader = new THREE.ObjectLoader();
-			this.object = loader.parse( json.object );
-
-		}
 
 	}
 

+ 15 - 2
editor/js/CmdAddScript.js

@@ -10,7 +10,7 @@ CmdAddScript = function ( object, script ) {
 	this.name = 'Add Script';
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
 	this.script = script;
 
@@ -18,8 +18,20 @@ CmdAddScript = function ( object, script ) {
 
 CmdAddScript.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
 
 			this.editor.scripts[ this.object.uuid ] = [];
@@ -34,6 +46,8 @@ CmdAddScript.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
 
 		var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
@@ -65,7 +79,6 @@ CmdAddScript.prototype = {
 
 		this.objectUuid = json.objectUuid;
 		this.script = json.script;
-		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 31 - 13
editor/js/CmdMoveObject.js

@@ -10,22 +10,22 @@ CmdMoveObject = function ( object, newParent, newBefore ) {
 	this.name = 'Move Object';
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
-	this.oldParent = object !== undefined ? object.parent : undefined;
-	this.oldParentUuid = this.oldParent !== undefined ? this.oldParent.uuid : undefined;
-	this.oldIndex = this.oldParent !== undefined ? this.oldParent.children.indexOf( this.object ) : undefined;
+	this.oldParent = ( object !== undefined ) ? object.parent : undefined;
+	this.oldParentUuid = ( this.oldParent !== undefined ) ? this.oldParent.uuid : undefined;
+	this.oldIndex = ( this.oldParent !== undefined ) ? this.oldParent.children.indexOf( this.object ) : undefined;
 
 	this.newParent = newParent;
-	this.newParentUuid = newParent !== undefined ? newParent.uuid : undefined;
+	this.newParentUuid = ( newParent !== undefined ) ? newParent.uuid : undefined;
 
 	if ( newBefore !== undefined ) {
 
-		this.newIndex = newParent !== undefined ? newParent.children.indexOf( newBefore ) : undefined;
+		this.newIndex = ( newParent !== undefined ) ? newParent.children.indexOf( newBefore ) : undefined;
 
 	} else {
 
-		this.newIndex = newParent !== undefined ? newParent.children.length : undefined;
+		this.newIndex = ( newParent !== undefined ) ? newParent.children.length : undefined;
 
 	}
 
@@ -41,8 +41,30 @@ CmdMoveObject = function ( object, newParent, newBefore ) {
 
 CmdMoveObject.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+				this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+		if ( this.oldParent === undefined ) {
+
+			this.oldParent = this.editor.objectByUuid( this.oldParentUuid );
+
+		}
+		if ( this.newParent === undefined ) {
+
+			this.newParent = this.editor.objectByUuid( this.newParentUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.oldParent.remove( this.object );
 
 		var children = this.newParent.children;
@@ -55,6 +77,8 @@ CmdMoveObject.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.newParent.remove( this.object );
 
 		var children = this.oldParent.children;
@@ -83,15 +107,9 @@ CmdMoveObject.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
-
-		this.oldParent = this.editor.objectByUuid( json.oldParentUuid );
 		this.oldParentUuid = json.oldParentUuid;
-
-		this.newParent = this.editor.objectByUuid( json.newParentUuid );
 		this.newParentUuid = json.newParentUuid;
-
 		this.newIndex = json.newIndex;
 		this.oldIndex = json.oldIndex;
 

+ 1 - 1
editor/js/CmdMultiCmds.js

@@ -9,7 +9,7 @@ CmdMultiCmds = function ( cmdArray ) {
 	this.type = 'CmdMultiCmds';
 	this.name = 'Multiple Changes';
 
-	this.cmdArray = cmdArray !== undefined ? cmdArray : [];
+	this.cmdArray = ( cmdArray !== undefined ) ? cmdArray : [];
 
 };
 

+ 34 - 19
editor/js/CmdRemoveObject.js

@@ -10,8 +10,8 @@ CmdRemoveObject = function ( object ) {
 	this.name = 'Remove Object';
 
 	this.object = object;
-	this.parent = object !== undefined ? object.parent : undefined;
-	this.parentUuid = object !== undefined ? object.parent.uuid : undefined;
+	this.parent = ( object !== undefined ) ? object.parent : undefined;
+	this.parentUuid = ( object !== undefined ) ? object.parent.uuid : undefined;
 
 	if ( object !== undefined ) {
 
@@ -62,8 +62,36 @@ CmdRemoveObject = function ( object ) {
 
 CmdRemoveObject.prototype = {
 
+	init: function () {
+
+		if ( this.parent === undefined ) {
+
+			this.parent = this.editor.objectByUuid( this.parentUuid );
+
+		}
+		if ( this.parent === undefined ) {
+
+			this.parent = this.editor.scene;
+
+		}
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectJSON.object.uuid );
+
+		}
+		if ( this.object === undefined ) {
+
+			var loader = new THREE.ObjectLoader();
+			this.object = loader.parse( this.objectJSON );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.index = this.parent.children.indexOf( this.object );
 
 		var scope = this.editor;
@@ -82,6 +110,8 @@ CmdRemoveObject.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		var scope = this.editor;
 
 		this.object.traverse( function ( child ) {
@@ -117,24 +147,9 @@ CmdRemoveObject.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.parent = this.editor.objectByUuid( json.parentUuid );
-		if ( this.parent === undefined ) {
-
-			this.parent = this.editor.scene;
-
-		}
-		this.parentUuid = json.parentUuid;
-
-		this.index = json.index;
-		this.object = this.editor.objectByUuid( json.object.object.uuid );
-
-		if ( this.object === undefined ) {
-
-			var loader = new THREE.ObjectLoader();
-			this.object = loader.parse( json.object );
-
-		}
 		this.objectJSON = json.object;
+		this.index = json.index;
+		this.parentUuid = json.parentUuid;
 
 	}
 

+ 15 - 2
editor/js/CmdRemoveScript.js

@@ -10,16 +10,28 @@ CmdRemoveScript = function ( object, script ) {
 	this.name = 'Remove Script';
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
 
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.script = script;
 
 };
 
 CmdRemoveScript.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
 
 		this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
@@ -36,6 +48,8 @@ CmdRemoveScript.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
 
 			this.editor.scripts[ this.object.uuid ] = [];
@@ -67,7 +81,6 @@ CmdRemoveScript.prototype = {
 		this.objectUuid = json.objectUuid;
 		this.script = json.script;
 		this.index = json.index;
-		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 14 - 3
editor/js/CmdSetColor.js

@@ -11,17 +11,28 @@ CmdSetColor = function ( object, attributeName, newValue ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.attributeName = attributeName;
-	this.oldValue = object !== undefined ? this.object[ this.attributeName ].getHex() : undefined;
+	this.oldValue = ( object !== undefined ) ? this.object[ this.attributeName ].getHex() : undefined;
 	this.newValue = newValue;
 
 };
 
 CmdSetColor.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
 		this.object[ this.attributeName ].setHex( this.newValue );
 		this.editor.signals.objectChanged.dispatch( this.object );
 
@@ -29,6 +40,7 @@ CmdSetColor.prototype = {
 
 	undo: function () {
 
+		this.init();
 		this.object[ this.attributeName ].setHex( this.oldValue );
 		this.editor.signals.objectChanged.dispatch( this.object );
 
@@ -57,7 +69,6 @@ CmdSetColor.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;

+ 39 - 20
editor/js/CmdSetGeometry.js

@@ -11,20 +11,49 @@ CmdSetGeometry = function ( object, newGeometry ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
-	this.oldGeometry = object !== undefined ? object.geometry : undefined;
+	this.oldGeometry = ( object !== undefined ) ? object.geometry : undefined;
 	this.newGeometry = newGeometry;
 
-	this.oldGeometryJSON = object !== undefined ? object.geometry.toJSON() : undefined;
-	this.newGeometryJSON = newGeometry !== undefined ? newGeometry.toJSON() : undefined;
+	this.oldGeometryJSON = ( object !== undefined ) ? object.geometry.toJSON() : undefined;
+	this.newGeometryJSON = ( newGeometry !== undefined ) ? newGeometry.toJSON() : undefined;
 
 };
 
 CmdSetGeometry.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+		if ( this.oldGeometry === undefined ) {
+
+			this.oldGeometry = parseGeometry( this.oldGeometryJSON );
+
+		}
+		if ( this.newGeometry === undefined ) {
+
+			this.newGeometry = parseGeometry( this.newGeometryJSON );
+
+		}
+
+		function parseGeometry ( data ) {
+
+			var loader = new THREE.ObjectLoader();
+			return loader.parseGeometries( [ data ] )[ data.uuid ];
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.geometry.dispose();
 		this.object.geometry = this.newGeometry;
 		this.object.geometry.computeBoundingSphere();
@@ -36,6 +65,8 @@ CmdSetGeometry.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.geometry.dispose();
 		this.object.geometry = this.oldGeometry;
 		this.object.geometry.computeBoundingSphere();
@@ -57,8 +88,8 @@ CmdSetGeometry.prototype = {
 		var output = Cmd.prototype.toJSON.call( this );
 
 		output.objectUuid = this.objectUuid;
-		output.oldGeometryJSON = this.oldGeometryJSON;
-		output.newGeometryJSON = this.newGeometryJSON;
+		output.oldGeometry = this.oldGeometryJSON;
+		output.newGeometry = this.newGeometryJSON;
 
 		return output;
 
@@ -68,21 +99,9 @@ CmdSetGeometry.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
-
-		this.oldGeometryJSON = json.oldGeometryJSON;
-		this.newGeometryJSON = json.newGeometryJSON;
-
-		this.oldGeometry = parseGeometry( this.oldGeometryJSON );
-		this.newGeometry = parseGeometry( this.newGeometryJSON );
-
-		function parseGeometry ( data ) {
-
-			var loader = new THREE.ObjectLoader();
-			return loader.parseGeometries( [ data ] )[ data.uuid ];
-
-		}
+		this.oldGeometryJSON = json.oldGeometry;
+		this.newGeometryJSON = json.newGeometry;
 
 	}
 

+ 17 - 3
editor/js/CmdSetGeometryValue.js

@@ -10,17 +10,30 @@ CmdSetGeometryValue = function ( object, attributeName, newValue ) {
 	this.name = 'Set Geometry.' + attributeName;
 
 	this.object = object;
+
 	this.attributeName = attributeName;
-	this.oldValue = object !== undefined ? object.geometry[ attributeName ] : undefined;
+	this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
 	this.newValue = newValue;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
 };
 
 CmdSetGeometryValue.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.geometry[ this.attributeName ] = this.newValue;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -30,6 +43,8 @@ CmdSetGeometryValue.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.geometry[ this.attributeName ] = this.oldValue;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -58,7 +73,6 @@ CmdSetGeometryValue.prototype = {
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
-		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 34 - 18
editor/js/CmdSetMaterial.js

@@ -10,11 +10,10 @@ CmdSetMaterial = function ( object, newMaterial ) {
 	this.name = 'New Material';
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
-
-	this.oldMaterial = object !== undefined ? object.material : undefined;
+	this.oldMaterial = ( object !== undefined ) ? object.material : undefined;
 	this.newMaterial = newMaterial;
 
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.oldMaterialJSON = serializeMaterial( this.oldMaterial );
 	this.newMaterialJSON = serializeMaterial( this.newMaterial );
 
@@ -66,8 +65,39 @@ CmdSetMaterial = function ( object, newMaterial ) {
 
 CmdSetMaterial.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+		if ( this.oldMaterial === undefined ) {
+
+			this.oldMaterial = parseMaterial( this.oldMaterialJSON );
+
+		}
+		if ( this.newMaterial === undefined ) {
+
+			this.newMaterial = parseMaterial( this.newMaterialJSON );
+
+		}
+
+		function parseMaterial ( json ) {
+
+			var loader = new THREE.ObjectLoader();
+			var images = loader.parseImages( json.images );
+			var textures  = loader.parseTextures( json.textures, images );
+			var materials = loader.parseMaterials( json.materials, textures );
+			return materials[ json.materials[ 0 ].uuid ];
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
 		this.object.material = this.newMaterial;
 		this.editor.signals.materialChanged.dispatch( this.newMaterial );
 
@@ -75,6 +105,7 @@ CmdSetMaterial.prototype = {
 
 	undo: function () {
 
+		this.init();
 		this.object.material = this.oldMaterial;
 		this.editor.signals.materialChanged.dispatch( this.oldMaterial );
 
@@ -96,25 +127,10 @@ CmdSetMaterial.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
-
 		this.oldMaterialJSON = json.oldMaterial;
 		this.newMaterialJSON = json.newMaterial;
 
-		this.oldMaterial = parseMaterial( json.oldMaterial );
-		this.newMaterial = parseMaterial( json.newMaterial );
-
-
-		function parseMaterial ( json ) {
-
-			var loader = new THREE.ObjectLoader();
-			var images = loader.parseImages( json.images );
-			var textures  = loader.parseTextures( json.textures, images );
-			var materials = loader.parseMaterials( json.materials, textures );
-			return materials[ json.materials[ 0 ].uuid ];
-
-		}
 	}
 
 };

+ 16 - 3
editor/js/CmdSetMaterialColor.js

@@ -11,17 +11,29 @@ CmdSetMaterialColor = function ( object, attributeName, newValue ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.attributeName = attributeName;
-	this.oldValue = object !== undefined ? this.object.material[ this.attributeName ].getHex() : undefined;
+	this.oldValue = ( object !== undefined ) ? this.object.material[ this.attributeName ].getHex() : undefined;
 	this.newValue = newValue;
 
 };
 
 CmdSetMaterialColor.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.material[ this.attributeName ].setHex( this.newValue );
 		this.editor.signals.materialChanged.dispatch( this.object.material );
 
@@ -29,6 +41,8 @@ CmdSetMaterialColor.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.material[ this.attributeName ].setHex( this.oldValue );
 		this.editor.signals.materialChanged.dispatch( this.object.material );
 
@@ -57,7 +71,6 @@ CmdSetMaterialColor.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;

+ 42 - 26
editor/js/CmdSetMaterialMap.js

@@ -11,10 +11,10 @@ CmdSetMaterialMap = function ( object, mapName, newMap ) {
 
 	this.object = object;
 	this.mapName = mapName;
-	this.oldMap = object !== undefined ? object.material[ mapName ] : undefined;
+	this.oldMap = ( object !== undefined ) ? object.material[ mapName ] : undefined;
 	this.newMap = newMap;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
 
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.newMapJSON = serializeMap( this.newMap );
 	this.oldMapJSON = serializeMap( this.oldMap );
 
@@ -63,8 +63,46 @@ CmdSetMaterialMap = function ( object, mapName, newMap ) {
 
 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 () {
 
+		this.init();
+
 		this.object.material[ this.mapName ] = this.newMap;
 		this.object.material.needsUpdate = true;
 		this.editor.signals.materialChanged.dispatch( this.object.material );
@@ -73,6 +111,8 @@ CmdSetMaterialMap.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.material[ this.mapName ] = this.oldMap;
 		this.object.material.needsUpdate = true;
 		this.editor.signals.materialChanged.dispatch( this.object.material );
@@ -85,7 +125,6 @@ CmdSetMaterialMap.prototype = {
 
 		output.objectUuid = this.objectUuid;
 		output.mapName = this.mapName;
-
 		output.oldMap = this.oldMapJSON;
 		output.newMap = this.newMapJSON;
 
@@ -99,32 +138,9 @@ CmdSetMaterialMap.prototype = {
 
 		this.objectUuid = json.objectUuid;
 		this.mapName = json.mapName;
-
-		this.object = this.editor.objectByUuid( json.objectUuid );
-
 		this.oldMapJSON = json.oldMap;
 		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;
-
-		}
-
 	}
 
 };

+ 17 - 4
editor/js/CmdSetMaterialValue.js

@@ -11,17 +11,29 @@ CmdSetMaterialValue = function ( object, attributeName, newValue ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.attributeName = attributeName;
-	this.oldValue = object !== undefined ? object.material[ attributeName ] : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
+	this.oldValue = ( object !== undefined ) ? object.material[ attributeName ] : undefined;
 	this.newValue = newValue;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.attributeName = attributeName;
 
 };
 
 CmdSetMaterialValue.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.material[ this.attributeName ] = this.newValue;
 		this.object.material.needsUpdate = true;
 		this.editor.signals.materialChanged.dispatch( this.object.material );
@@ -30,6 +42,8 @@ CmdSetMaterialValue.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.material[ this.attributeName ] = this.oldValue;
 		this.object.material.needsUpdate = true;
 		this.editor.signals.materialChanged.dispatch( this.object.material );
@@ -63,7 +77,6 @@ CmdSetMaterialValue.prototype = {
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
-		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 19 - 6
editor/js/CmdSetPosition.js

@@ -11,16 +11,16 @@ CmdSetPosition = function ( object, newPositionVector, oldPositionVector ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
-	if (object !== undefined && newPositionVector !== undefined) {
+	if ( object !== undefined && newPositionVector !== undefined ) {
 
 		this.oldPosition = object.position.clone();
 		this.newPosition = newPositionVector.clone();
 
 	}
 
-	if (oldPositionVector !== undefined) {
+	if ( oldPositionVector !== undefined ) {
 
 		this.oldPosition = oldPositionVector.clone();
 
@@ -29,8 +29,20 @@ CmdSetPosition = function ( object, newPositionVector, oldPositionVector ) {
 };
 CmdSetPosition.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.position.copy( this.newPosition );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -39,6 +51,8 @@ CmdSetPosition.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.position.copy( this.oldPosition );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -67,10 +81,9 @@ CmdSetPosition.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
-		this.oldPosition = new THREE.Vector3().fromArray(json.oldPosition);
-		this.newPosition = new THREE.Vector3().fromArray(json.newPosition);
+		this.oldPosition = new THREE.Vector3().fromArray( json.oldPosition );
+		this.newPosition = new THREE.Vector3().fromArray( json.newPosition );
 
 	}
 

+ 15 - 2
editor/js/CmdSetRotation.js

@@ -11,7 +11,7 @@ CmdSetRotation = function ( object, newRotationEuler, oldRotationEuler ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
 	if ( object !== undefined && newRotationEuler !== undefined) {
 
@@ -30,8 +30,20 @@ CmdSetRotation = function ( object, newRotationEuler, oldRotationEuler ) {
 
 CmdSetRotation.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.rotation.copy( this.newRotation );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -40,6 +52,8 @@ CmdSetRotation.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.rotation.copy( this.oldRotation );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -68,7 +82,6 @@ CmdSetRotation.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
 		this.oldRotation = new THREE.Euler().fromArray(json.oldRotation);
 		this.newRotation = new THREE.Euler().fromArray(json.newRotation);

+ 17 - 4
editor/js/CmdSetScale.js

@@ -11,7 +11,7 @@ CmdSetScale = function ( object, newScaleVector, oldScaleVector ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
 	if ( object !== undefined && newScaleVector !== undefined ) {
 
@@ -29,8 +29,20 @@ CmdSetScale = function ( object, newScaleVector, oldScaleVector ) {
 
 CmdSetScale.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.scale.copy( this.newScale );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -39,6 +51,8 @@ CmdSetScale.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.scale.copy( this.oldScale );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -67,10 +81,9 @@ CmdSetScale.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
-		this.oldScale = new THREE.Vector3().fromArray(json.oldScale);
-		this.newScale = new THREE.Vector3().fromArray(json.newScale);
+		this.oldScale = new THREE.Vector3().fromArray( json.oldScale );
+		this.newScale = new THREE.Vector3().fromArray( json.newScale );
 
 	}
 

+ 23 - 5
editor/js/CmdSetScriptValue.js

@@ -12,18 +12,36 @@ CmdSetScriptValue = function ( object, script, attributeName, newValue, cursorPo
 
 	this.object = object;
 	this.script = script;
+
 	this.attributeName = attributeName;
-	this.oldValue = script !== undefined ? script[ this.attributeName ] : undefined;
+	this.oldValue = ( script !== undefined ) ? script[ this.attributeName ] : undefined;
 	this.newValue = newValue;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.cursorPosition = cursorPosition; // Format {line: 2, ch: 3}
 
 };
 
 CmdSetScriptValue.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+		if ( this.script === undefined ) {
+
+			this.script = this.editor.scripts[ this.objectUuid ][ this.index ];
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.index = this.editor.scripts[ this.objectUuid ].indexOf( this.script );
 		this.script[ this.attributeName ] = this.newValue;
 
@@ -34,6 +52,8 @@ CmdSetScriptValue.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.script[ this.attributeName ] = this.oldValue;
 
 		this.editor.signals.scriptChanged.dispatch();
@@ -69,11 +89,9 @@ CmdSetScriptValue.prototype = {
 
 		this.objectUuid = json.objectUuid;
 		this.index = json.index;
+		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
-		this.attributeName = json.attributeName;
-		this.object = this.editor.objectByUuid( json.objectUuid );
-		this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
 		this.cursorPosition = json.cursorPosition;
 
 	}

+ 20 - 8
editor/js/CmdSetUuid.js

@@ -11,15 +11,32 @@ CmdSetUuid = function ( object, newUuid ) {
 
 	this.object = object;
 
-	this.oldUuid = object !== undefined ? object.uuid : undefined;
+	this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.newUuid = newUuid;
 
 };
 
 CmdSetUuid.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.oldUuid );
+
+		}
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.newUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object.uuid = this.newUuid;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -29,6 +46,8 @@ CmdSetUuid.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object.uuid = this.oldUuid;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -53,13 +72,6 @@ CmdSetUuid.prototype = {
 
 		this.oldUuid = json.oldUuid;
 		this.newUuid = json.newUuid;
-		this.object = this.editor.objectByUuid( json.oldUuid );
-
-		if ( this.object === undefined ) {
-
-			this.object = this.editor.objectByUuid( json.newUuid );
-
-		}
 
 	}
 

+ 16 - 3
editor/js/CmdSetValue.js

@@ -12,16 +12,28 @@ CmdSetValue = function ( object, attributeName, newValue ) {
 
 	this.object = object;
 	this.attributeName = attributeName;
-	this.oldValue = object !== undefined ? object[ attributeName ] : undefined;
+	this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
 	this.newValue = newValue;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
 
 };
 
 CmdSetValue.prototype = {
 
+	init: function () {
+
+		if ( this.object === undefined ) {
+
+			this.object = this.editor.objectByUuid( this.objectUuid );
+
+		}
+
+	},
+
 	execute: function () {
 
+		this.init();
+
 		this.object[ this.attributeName ] = this.newValue;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -31,6 +43,8 @@ CmdSetValue.prototype = {
 
 	undo: function () {
 
+		this.init();
+
 		this.object[ this.attributeName ] = this.oldValue;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -65,7 +79,6 @@ CmdSetValue.prototype = {
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
-		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 10 - 43
editor/js/History.js

@@ -94,15 +94,6 @@ History.prototype = {
 
 			var cmd = this.undos.pop();
 
-			if ( cmd.serialized ) {
-
-				var json = cmd;
-				cmd = new window[ json.type ]();	// creates a new object of type "json.type"
-				cmd.editor = this.editor;
-				cmd.fromJSON( json );
-
-			}
-
 		}
 
 		if ( cmd !== undefined ) {
@@ -132,15 +123,6 @@ History.prototype = {
 
 			var cmd = this.redos.pop();
 
-			if ( cmd.serialized ) {
-
-				var json = cmd;
-				cmd = new window[ json.type ]();	// creates a new object of type "json.type"
-				cmd.editor = this.editor;
-				cmd.fromJSON( json );
-
-			}
-
 		}
 
 		if ( cmd !== undefined ) {
@@ -166,16 +148,7 @@ History.prototype = {
 		for ( var i = 0 ; i < this.undos.length; i++ ) {
 
 			var cmd = this.undos[ i ];
-
-			if ( cmd.serialized ) {
-
-				undos.push( cmd );	// add without serializing
-
-			} else {
-
-				undos.push( cmd.toJSON() );
-
-			}
+			undos.push( cmd.toJSON() );
 
 		}
 
@@ -188,17 +161,7 @@ History.prototype = {
 		for ( var i = 0 ; i < this.redos.length; i++ ) {
 
 			var cmd = this.redos[ i ];
-
-			if ( cmd.serialized ) {
-
-				redos.push( cmd );	// add without serializing
-
-			} else {
-
-				redos.push( cmd.toJSON() );
-
-			}
-
+			redos.push( cmd.toJSON() );
 
 		}
 
@@ -214,8 +177,10 @@ History.prototype = {
 
 		for ( var i = 0; i < json.undos.length ; i++ ) {
 
-			json.undos[ i ].serialized = true;
-			this.undos.push( json.undos[ i ] );
+			var cmd = new window[ json.undos[ i ].type ]();	// creates a new object of type "json.type"
+			cmd.fromJSON( json.undos[ i ] );
+			cmd.editor = this.editor;
+			this.undos.push( cmd );
 
 			this.idCounter = json.undos[ i ].id > this.idCounter ? json.undos[ i ].id : this.idCounter; // set last used idCounter
 
@@ -223,8 +188,10 @@ History.prototype = {
 
 		for ( var i = 0; i < json.redos.length ; i++ ) {
 
-			json.redos[ i ].serialized = true;
-			this.redos.push( json.redos[ i ] );
+			var cmd = new window[ json.redos[ i ].type ]();	// creates a new object of type "json.type"
+			cmd.fromJSON( json.redos[ i ] );
+			cmd.editor = this.editor;
+			this.redos.push( cmd );
 
 			this.idCounter = json.redos[ i ].id > this.idCounter ? json.redos[ i ].id : this.idCounter; // set last used idCounter