|
@@ -1,97 +1,72 @@
|
|
|
Menubar.File = function ( editor ) {
|
|
|
|
|
|
- // helpers
|
|
|
-
|
|
|
- function exportGeometry ( exporterClass ) {
|
|
|
-
|
|
|
- var object = editor.selected;
|
|
|
- var exporter = new exporterClass();
|
|
|
-
|
|
|
- var output = exporter.parse( object.geometry );
|
|
|
-
|
|
|
- if ( exporter instanceof THREE.BufferGeometryExporter ||
|
|
|
- exporter instanceof THREE.GeometryExporter ) {
|
|
|
-
|
|
|
- output = JSON.stringify( output, null, '\t' );
|
|
|
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- var blob = new Blob( [ output ], { type: 'text/plain' } );
|
|
|
- var objectURL = URL.createObjectURL( blob );
|
|
|
-
|
|
|
- window.open( objectURL, '_blank' );
|
|
|
- window.focus();
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- function exportObject ( exporterClass ) {
|
|
|
-
|
|
|
- var object = editor.selected;
|
|
|
- var exporter = new exporterClass();
|
|
|
+ var container = new UI.Panel();
|
|
|
+ container.setClass( 'menu' );
|
|
|
|
|
|
- var output = JSON.stringify( exporter.parse( object ), null, '\t' );
|
|
|
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
|
+ var title = new UI.Panel();
|
|
|
+ title.setClass( 'title' );
|
|
|
+ title.setTextContent( 'File' );
|
|
|
+ container.add( title );
|
|
|
|
|
|
- var blob = new Blob( [ output ], { type: 'text/plain' } );
|
|
|
- var objectURL = URL.createObjectURL( blob );
|
|
|
+ var options = new UI.Panel();
|
|
|
+ options.setClass( 'options' );
|
|
|
+ container.add( options );
|
|
|
|
|
|
- window.open( objectURL, '_blank' );
|
|
|
- window.focus();
|
|
|
+ // New
|
|
|
|
|
|
- }
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'New' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
- function exportScene ( exporterClass ) {
|
|
|
-
|
|
|
- var exporter = new exporterClass();
|
|
|
+ if ( confirm( 'Are you sure?' ) ) {
|
|
|
|
|
|
- var output = exporter.parse( editor.scene );
|
|
|
+ editor.config.clear();
|
|
|
+ editor.storage.clear( function () {
|
|
|
|
|
|
- if ( exporter instanceof THREE.ObjectExporter ) {
|
|
|
+ location.href = location.pathname;
|
|
|
|
|
|
- output = JSON.stringify( output, null, '\t' );
|
|
|
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
|
|
|
|
- var blob = new Blob( [ output ], { type: 'text/plain' } );
|
|
|
- var objectURL = URL.createObjectURL( blob );
|
|
|
-
|
|
|
- window.open( objectURL, '_blank' );
|
|
|
- window.focus();
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
|
|
|
- }
|
|
|
+ //
|
|
|
|
|
|
- // event handlers
|
|
|
+ options.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- function onNewOptionClick () {
|
|
|
+ // Import
|
|
|
|
|
|
- if ( confirm( 'Are you sure?' ) ) {
|
|
|
-
|
|
|
- editor.config.clear();
|
|
|
- editor.storage.clear( function () {
|
|
|
-
|
|
|
- location.href = location.pathname;
|
|
|
-
|
|
|
- } );
|
|
|
+ var fileInput = document.createElement( 'input' );
|
|
|
+ fileInput.type = 'file';
|
|
|
+ fileInput.addEventListener( 'change', function ( event ) {
|
|
|
|
|
|
- }
|
|
|
+ editor.loader.loadFile( fileInput.files[ 0 ] );
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
|
|
|
- function onImportOptionClick () {
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Import' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
fileInput.click();
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
|
|
|
- function onFileInputChange ( event ) {
|
|
|
+ //
|
|
|
|
|
|
- editor.loader.loadFile( fileInput.files[ 0 ] );
|
|
|
+ options.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- }
|
|
|
+ // Export Geometry
|
|
|
|
|
|
- function onExportGeometryOptionClick () {
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Export Geometry' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
var object = editor.selected;
|
|
|
|
|
@@ -121,9 +96,15 @@ Menubar.File = function ( editor ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
+
|
|
|
+ // Export Object
|
|
|
|
|
|
- function onExportObjectOptionClick () {
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Export Object' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
if ( editor.selected === null ) {
|
|
|
|
|
@@ -134,63 +115,125 @@ Menubar.File = function ( editor ) {
|
|
|
|
|
|
exportObject( THREE.ObjectExporter );
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
+
|
|
|
+ // Export Scene
|
|
|
|
|
|
- function onExportSceneOptionClick () {
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Export Scene' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
exportScene( THREE.ObjectExporter );
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
|
|
|
- function onExportOBJOptionClick () {
|
|
|
+ // Export OBJ
|
|
|
+
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Export OBJ' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
exportGeometry( THREE.OBJExporter );
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
+
|
|
|
+ // Export STL
|
|
|
|
|
|
- function onExportSTLOptionClick () {
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Export STL' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
exportScene( THREE.STLExporter );
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ options.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- function onExportTestOptionClick() {
|
|
|
+ // Test
|
|
|
+
|
|
|
+ var option = new UI.Panel();
|
|
|
+ option.setClass( 'option' );
|
|
|
+ option.setTextContent( 'Test' );
|
|
|
+ option.onClick( function () {
|
|
|
|
|
|
var text = new UI.Text( 'blah' );
|
|
|
editor.showDialog( text );
|
|
|
|
|
|
- }
|
|
|
+ } );
|
|
|
+ options.add( option );
|
|
|
|
|
|
- // create file input element for scene import
|
|
|
|
|
|
- var fileInput = document.createElement( 'input' );
|
|
|
- fileInput.type = 'file';
|
|
|
- fileInput.addEventListener( 'change', onFileInputChange);
|
|
|
+ //
|
|
|
+
|
|
|
+ var exportGeometry = function ( exporterClass ) {
|
|
|
|
|
|
- // configure menu contents
|
|
|
+ var object = editor.selected;
|
|
|
+ var exporter = new exporterClass();
|
|
|
|
|
|
- var createOption = UI.MenubarHelper.createOption;
|
|
|
- var createDivider = UI.MenubarHelper.createDivider;
|
|
|
-
|
|
|
- var menuConfig = [
|
|
|
- createOption( 'New', onNewOptionClick ),
|
|
|
- createDivider(),
|
|
|
-
|
|
|
- createOption( 'Import', onImportOptionClick ),
|
|
|
- createDivider(),
|
|
|
-
|
|
|
- createOption( 'Export Geometry', onExportGeometryOptionClick ),
|
|
|
- createOption( 'Export Object', onExportObjectOptionClick ),
|
|
|
- createOption( 'Export Scene', onExportSceneOptionClick ),
|
|
|
- createOption( 'Export OBJ', onExportOBJOptionClick ),
|
|
|
- createOption( 'Export STL', onExportSTLOptionClick ),
|
|
|
- createDivider(),
|
|
|
-
|
|
|
- createOption( 'Export Test', onExportTestOptionClick )
|
|
|
- ];
|
|
|
+ var output = exporter.parse( object.geometry );
|
|
|
+
|
|
|
+ if ( exporter instanceof THREE.BufferGeometryExporter ||
|
|
|
+ exporter instanceof THREE.GeometryExporter ) {
|
|
|
|
|
|
- var optionsPanel = UI.MenubarHelper.createOptionsPanel( menuConfig );
|
|
|
+ output = JSON.stringify( output, null, '\t' );
|
|
|
+ output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var blob = new Blob( [ output ], { type: 'text/plain' } );
|
|
|
+ var objectURL = URL.createObjectURL( blob );
|
|
|
+
|
|
|
+ window.open( objectURL, '_blank' );
|
|
|
+ window.focus();
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ var exportObject = function ( exporterClass ) {
|
|
|
+
|
|
|
+ var object = editor.selected;
|
|
|
+ var exporter = new exporterClass();
|
|
|
+
|
|
|
+ var output = JSON.stringify( exporter.parse( object ), null, '\t' );
|
|
|
+ output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
|
+
|
|
|
+ var blob = new Blob( [ output ], { type: 'text/plain' } );
|
|
|
+ var objectURL = URL.createObjectURL( blob );
|
|
|
+
|
|
|
+ window.open( objectURL, '_blank' );
|
|
|
+ window.focus();
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ var exportScene = function ( exporterClass ) {
|
|
|
+
|
|
|
+ var exporter = new exporterClass();
|
|
|
+
|
|
|
+ var output = exporter.parse( editor.scene );
|
|
|
+
|
|
|
+ if ( exporter instanceof THREE.ObjectExporter ) {
|
|
|
+
|
|
|
+ output = JSON.stringify( output, null, '\t' );
|
|
|
+ output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var blob = new Blob( [ output ], { type: 'text/plain' } );
|
|
|
+ var objectURL = URL.createObjectURL( blob );
|
|
|
+
|
|
|
+ window.open( objectURL, '_blank' );
|
|
|
+ window.focus();
|
|
|
+
|
|
|
+ };
|
|
|
|
|
|
- return UI.MenubarHelper.createMenuContainer( 'File', optionsPanel );
|
|
|
+ return container;
|
|
|
|
|
|
-}
|
|
|
+};
|