Browse Source

User friendly file saving

User friendly file saving
Alexander 10 years ago
parent
commit
5395ea1176
1 changed files with 11 additions and 8 deletions
  1. 11 8
      editor/js/Menubar.File.js

+ 11 - 8
editor/js/Menubar.File.js

@@ -89,7 +89,7 @@ Menubar.File = function ( editor ) {
 		output = JSON.stringify( output, null, '\t' );
 		output = JSON.stringify( output, null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 
 
-		exportString( output );
+		exportString( output, "geometry.json" );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -114,7 +114,7 @@ Menubar.File = function ( editor ) {
 		output = JSON.stringify( output, null, '\t' );
 		output = JSON.stringify( output, null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 
 
-		exportString( output );
+		exportString( output, "model.json" );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -130,7 +130,7 @@ Menubar.File = function ( editor ) {
 		output = JSON.stringify( output, null, '\t' );
 		output = JSON.stringify( output, null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 
 
-		exportString( output );
+		exportString( output, "scene.json" );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -153,7 +153,7 @@ Menubar.File = function ( editor ) {
 
 
 		var exporter = new THREE.OBJExporter();
 		var exporter = new THREE.OBJExporter();
 
 
-		exportString( exporter.parse( object ) );
+		exportString( exporter.parse( object ), "model.obj" );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -167,7 +167,7 @@ Menubar.File = function ( editor ) {
 
 
 		var exporter = new THREE.STLExporter();
 		var exporter = new THREE.STLExporter();
 
 
-		exportString( exporter.parse( editor.scene ) );
+		exportString( exporter.parse( editor.scene ), "model.stl" );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -274,13 +274,16 @@ Menubar.File = function ( editor ) {
 
 
 	//
 	//
 
 
-	var exportString = function ( output ) {
+	var exportString = function ( output, filename ) {
 
 
 		var blob = new Blob( [ output ], { type: 'text/plain' } );
 		var blob = new Blob( [ output ], { type: 'text/plain' } );
 		var objectURL = URL.createObjectURL( blob );
 		var objectURL = URL.createObjectURL( blob );
 
 
-		window.open( objectURL, '_blank' );
-		window.focus();
+		var link = document.createElement('a');
+		link.href = objectURL;
+		link.download = filename || "data.json";
+		link.target = "_blank";
+		link.click();
 
 
 	};
 	};