浏览代码

Merge branch 'dev' of https://github.com/lxxxvi/three.js into dev

Mario Schuettel 9 年之前
父节点
当前提交
49ac9b8deb

+ 12 - 2
editor/js/Cmd.js

@@ -2,14 +2,22 @@
  * Created by Daniel on 20.07.15.
  */
 
-Cmd = function () {
+Cmd = function ( editorRef ) {
 
 	this.id = -1;
-	this.serialized = false;
+	this.inMemory = false;
 	this.updatable = false;
 	this.type = '';
 	this.name = '';
 
+	if ( editorRef !== undefined ) {
+
+		Cmd.editor = editorRef;
+
+	}
+	this.editor = Cmd.editor;
+
+
 };
 
 Cmd.prototype.toJSON = function () {
@@ -24,8 +32,10 @@ Cmd.prototype.toJSON = function () {
 
 Cmd.prototype.fromJSON = function ( json ) {
 
+	this.inMemory = true;
 	this.type = json.type;
 	this.id = json.id;
 	this.name = json.name;
+	this.json = json;
 
 };

+ 39 - 42
editor/js/CmdAddObject.js

@@ -12,46 +12,6 @@ CmdAddObject = function ( object ) {
 	if ( object !== undefined ) {
 
 		this.name = 'Add Object: ' + object.name;
-		object.updateMatrixWorld( true );
-
-		meta = {
-			geometries: {},
-			materials: {},
-			textures: {},
-			images: {}
-		};
-		var json = object.toJSON( meta );
-
-		var geometries = extractFromCache( meta.geometries );
-		var materials = extractFromCache( meta.materials );
-		var textures = extractFromCache( meta.textures );
-		var images = extractFromCache( meta.images );
-
-		if ( geometries.length > 0 ) json.geometries = geometries;
-		if ( materials.length > 0 ) json.materials = materials;
-		if ( textures.length > 0 ) json.textures = textures;
-		if ( images.length > 0 ) json.images = images;
-
-		this.objectJSON = json;
-
-	}
-
-	// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
-
-	// extract data from the cache hash
-	// remove metadata on each item
-	// and return as array
-	function extractFromCache ( cache ) {
-
-		var values = [];
-		for ( var key in cache ) {
-
-			var data = cache[ key ];
-			delete data.metadata;
-			values.push( data );
-
-		}
-		return values;
 
 	}
 
@@ -76,17 +36,54 @@ CmdAddObject.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.object = this.objectJSON;
+		this.object.updateMatrixWorld( true );
+
+		meta = {
+			geometries: {},
+			materials: {},
+			textures: {},
+			images: {}
+		};
+		var json = this.object.toJSON( meta );
+
+		var geometries = extractFromCache( meta.geometries );
+		var materials = extractFromCache( meta.materials );
+		var textures = extractFromCache( meta.textures );
+		var images = extractFromCache( meta.images );
 
+		if ( geometries.length > 0 ) json.geometries = geometries;
+		if ( materials.length > 0 ) json.materials = materials;
+		if ( textures.length > 0 ) json.textures = textures;
+		if ( images.length > 0 ) json.images = images;
+
+		output.object = json;
 		return output;
 
+		// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
+
+		// extract data from the cache hash
+		// remove metadata on each item
+		// and return as array
+		function extractFromCache ( cache ) {
+
+			var values = [];
+			for ( var key in cache ) {
+
+				var data = cache[ key ];
+				delete data.metadata;
+				values.push( data );
+
+			}
+			return values;
+
+		}
+
 	},
 
 	fromJSON: function ( json ) {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectJSON = json.object;
 		this.object = this.editor.objectByUuid( json.object.object.uuid );
 
 		if ( this.object === undefined ) {

+ 1 - 4
editor/js/CmdAddScript.js

@@ -10,8 +10,6 @@ CmdAddScript = function ( object, script ) {
 	this.name = 'Add Script';
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
-
 	this.script = script;
 
 };
@@ -52,7 +50,7 @@ CmdAddScript.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.script = this.script;
 
 		return output;
@@ -63,7 +61,6 @@ CmdAddScript.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
 		this.script = json.script;
 		this.object = this.editor.objectByUuid( json.objectUuid );
 

+ 15 - 16
editor/js/CmdMoveObject.js

@@ -10,22 +10,17 @@ CmdMoveObject = function ( object, newParent, newBefore ) {
 	this.name = 'Move Object';
 
 	this.object = object;
-	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.oldIndex = ( this.oldParent !== undefined ) ? this.oldParent.children.indexOf( this.object ) : undefined;
 	this.newParent = newParent;
-	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;
 
 	}
 
@@ -69,9 +64,9 @@ CmdMoveObject.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
-		output.newParentUuid = this.newParentUuid;
-		output.oldParentUuid = this.oldParentUuid;
+		output.objectUuid = this.object.uuid;
+		output.newParentUuid = this.newParent.uuid;
+		output.oldParentUuid = this.oldParent.uuid;
 		output.newIndex = this.newIndex;
 		output.oldIndex = this.oldIndex;
 
@@ -84,14 +79,18 @@ 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;
+		if ( this.oldParent === undefined ) {
 
+			this.oldParent = this.editor.scene;
+
+		}
 		this.newParent = this.editor.objectByUuid( json.newParentUuid );
-		this.newParentUuid = json.newParentUuid;
+		if ( this.newParent === undefined ) {
+
+			this.newParent = this.editor.scene;
 
+		}
 		this.newIndex = json.newIndex;
 		this.oldIndex = json.oldIndex;
 

+ 1 - 3
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 : [];
 
 };
 
@@ -21,7 +21,6 @@ CmdMultiCmds.prototype = {
 
 		for ( var i = 0; i < this.cmdArray.length; i++ ) {
 
-			this.cmdArray[ i ].editor = this.editor;
 			this.cmdArray[ i ].execute();
 
 		}
@@ -70,7 +69,6 @@ CmdMultiCmds.prototype = {
 		for ( var i = 0; i < cmds.length; i++ ) {
 
 			var cmd = new window[ cmds[ i ].type ]();	// creates a new object of type "json.type"
-			cmd.editor = this.editor;
 			cmd.fromJSON( cmds[ i ] );
 			this.cmdArray.push( cmd );
 

+ 46 - 51
editor/js/CmdRemoveObject.js

@@ -10,51 +10,10 @@ 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;
+	if ( this.parent !== undefined ) {
 
-	if ( object !== undefined ) {
-
-		object.updateMatrixWorld( true );
-
-		meta = {
-			geometries: {},
-			materials: {},
-			textures: {},
-			images: {}
-		};
-		var json = object.toJSON( meta );
-
-		var geometries = extractFromCache( meta.geometries );
-		var materials = extractFromCache( meta.materials );
-		var textures = extractFromCache( meta.textures );
-		var images = extractFromCache( meta.images );
-
-		if ( geometries.length > 0 ) json.geometries = geometries;
-		if ( materials.length > 0 ) json.materials = materials;
-		if ( textures.length > 0 ) json.textures = textures;
-		if ( images.length > 0 ) json.images = images;
-
-		this.objectJSON = json;
-
-	}
-
-	// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
-
-	// extract data from the cache hash
-	// remove metadata on each item
-	// and return as array
-	function extractFromCache ( cache ) {
-
-		var values = [];
-		for ( var key in cache ) {
-
-			var data = cache[ key ];
-			delete data.metadata;
-			values.push( data );
-
-		}
-		return values;
+		this.index = this.parent.children.indexOf( this.object );
 
 	}
 
@@ -64,8 +23,6 @@ CmdRemoveObject.prototype = {
 
 	execute: function () {
 
-		this.index = this.parent.children.indexOf( this.object );
-
 		var scope = this.editor;
 		this.object.traverse( function ( child ) {
 
@@ -105,12 +62,52 @@ CmdRemoveObject.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.object = this.objectJSON;
+		this.object.updateMatrixWorld( true );
+
+		meta = {
+			geometries: {},
+			materials: {},
+			textures: {},
+			images: {}
+		};
+		var json = this.object.toJSON( meta );
+
+		var geometries = extractFromCache( meta.geometries );
+		var materials = extractFromCache( meta.materials );
+		var textures = extractFromCache( meta.textures );
+		var images = extractFromCache( meta.images );
+
+		if ( geometries.length > 0 ) json.geometries = geometries;
+		if ( materials.length > 0 ) json.materials = materials;
+		if ( textures.length > 0 ) json.textures = textures;
+		if ( images.length > 0 ) json.images = images;
+
+		output.object = json;
 		output.index = this.index;
-		output.parentUuid = this.parentUuid;
+		output.parentUuid = this.parent.uuid;
 
 		return output;
 
+
+		// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
+
+		// extract data from the cache hash
+		// remove metadata on each item
+		// and return as array
+		function extractFromCache ( cache ) {
+
+			var values = [];
+			for ( var key in cache ) {
+
+				var data = cache[ key ];
+				delete data.metadata;
+				values.push( data );
+
+			}
+			return values;
+
+		}
+
 	},
 
 	fromJSON: function ( json ) {
@@ -123,18 +120,16 @@ CmdRemoveObject.prototype = {
 			this.parent = this.editor.scene;
 
 		}
-		this.parentUuid = json.parentUuid;
 
 		this.index = json.index;
-		this.object = this.editor.objectByUuid( json.object.object.uuid );
 
+		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;
 
 	}
 

+ 5 - 6
editor/js/CmdRemoveScript.js

@@ -10,10 +10,12 @@ CmdRemoveScript = function ( object, script ) {
 	this.name = 'Remove Script';
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
-
 	this.script = script;
+	if ( this.object && this.script ) {
+
+		this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
 
+	}
 };
 
 CmdRemoveScript.prototype = {
@@ -22,8 +24,6 @@ CmdRemoveScript.prototype = {
 
 		if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
 
-		this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
-
 		if ( this.index !== - 1 ) {
 
 			this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
@@ -52,7 +52,7 @@ CmdRemoveScript.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.script = this.script;
 		output.index = this.index;
 
@@ -64,7 +64,6 @@ CmdRemoveScript.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
 		this.script = json.script;
 		this.index = json.index;
 		this.object = this.editor.objectByUuid( json.objectUuid );

+ 2 - 4
editor/js/CmdSetColor.js

@@ -11,9 +11,8 @@ CmdSetColor = function ( object, attributeName, newValue ) {
 	this.updatable = true;
 
 	this.object = object;
-	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;
 
 };
@@ -44,7 +43,7 @@ CmdSetColor.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.attributeName = this.attributeName;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
@@ -58,7 +57,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;
 		this.newValue = json.newValue;

+ 6 - 16
editor/js/CmdSetGeometry.js

@@ -11,14 +11,9 @@ CmdSetGeometry = function ( object, newGeometry ) {
 	this.updatable = true;
 
 	this.object = object;
-	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;
-
 };
 
 CmdSetGeometry.prototype = {
@@ -56,9 +51,9 @@ CmdSetGeometry.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
-		output.oldGeometryJSON = this.oldGeometryJSON;
-		output.newGeometryJSON = this.newGeometryJSON;
+		output.objectUuid = this.object.uuid;
+		output.oldGeometry = this.object.geometry.toJSON();
+		output.newGeometry = this.newGeometry.toJSON();
 
 		return output;
 
@@ -69,13 +64,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 );
+		this.oldGeometry = parseGeometry( json.oldGeometry );
+		this.newGeometry = parseGeometry( json.newGeometry );
 
 		function parseGeometry ( data ) {
 
@@ -86,5 +77,4 @@ CmdSetGeometry.prototype = {
 
 	}
 
-
 };

+ 3 - 5
editor/js/CmdSetGeometryValue.js

@@ -11,9 +11,8 @@ CmdSetGeometryValue = function ( object, attributeName, newValue ) {
 
 	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;
 
 };
 
@@ -41,7 +40,7 @@ CmdSetGeometryValue.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.attributeName = this.attributeName;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
@@ -54,11 +53,10 @@ CmdSetGeometryValue.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
+		this.object = this.editor.objectByUuid( json.objectUuid );
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
-		this.object = this.editor.objectByUuid( json.objectUuid );
 
 	}
 

+ 46 - 56
editor/js/CmdSetMaterial.js

@@ -10,85 +10,80 @@ 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.oldMaterialJSON = serializeMaterial( this.oldMaterial );
-	this.newMaterialJSON = serializeMaterial( this.newMaterial );
+};
 
+CmdSetMaterial.prototype = {
 
-	function serializeMaterial ( material ) {
+	execute: function () {
 
-		if ( material === undefined ) return null;
+		this.object.material = this.newMaterial;
+		this.editor.signals.materialChanged.dispatch( this.newMaterial );
 
-		var meta = {
-			geometries: {},
-			materials: {},
-			textures: {},
-			images: {}
-		};
+	},
 
-		var json = {};
-		json.materials = [ material.toJSON( meta ) ];
+	undo: function () {
 
-		var textures = extractFromCache( meta.textures );
-		var images = extractFromCache( meta.images );
+		this.object.material = this.oldMaterial;
+		this.editor.signals.materialChanged.dispatch( this.oldMaterial );
 
-		if ( textures.length > 0 ) json.textures = textures;
-		if ( images.length > 0 ) json.images = images;
+	},
 
-		return json;
+	toJSON: function () {
 
-	}
+		var output = Cmd.prototype.toJSON.call( this );
 
-	// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
+		output.objectUuid = this.object.uuid;
+		output.oldMaterial = serializeMaterial( this.oldMaterial );
+		output.newMaterial = serializeMaterial( this.newMaterial );
 
-	// extract data from the cache hash
-	// remove metadata on each item
-	// and return as array
-	function extractFromCache ( cache ) {
+		return output;
 
-		var values = [];
-		for ( var key in cache ) {
 
-			var data = cache[ key ];
-			delete data.metadata;
-			values.push( data );
+		function serializeMaterial ( material ) {
 
-		}
-		return values;
+			if ( material === undefined ) return null;
 
-	}
+			var meta = {
+				geometries: {},
+				materials: {},
+				textures: {},
+				images: {}
+			};
 
-};
+			var json = {};
+			json.materials = [ material.toJSON( meta ) ];
 
-CmdSetMaterial.prototype = {
+			var textures = extractFromCache( meta.textures );
+			var images = extractFromCache( meta.images );
 
-	execute: function () {
+			if ( textures.length > 0 ) json.textures = textures;
+			if ( images.length > 0 ) json.images = images;
 
-		this.object.material = this.newMaterial;
-		this.editor.signals.materialChanged.dispatch( this.newMaterial );
+			return json;
 
-	},
+		}
 
-	undo: function () {
+		// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
 
-		this.object.material = this.oldMaterial;
-		this.editor.signals.materialChanged.dispatch( this.oldMaterial );
+		// extract data from the cache hash
+		// remove metadata on each item
+		// and return as array
+		function extractFromCache ( cache ) {
 
-	},
-
-	toJSON: function () {
+			var values = [];
+			for ( var key in cache ) {
 
-		var output = Cmd.prototype.toJSON.call( this );
+				var data = cache[ key ];
+				delete data.metadata;
+				values.push( data );
 
-		output.objectUuid = this.objectUuid;
-		output.oldMaterial = this.oldMaterialJSON;
-		output.newMaterial = this.newMaterialJSON;
+			}
+			return values;
 
-		return output;
+		}
 
 	},
 
@@ -97,11 +92,6 @@ 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 );
 

+ 2 - 4
editor/js/CmdSetMaterialColor.js

@@ -11,9 +11,8 @@ CmdSetMaterialColor = function ( object, attributeName, newValue ) {
 	this.updatable = true;
 
 	this.object = object;
-	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;
 
 };
@@ -44,7 +43,7 @@ CmdSetMaterialColor.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.attributeName = this.attributeName;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
@@ -58,7 +57,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;
 		this.newValue = json.newValue;

+ 46 - 59
editor/js/CmdSetMaterialMap.js

@@ -5,59 +5,13 @@
 CmdSetMaterialMap = function ( object, mapName, newMap ) {
 
 	Cmd.call( this );
-
 	this.type = 'CmdSetMaterialMap';
 	this.name = 'Set Material.' + mapName;
 
 	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.newMapJSON = serializeMap( this.newMap );
-	this.oldMapJSON = serializeMap( this.oldMap );
-
-	// serializes a map (THREE.Texture)
-
-	function serializeMap ( map ) {
-
-		if ( map === null || map === undefined ) return null;
-
-		var meta = {
-			geometries: {},
-			materials: {},
-			textures: {},
-			images: {}
-		};
-
-		var json = map.toJSON( meta );
-		var images = extractFromCache( meta.images );
-		if ( images.length > 0 ) json.images = images;
-		json.sourceFile = map.sourceFile;
-
-		return json;
-
-	}
-
-	// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
-
-	// extract data from the cache hash
-	// remove metadata on each item
-	// and return as array
-	function extractFromCache ( cache ) {
-
-		var values = [];
-		for ( var key in cache ) {
-
-			var data = cache[ key ];
-			delete data.metadata;
-			values.push( data );
-
-		}
-		return values;
-
-	}
 
 };
 
@@ -83,32 +37,65 @@ CmdSetMaterialMap.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.mapName = this.mapName;
-
-		output.oldMap = this.oldMapJSON;
-		output.newMap = this.newMapJSON;
+		output.newMap = serializeMap( this.newMap );
+		output.oldMap = serializeMap( this.oldMap );
 
 		return output;
 
+		// serializes a map (THREE.Texture)
+
+		function serializeMap ( map ) {
+
+			if ( map === null || map === undefined ) return null;
+
+			var meta = {
+				geometries: {},
+				materials: {},
+				textures: {},
+				images: {}
+			};
+
+			var json = map.toJSON( meta );
+			var images = extractFromCache( meta.images );
+			if ( images.length > 0 ) json.images = images;
+			json.sourceFile = map.sourceFile;
+
+			return json;
+
+		}
+
+		// Note: The function 'extractFromCache' is copied from Object3D.toJSON()
+
+		// extract data from the cache hash
+		// remove metadata on each item
+		// and return as array
+		function extractFromCache ( cache ) {
+
+			var values = [];
+			for ( var key in cache ) {
+
+				var data = cache[ key ];
+				delete data.metadata;
+				values.push( data );
+
+			}
+			return values;
+
+		}
+
 	},
 
 	fromJSON: function ( json ) {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
-		this.mapName = json.mapName;
-
 		this.object = this.editor.objectByUuid( json.objectUuid );
-
-		this.oldMapJSON = json.oldMap;
-		this.newMapJSON = json.newMap;
-
+		this.mapName = json.mapName;
 		this.oldMap = parseTexture( json.oldMap );
 		this.newMap = parseTexture( json.newMap );
 
-
 		function parseTexture ( json ) {
 
 			var map = null;

+ 3 - 5
editor/js/CmdSetMaterialValue.js

@@ -11,10 +11,9 @@ CmdSetMaterialValue = function ( object, attributeName, newValue ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.attributeName = attributeName;
-	this.oldValue = object !== undefined ? object.material[ attributeName ] : undefined;
+	this.oldValue = ( object !== undefined ) ? object.material[ attributeName ] : undefined;
 	this.newValue = newValue;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
+	this.attributeName = attributeName;
 
 };
 
@@ -46,7 +45,7 @@ CmdSetMaterialValue.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.attributeName = this.attributeName;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
@@ -59,7 +58,6 @@ CmdSetMaterialValue.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;

+ 5 - 7
editor/js/CmdSetPosition.js

@@ -11,16 +11,15 @@ CmdSetPosition = function ( object, newPositionVector, oldPositionVector ) {
 	this.updatable = true;
 
 	this.object = object;
-	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();
 
@@ -55,7 +54,7 @@ CmdSetPosition.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.oldPosition = this.oldPosition.toArray();
 		output.newPosition = this.newPosition.toArray();
 
@@ -68,9 +67,8 @@ 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 );
 
 	}
 

+ 1 - 3
editor/js/CmdSetRotation.js

@@ -11,7 +11,6 @@ CmdSetRotation = function ( object, newRotationEuler, oldRotationEuler ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
 
 	if ( object !== undefined && newRotationEuler !== undefined) {
 
@@ -56,7 +55,7 @@ CmdSetRotation.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.oldRotation = this.oldRotation.toArray();
 		output.newRotation = this.newRotation.toArray();
 
@@ -69,7 +68,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);
 

+ 3 - 5
editor/js/CmdSetScale.js

@@ -11,7 +11,6 @@ CmdSetScale = function ( object, newScaleVector, oldScaleVector ) {
 	this.updatable = true;
 
 	this.object = object;
-	this.objectUuid = object !== undefined ? object.uuid : undefined;
 
 	if ( object !== undefined && newScaleVector !== undefined ) {
 
@@ -55,7 +54,7 @@ CmdSetScale.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.oldScale = this.oldScale.toArray();
 		output.newScale = this.newScale.toArray();
 
@@ -68,9 +67,8 @@ 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 );
 
 	}
 

+ 4 - 6
editor/js/CmdSetScene.js

@@ -2,7 +2,7 @@
  * Created by Daniel on 20.07.15.
  */
 
-CmdSetScene = function ( oldScene, newScene ) {
+CmdSetScene = function ( newScene ) {
 
 	Cmd.call( this );
 
@@ -13,9 +13,9 @@ CmdSetScene = function ( oldScene, newScene ) {
 
 	if ( newScene !== undefined ) {
 
-		this.cmdArray.push( new CmdSetUuid( oldScene, newScene.uuid ) );
-		this.cmdArray.push( new CmdSetValue( oldScene, 'name', newScene.name ) );
-		this.cmdArray.push( new CmdSetValue( oldScene, 'userData', JSON.parse( JSON.stringify( newScene.userData ) ) ) );
+		this.cmdArray.push( new CmdSetUuid( this.editor.scene, newScene.uuid ) );
+		this.cmdArray.push( new CmdSetValue( this.editor.scene, 'name', newScene.name ) );
+		this.cmdArray.push( new CmdSetValue( this.editor.scene, 'userData', JSON.parse( JSON.stringify( newScene.userData ) ) ) );
 
 		while ( newScene.children.length > 0 ) {
 
@@ -35,7 +35,6 @@ CmdSetScene.prototype = {
 
 		for ( var i = 0; i < this.cmdArray.length; i ++ ) {
 
-			this.cmdArray[ i ].editor = this.editor;
 			this.cmdArray[ i ].execute();
 
 		}
@@ -84,7 +83,6 @@ CmdSetScene.prototype = {
 		for ( var i = 0; i < cmds.length; i ++ ) {
 
 			var cmd = new window[ cmds[ i ].type ]();	// creates a new object of type "json.type"
-			cmd.editor = this.editor;
 			cmd.fromJSON( cmds[ i ] );
 			this.cmdArray.push( cmd );
 

+ 4 - 7
editor/js/CmdSetScriptValue.js

@@ -12,10 +12,10 @@ 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.cursorPosition = cursorPosition; // Format {line: 2, ch: 3}
 
 };
@@ -24,7 +24,6 @@ CmdSetScriptValue.prototype = {
 
 	execute: function () {
 
-		this.index = this.editor.scripts[ this.objectUuid ].indexOf( this.script );
 		this.script[ this.attributeName ] = this.newValue;
 
 		this.editor.signals.scriptChanged.dispatch();
@@ -52,8 +51,8 @@ CmdSetScriptValue.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
-		output.index = this.index;
+		output.objectUuid = this.object.uuid;
+		output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
 		output.attributeName = this.attributeName;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
@@ -67,8 +66,6 @@ CmdSetScriptValue.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
-		this.index = json.index;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;
 		this.attributeName = json.attributeName;

+ 1 - 1
editor/js/CmdSetUuid.js

@@ -11,7 +11,7 @@ CmdSetUuid = function ( object, newUuid ) {
 
 	this.object = object;
 
-	this.oldUuid = object !== undefined ? object.uuid : undefined;
+	this.oldUuid = ( object !== undefined ) ? object.uuid : undefined;
 	this.newUuid = newUuid;
 
 };

+ 2 - 4
editor/js/CmdSetValue.js

@@ -12,9 +12,8 @@ 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;
 
 };
 
@@ -48,7 +47,7 @@ CmdSetValue.prototype = {
 
 		var output = Cmd.prototype.toJSON.call( this );
 
-		output.objectUuid = this.objectUuid;
+		output.objectUuid = this.object.uuid;
 		output.attributeName = this.attributeName;
 		output.oldValue = this.oldValue;
 		output.newValue = this.newValue;
@@ -61,7 +60,6 @@ CmdSetValue.prototype = {
 
 		Cmd.prototype.fromJSON.call( this, json );
 
-		this.objectUuid = json.objectUuid;
 		this.attributeName = json.attributeName;
 		this.oldValue = json.oldValue;
 		this.newValue = json.newValue;

+ 25 - 43
editor/js/History.js

@@ -13,6 +13,10 @@ History = function ( editor ) {
 
 	this.historyDisabled = false;
 
+	//Set editor-reference in Cmd
+
+	Cmd( editor );
+
 	// signals
 
 	var scope = this;
@@ -63,12 +67,13 @@ History.prototype = {
 			// the command is not updatable and is added as a new part of the history
 
 			this.undos.push( cmd );
-			cmd.editor = this.editor;
 			cmd.id = ++this.idCounter;
 
 		}
 		cmd.name = optionalName !== undefined ? optionalName : cmd.name;
 		cmd.execute();
+		cmd.inMemory = true;
+		cmd.json = cmd.toJSON();	// serialize cmd immediately after execution
 
 		this.lastCmdTime = new Date();
 
@@ -94,12 +99,9 @@ History.prototype = {
 
 			var cmd = this.undos.pop();
 
-			if ( cmd.serialized ) {
+			if ( cmd.inMemory === false ) {
 
-				var json = cmd;
-				cmd = new window[ json.type ]();	// creates a new object of type "json.type"
-				cmd.editor = this.editor;
-				cmd.fromJSON( json );
+				cmd.fromJSON( cmd.json );
 
 			}
 
@@ -132,12 +134,9 @@ History.prototype = {
 
 			var cmd = this.redos.pop();
 
-			if ( cmd.serialized ) {
+			if ( cmd.inMemory === false ) {
 
-				var json = cmd;
-				cmd = new window[ json.type ]();	// creates a new object of type "json.type"
-				cmd.editor = this.editor;
-				cmd.fromJSON( json );
+				cmd.fromJSON( cmd.json );
 
 			}
 
@@ -166,16 +165,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.json );
 
 		}
 
@@ -188,17 +178,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.json );
 
 		}
 
@@ -214,19 +194,21 @@ History.prototype = {
 
 		for ( var i = 0; i < json.undos.length ; i++ ) {
 
-			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
+			var cmdJSON = json.undos[ i ];
+			var cmd = new window[ cmdJSON.type ]();	// creates a new object of type "json.type"
+			cmd.json = cmdJSON;
+			this.undos.push( cmd );
+			this.idCounter = cmdJSON.id > this.idCounter ? cmdJSON.id : this.idCounter; // set last used idCounter
 
 		}
 
 		for ( var i = 0; i < json.redos.length ; i++ ) {
 
-			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
+			var cmdJSON = json.redos[ i ];
+			var cmd = new window[ cmdJSON.type ]();	// creates a new object of type "json.type"
+			cmd.json = cmdJSON;
+			this.redos.push( cmd );
+			this.idCounter = cmdJSON.id > this.idCounter ? cmdJSON.id : this.idCounter; // set last used idCounter
 
 		}
 
@@ -258,10 +240,10 @@ History.prototype = {
 
 		var cmd = this.undos.length > 0 ? this.undos[ this.undos.length - 1 ] : undefined;	// next cmd to pop
 
-		if ( cmd === undefined || id > cmd.id ) {
+		if ( cmd === undefined || id > cmd.json.id ) {
 
 			cmd = this.redo();
-			while ( cmd !== undefined && id > cmd.id ) {
+			while ( cmd !== undefined && id > cmd.json.id ) {
 
 				cmd = this.redo();
 
@@ -273,7 +255,7 @@ History.prototype = {
 
 				cmd = this.undos[ this.undos.length - 1 ];	// next cmd to pop
 
-				if ( cmd === undefined || id === cmd.id ) break;
+				if ( cmd === undefined || id === cmd.json.id ) break;
 
 				cmd = this.undo();
 

+ 5 - 5
editor/js/Loader.js

@@ -40,7 +40,7 @@ var Loader = function ( editor ) {
 					var loader = new THREE.AWDLoader();
 					var scene = loader.parse( event.target.result );
 
-					editor.execute( new CmdSetScene( editor.scene, scene ) );
+					editor.execute( new CmdSetScene( scene ) );
 
 				}, false );
 				reader.readAsArrayBuffer( file );
@@ -58,7 +58,7 @@ var Loader = function ( editor ) {
 					var loader = new THREE.BabylonLoader();
 					var scene = loader.parse( json );
 
-					editor.execute( new CmdSetScene( editor.scene, scene ) );
+					editor.execute( new CmdSetScene( scene ) );
 
 				}, false );
 				reader.readAsText( file );
@@ -371,7 +371,7 @@ var Loader = function ( editor ) {
 
 					var result = new THREE.VRMLLoader().parse( contents );
 
-					editor.execute( new CmdSetScene( editor.scene, result ) );
+					editor.execute( new CmdSetScene( result ) );
 
 				}, false );
 				reader.readAsText( file );
@@ -475,7 +475,7 @@ var Loader = function ( editor ) {
 
 			if ( result instanceof THREE.Scene ) {
 
-				editor.execute( new CmdSetScene( editor.scene, result ) );
+				editor.execute( new CmdSetScene( result ) );
 
 			} else {
 
@@ -491,7 +491,7 @@ var Loader = function ( editor ) {
 			var loader = new THREE.SceneLoader();
 			loader.parse( data, function ( result ) {
 
-				editor.execute( new CmdSetScene( editor.scene, result.scene ) );
+				editor.execute( new CmdSetScene( result.scene ) );
 
 			}, '' );
 

+ 5 - 5
editor/js/Sidebar.History.js

@@ -51,9 +51,9 @@ Sidebar.History = function ( editor ) {
 
 				var object = objects[ i ];
 
-				var html = pad + "<span style='color: #0000cc '>" + enumerator++ + ". Undo: " + object.name + "</span>";
+				var html = pad + "<span style='color: #0000cc '>" + enumerator++ + ". Undo: " + object.json.name + "</span>";
 
-				options.push( { value: object.id, html: html } );
+				options.push( { value: object.json.id, html: html } );
 
 			}
 
@@ -66,9 +66,9 @@ Sidebar.History = function ( editor ) {
 
 				var object = objects[ i ];
 
-				var html = pad + "<span style='color: #71544e'>" + enumerator++ + ". Redo: " +  object.name + "</span>";
+				var html = pad + "<span style='color: #71544e'>" + enumerator++ + ". Redo: " +  object.json.name + "</span>";
 
-				options.push( { value: object.id, html: html } );
+				options.push( { value: object.json.id, html: html } );
 
 			}
 
@@ -87,7 +87,7 @@ Sidebar.History = function ( editor ) {
 	signals.historyChanged.add( refreshUI );
 	signals.historyChanged.add( function ( cmd ) {
 		
-		outliner.setValue( cmd !== undefined ? cmd.id : null );
+		outliner.setValue( cmd !== undefined ? cmd.json.id : null );
 
 	} );
 

+ 1 - 1
test/unit/editor/TestCmdSetScene.js

@@ -24,7 +24,7 @@ test("Test for CmdSetScene (Undo and Redo)", function() {
 	scenes.map( function( scene ) {
 
 		var importedScene = importScene( scene.exportedData );
-		var cmd = new CmdSetScene( editor.scene, importedScene );
+		var cmd = new CmdSetScene( importedScene );
 		cmd.updatable = false;
 		editor.execute( cmd );