123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- /**
- * @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( 'Are you sure?' ) ) {
- editor.config.setKey(
- 'camera/position', [ 500, 250, 500 ],
- 'camera/target', [ 0, 0, 0 ]
- );
- editor.storage.clear( function () {
- location.href = location.pathname;
- } );
- }
- } );
- 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();
- output = JSON.stringify( output, null, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- exportString( output );
- } );
- 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();
- output = JSON.stringify( output, null, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- exportString( output );
- } );
- 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();
- output = JSON.stringify( output, null, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- exportString( output );
- } );
- 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 ) );
- } );
- 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 ) );
- } );
- 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', [
- '<!DOCTYPE html>',
- '<html lang="en">',
- ' <head>',
- ' <title>three.js</title>',
- ' <meta charset="utf-8">',
- ' <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">',
- ' <style>',
- ' body {',
- ' margin: 0px;',
- ' overflow: hidden;',
- ' }',
- ' </style>',
- ' </head>',
- ' <body ontouchstart="">',
- ' <script src="js/three.min.js"></script>',
- ' <script src="js/OrbitControls.js"></script>',
- ' <script>',
- '',
- ' var camera, controls, scene, renderer;',
- '',
- ' var loader = new THREE.ObjectLoader();',
- ' loader.load( \'scene.json\', function ( object ) {',
- '',
- ' scene = object;',
- '',
- ' camera = new THREE.PerspectiveCamera( ' + camera.fov + ', 1, ' + camera.near + ', ' + camera.far + ' );',
- ' camera.position.set( ' + camera.position.x + ', ' + camera.position.y + ', ' + camera.position.z + ' );',
- ' camera.rotation.set( ' + camera.rotation.x + ', ' + camera.rotation.y + ', ' + camera.rotation.z + ' );',
- '',
- ' controls = new THREE.OrbitControls( camera );',
- ' controls.addEventListener( \'change\', render );',
- '',
- ' renderer = new THREE.WebGLRenderer();',
- ' renderer.setSize( window.innerWidth, window.innerHeight );',
- ' document.body.appendChild( renderer.domElement );',
- '',
- ' camera.aspect = window.innerWidth / window.innerHeight;',
- ' camera.updateProjectionMatrix();',
- '',
- ' animate();',
- ' render();',
- '',
- ' } );',
- '',
- ' var render = function () {',
- '',
- ' renderer.render( scene, camera );',
- '',
- ' };',
- '',
- ' var animate = function () {',
- '',
- ' requestAnimationFrame( animate );',
- ' controls.update();',
- '',
- ' };',
- '',
- ' </script>',
- ' </body>',
- '</html>'
- ].join( '\n' ) );
- //
- var output = editor.scene.toJSON();
- output = JSON.stringify( output, null, '\t' );
- output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
- zip.file( 'scene.json', output );
- //
- var manager = new THREE.LoadingManager( function () {
- location.href = 'data:application/zip;base64,' + zip.generate();
- } );
- var loader = new THREE.XHRLoader( manager );
- loader.load( '../build/three.min.js', function ( content ) {
- zip.file( 'js/three.min.js', content );
- } );
- loader.load( '../examples/js/controls/OrbitControls.js', function ( content ) {
- zip.file( 'js/OrbitControls.js', content );
- } );
- } );
- options.add( option );
- /*
- // 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 );
- */
- //
- var exportString = function ( output ) {
- var blob = new Blob( [ output ], { type: 'text/plain' } );
- var objectURL = URL.createObjectURL( blob );
- window.open( objectURL, '_blank' );
- window.focus();
- };
- return container;
- };
|