/** * @author mrdoob / http://mrdoob.com/ */ Menubar.File = function ( editor ) { var container = new UI.Panel(); container.setClass( 'menu' ); var title = new UI.Panel(); title.setClass( 'title' ); title.setTextContent( 'File' ); container.add( title ); var options = new UI.Panel(); options.setClass( 'options' ); container.add( options ); // New var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'New' ); option.onClick( function () { if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) { editor.clear(); } } ); options.add( option ); // options.add( new UI.HorizontalRule() ); // Import var fileInput = document.createElement( 'input' ); fileInput.type = 'file'; fileInput.addEventListener( 'change', function ( event ) { editor.loader.loadFile( fileInput.files[ 0 ] ); } ); var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Import' ); option.onClick( function () { fileInput.click(); } ); options.add( option ); // options.add( new UI.HorizontalRule() ); // Export Geometry var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Export Geometry' ); option.onClick( function () { var object = editor.selected; if ( object === null ) { alert( 'No object selected.' ); return; } var geometry = object.geometry; if ( geometry === undefined ) { alert( 'The selected object doesn\'t have geometry.' ); return; } var output = geometry.toJSON(); try { output = JSON.stringify( output, null, '\t' ); output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' ); } catch ( e ) { output = JSON.stringify( output ); } exportString( output, 'geometry.json' ); } ); options.add( option ); // Export Object var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Export Object' ); option.onClick( function () { var object = editor.selected; if ( object === null ) { alert( 'No object selected' ); return; } var output = object.toJSON(); try { output = JSON.stringify( output, null, '\t' ); output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' ); } catch ( e ) { output = JSON.stringify( output ); } exportString( output, 'model.json' ); } ); options.add( option ); // Export Scene var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Export Scene' ); option.onClick( function () { var output = editor.scene.toJSON(); try { output = JSON.stringify( output, null, '\t' ); output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' ); } catch ( e ) { output = JSON.stringify( output ); } exportString( output, 'scene.json' ); } ); options.add( option ); // Export OBJ var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Export OBJ' ); option.onClick( function () { var object = editor.selected; if ( object === null ) { alert( 'No object selected.' ); return; } var exporter = new THREE.OBJExporter(); exportString( exporter.parse( object ), 'model.obj' ); } ); options.add( option ); // Export STL var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Export STL' ); option.onClick( function () { var exporter = new THREE.STLExporter(); exportString( exporter.parse( editor.scene ), 'model.stl' ); } ); options.add( option ); // options.add( new UI.HorizontalRule() ); // Publish var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Publish' ); option.onClick( function () { var camera = editor.camera; var zip = new JSZip(); zip.file( 'index.html', [ '', '', '
', '