Menubar.File.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. Menubar.File = function ( editor ) {
  2. var container = new UI.Panel();
  3. container.setClass( 'menu' );
  4. container.onMouseOver( function () { options.setDisplay( 'block' ) } );
  5. container.onMouseOut( function () { options.setDisplay( 'none' ) } );
  6. container.onClick( function () { options.setDisplay( 'block' ) } );
  7. var title = new UI.Panel();
  8. title.setTextContent( 'File' ).setColor( '#666' );
  9. title.setMargin( '0px' );
  10. title.setPadding( '8px' );
  11. container.add( title );
  12. //
  13. var selectedObject;
  14. var scene;
  15. var options = new UI.Panel();
  16. options.setClass( 'options' );
  17. options.setDisplay( 'none' );
  18. container.add( options );
  19. /*
  20. // open
  21. var option = new UI.Panel();
  22. option.setClass( 'option' );
  23. option.setTextContent( 'Open' );
  24. option.onClick( function () { alert( 'Open' ) } );
  25. options.add( option );
  26. */
  27. // reset
  28. var option = new UI.Panel();
  29. option.setClass( 'option' );
  30. option.setTextContent( 'Reset' );
  31. option.onClick( function () {
  32. if ( confirm( 'Are you sure?' ) ) {
  33. if ( localStorage.threejsEditor !== undefined ) {
  34. delete localStorage.threejsEditor;
  35. }
  36. location.reload();
  37. }
  38. } );
  39. options.add( option );
  40. // export geometry
  41. var option = new UI.Panel();
  42. option.setClass( 'option' );
  43. option.setTextContent( 'Export Geometry' );
  44. option.onClick( function () {
  45. exportGeometry( THREE.GeometryExporter );
  46. } );
  47. options.add( option );
  48. /*
  49. // export scene
  50. var option = new UI.Panel();
  51. option.setClass( 'option' );
  52. option.setTextContent( 'Export Scene' );
  53. option.onClick( function () {
  54. exportScene( THREE.SceneExporter );
  55. } );
  56. options.add( option );
  57. */
  58. // export object
  59. var option = new UI.Panel();
  60. option.setClass( 'option' );
  61. option.setTextContent( 'Export Object' );
  62. option.onClick( function () {
  63. exportObject( THREE.ObjectExporter );
  64. } );
  65. options.add( option );
  66. // export scene
  67. var option = new UI.Panel();
  68. option.setClass( 'option' );
  69. option.setTextContent( 'Export Scene' );
  70. option.onClick( function () {
  71. exportScene( THREE.ObjectExporter );
  72. } );
  73. options.add( option );
  74. // export OBJ
  75. var option = new UI.Panel();
  76. option.setClass( 'option' );
  77. option.setTextContent( 'Export OBJ' );
  78. option.onClick( function () {
  79. exportGeometry( THREE.OBJExporter );
  80. } );
  81. options.add( option );
  82. var exportGeometry = function ( exporterClass ) {
  83. if ( selectedObject.geometry === undefined ) {
  84. alert( "Selected object doesn't have any geometry" );
  85. return;
  86. }
  87. var exporter = new exporterClass();
  88. var output;
  89. if ( exporter instanceof THREE.GeometryExporter ) {
  90. output = JSON.stringify( exporter.parse( selectedObject.geometry ), null, '\t' );
  91. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  92. } else {
  93. output = exporter.parse( selectedObject.geometry );
  94. }
  95. var blob = new Blob( [ output ], { type: 'text/plain' } );
  96. var objectURL = URL.createObjectURL( blob );
  97. window.open( objectURL, '_blank' );
  98. window.focus();
  99. };
  100. var exportObject = function ( exporterClass ) {
  101. var exporter = new exporterClass();
  102. var output = JSON.stringify( exporter.parse( selectedObject ), null, '\t' );
  103. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  104. var blob = new Blob( [ output ], { type: 'text/plain' } );
  105. var objectURL = URL.createObjectURL( blob );
  106. window.open( objectURL, '_blank' );
  107. window.focus();
  108. };
  109. var exportScene = function ( exporterClass ) {
  110. var exporter = new exporterClass();
  111. var output = JSON.stringify( exporter.parse( scene ), null, '\t' );
  112. output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  113. var blob = new Blob( [ output ], { type: 'text/plain' } );
  114. var objectURL = URL.createObjectURL( blob );
  115. window.open( objectURL, '_blank' );
  116. window.focus();
  117. };
  118. return container;
  119. }