浏览代码

Editor: Fixed saving.
https://twitter.com/inexorabletash/status/667043708160708608

Mr.doob 9 年之前
父节点
当前提交
cf399f38b3
共有 1 个文件被更改,包括 17 次插入19 次删除
  1. 17 19
      editor/js/Menubar.File.js

+ 17 - 19
editor/js/Menubar.File.js

@@ -98,7 +98,7 @@ Menubar.File = function ( editor ) {
 
 
 		}
 		}
 
 
-		exportString( output, 'geometry.json' );
+		saveString( output, 'geometry.json' );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -132,7 +132,7 @@ Menubar.File = function ( editor ) {
 
 
 		}
 		}
 
 
-		exportString( output, 'model.json' );
+		saveString( output, 'model.json' );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -157,7 +157,7 @@ Menubar.File = function ( editor ) {
 
 
 		}
 		}
 
 
-		exportString( output, 'scene.json' );
+		saveString( output, 'scene.json' );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -180,7 +180,7 @@ Menubar.File = function ( editor ) {
 
 
 		var exporter = new THREE.OBJExporter();
 		var exporter = new THREE.OBJExporter();
 
 
-		exportString( exporter.parse( object ), 'model.obj' );
+		saveString( exporter.parse( object ), 'model.obj' );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -194,7 +194,7 @@ Menubar.File = function ( editor ) {
 
 
 		var exporter = new THREE.STLExporter();
 		var exporter = new THREE.STLExporter();
 
 
-		exportString( exporter.parse( editor.scene ), 'model.stl' );
+		saveString( exporter.parse( editor.scene ), 'model.stl' );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -271,7 +271,7 @@ Menubar.File = function ( editor ) {
 
 
 		var manager = new THREE.LoadingManager( function () {
 		var manager = new THREE.LoadingManager( function () {
 
 
-			location.href = 'data:application/zip;base64,' + zip.generate();
+			save( zip.generate( { type: 'blob' } ), 'download.zip' );
 
 
 		} );
 		} );
 
 
@@ -297,23 +297,21 @@ Menubar.File = function ( editor ) {
 	link.style.display = 'none';
 	link.style.display = 'none';
 	document.body.appendChild( link ); // Firefox workaround, see #6594
 	document.body.appendChild( link ); // Firefox workaround, see #6594
 
 
-	var exportString = function ( output, filename ) {
+	function save( blob, filename ) {
 
 
-		var blob = new Blob( [ output ], { type: 'text/plain' } );
-		var objectURL = URL.createObjectURL( blob );
-
-		link.href = objectURL;
+		link.href = URL.createObjectURL( blob );
 		link.download = filename || 'data.json';
 		link.download = filename || 'data.json';
-		link.target = '_blank';
+		link.click();
+
+		// URL.revokeObjectURL( url ); breaks Firefox...
+
+	}
+
+	function saveString( text, filename ) {
 
 
-		var event = document.createEvent( 'MouseEvents' );
-		event.initMouseEvent(
-			'click', true, false, window, 0, 0, 0, 0, 0,
-			false, false, false, false, 0, null
-		);
-		link.dispatchEvent( event );
+		save( new Blob( [ text ], { type: 'text/plain' } ), filename );
 
 
-	};
+	}
 
 
 	return container;
 	return container;