Prechádzať zdrojové kódy

Revert "experimental" partially

This reverts commit cf5cbfbfafde64c38559f98eeb2dd47f29ca4af9.
Daniel 9 rokov pred
rodič
commit
633e8e76b6

+ 1 - 0
editor/js/Cmd.js

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

+ 8 - 19
editor/js/CmdAddObject.js

@@ -59,33 +59,14 @@ 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();
 
@@ -106,6 +87,14 @@ 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 );
+
+		}
 
 	}
 

+ 1 - 14
editor/js/CmdAddScript.js

@@ -18,20 +18,8 @@ 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 ] = [];
@@ -46,8 +34,6 @@ 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 );
@@ -79,6 +65,7 @@ CmdAddScript.prototype = {
 
 		this.objectUuid = json.objectUuid;
 		this.script = json.script;
+		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 6 - 24
editor/js/CmdMoveObject.js

@@ -41,30 +41,8 @@ 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;
@@ -77,8 +55,6 @@ CmdMoveObject.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.newParent.remove( this.object );
 
 		var children = this.oldParent.children;
@@ -107,9 +83,15 @@ 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;
 

+ 17 - 32
editor/js/CmdRemoveObject.js

@@ -62,36 +62,8 @@ 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;
@@ -110,8 +82,6 @@ CmdRemoveObject.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		var scope = this.editor;
 
 		this.object.traverse( function ( child ) {
@@ -147,10 +117,25 @@ CmdRemoveObject.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectJSON = json.object;
-		this.index = json.index;
+		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;
+
 	}
 
 };

+ 1 - 14
editor/js/CmdRemoveScript.js

@@ -18,20 +18,8 @@ CmdRemoveScript = function ( object, 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 );
@@ -48,8 +36,6 @@ CmdRemoveScript.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
 
 			this.editor.scripts[ this.object.uuid ] = [];
@@ -81,6 +67,7 @@ CmdRemoveScript.prototype = {
 		this.objectUuid = json.objectUuid;
 		this.script = json.script;
 		this.index = json.index;
+		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 1 - 12
editor/js/CmdSetColor.js

@@ -20,19 +20,8 @@ CmdSetColor = function ( object, attributeName, 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 );
 
@@ -40,7 +29,6 @@ CmdSetColor.prototype = {
 
 	undo: function () {
 
-		this.init();
 		this.object[ this.attributeName ].setHex( this.oldValue );
 		this.editor.signals.objectChanged.dispatch( this.object );
 
@@ -69,6 +57,7 @@ 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;

+ 12 - 31
editor/js/CmdSetGeometry.js

@@ -23,37 +23,8 @@ CmdSetGeometry = function ( object, newGeometry ) {
 
 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();
@@ -65,8 +36,6 @@ CmdSetGeometry.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object.geometry.dispose();
 		this.object.geometry = this.oldGeometry;
 		this.object.geometry.computeBoundingSphere();
@@ -99,10 +68,22 @@ CmdSetGeometry.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
+		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.objectUuid = json.objectUuid;
 		this.oldGeometryJSON = json.oldGeometry;
 		this.newGeometryJSON = json.newGeometry;
 
+
+		this.oldGeometry = parseGeometry( this.oldGeometryJSON );
+		this.newGeometry = parseGeometry( this.newGeometryJSON );
+
+		function parseGeometry ( data ) {
+
+			var loader = new THREE.ObjectLoader();
+			return loader.parseGeometries( [ data ] )[ data.uuid ];
+
+		}
+
 	}
 
 

+ 1 - 14
editor/js/CmdSetGeometryValue.js

@@ -20,20 +20,8 @@ CmdSetGeometryValue = function ( object, attributeName, newValue ) {
 
 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();
@@ -43,8 +31,6 @@ 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();
@@ -73,6 +59,7 @@ CmdSetGeometryValue.prototype = {
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
+		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 15 - 32
editor/js/CmdSetMaterial.js

@@ -65,39 +65,8 @@ 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 );
 
@@ -105,7 +74,6 @@ CmdSetMaterial.prototype = {
 
 	undo: function () {
 
-		this.init();
 		this.object.material = this.oldMaterial;
 		this.editor.signals.materialChanged.dispatch( this.oldMaterial );
 
@@ -127,10 +95,25 @@ 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 ];
+
+		}
 	}
 
 };

+ 1 - 14
editor/js/CmdSetMaterialColor.js

@@ -20,20 +20,8 @@ CmdSetMaterialColor = function ( object, attributeName, 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 );
 
@@ -41,8 +29,6 @@ CmdSetMaterialColor.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object.material[ this.attributeName ].setHex( this.oldValue );
 		this.editor.signals.materialChanged.dispatch( this.object.material );
 
@@ -71,6 +57,7 @@ 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;

+ 24 - 40
editor/js/CmdSetMaterialMap.js

@@ -63,46 +63,8 @@ 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 );
@@ -111,8 +73,6 @@ 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 );
@@ -125,6 +85,7 @@ CmdSetMaterialMap.prototype = {
 
 		output.objectUuid = this.objectUuid;
 		output.mapName = this.mapName;
+
 		output.oldMap = this.oldMapJSON;
 		output.newMap = this.newMapJSON;
 
@@ -138,9 +99,32 @@ 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;
+
+		}
+
 	}
 
 };

+ 1 - 14
editor/js/CmdSetMaterialValue.js

@@ -20,20 +20,8 @@ CmdSetMaterialValue = function ( object, attributeName, newValue ) {
 
 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 );
@@ -42,8 +30,6 @@ 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 );
@@ -77,6 +63,7 @@ CmdSetMaterialValue.prototype = {
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
+		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 1 - 14
editor/js/CmdSetPosition.js

@@ -29,20 +29,8 @@ 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 );
@@ -51,8 +39,6 @@ CmdSetPosition.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object.position.copy( this.oldPosition );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -81,6 +67,7 @@ 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 );

+ 1 - 14
editor/js/CmdSetRotation.js

@@ -30,20 +30,8 @@ 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 );
@@ -52,8 +40,6 @@ CmdSetRotation.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object.rotation.copy( this.oldRotation );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -82,6 +68,7 @@ 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);

+ 1 - 14
editor/js/CmdSetScale.js

@@ -29,20 +29,8 @@ 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 );
@@ -51,8 +39,6 @@ CmdSetScale.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object.scale.copy( this.oldScale );
 		this.object.updateMatrixWorld( true );
 		this.editor.signals.objectChanged.dispatch( this.object );
@@ -81,6 +67,7 @@ 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 );

+ 3 - 20
editor/js/CmdSetScriptValue.js

@@ -23,25 +23,8 @@ CmdSetScriptValue = function ( object, script, attributeName, newValue, cursorPo
 
 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;
 
@@ -52,8 +35,6 @@ CmdSetScriptValue.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.script[ this.attributeName ] = this.oldValue;
 
 		this.editor.signals.scriptChanged.dispatch();
@@ -89,9 +70,11 @@ 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;
 
 	}

+ 7 - 19
editor/js/CmdSetUuid.js

@@ -18,25 +18,8 @@ CmdSetUuid = function ( object, 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();
@@ -46,8 +29,6 @@ CmdSetUuid.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object.uuid = this.oldUuid;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -72,6 +53,13 @@ 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 );
+
+		}
 
 	}
 

+ 1 - 14
editor/js/CmdSetValue.js

@@ -20,20 +20,8 @@ CmdSetValue = function ( object, attributeName, newValue ) {
 
 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();
@@ -43,8 +31,6 @@ CmdSetValue.prototype = {
 
 	undo: function () {
 
-		this.init();
-
 		this.object[ this.attributeName ] = this.oldValue;
 		this.editor.signals.objectChanged.dispatch( this.object );
 		this.editor.signals.sceneGraphChanged.dispatch();
@@ -79,6 +65,7 @@ CmdSetValue.prototype = {
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
+		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 43 - 10
editor/js/History.js

@@ -94,6 +94,15 @@ 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 ) {
@@ -123,6 +132,15 @@ 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 ) {
@@ -148,7 +166,16 @@ History.prototype = {
 		for ( var i = 0 ; i < this.undos.length; i++ ) {
 
 			var cmd = this.undos[ i ];
-			undos.push( cmd.toJSON() );
+
+			if ( cmd.serialized ) {
+
+				undos.push( cmd );	// add without serializing
+
+			} else {
+
+				undos.push( cmd.toJSON() );
+
+			}
 
 		}
 
@@ -161,7 +188,17 @@ History.prototype = {
 		for ( var i = 0 ; i < this.redos.length; i++ ) {
 
 			var cmd = this.redos[ i ];
-			redos.push( cmd.toJSON() );
+
+			if ( cmd.serialized ) {
+
+				redos.push( cmd );	// add without serializing
+
+			} else {
+
+				redos.push( cmd.toJSON() );
+
+			}
+
 
 		}
 
@@ -177,10 +214,8 @@ History.prototype = {
 
 		for ( var i = 0; i < json.undos.length ; 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 );
+			json.undos[ i ].serialized = true;
+			this.undos.push( json.undos[ i ] );
 
 			this.idCounter = json.undos[ i ].id > this.idCounter ? json.undos[ i ].id : this.idCounter; // set last used idCounter
 
@@ -188,10 +223,8 @@ History.prototype = {
 
 		for ( var i = 0; i < json.redos.length ; 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 );
+			json.redos[ i ].serialized = true;
+			this.redos.push( json.redos[ i ] );
 
 			this.idCounter = json.redos[ i ].id > this.idCounter ? json.redos[ i ].id : this.idCounter; // set last used idCounter