Menubar.Edit.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. Menubar.Edit = function ( editor ) {
  2. var container = new UI.Panel();
  3. container.setClass( 'menu' );
  4. var title = new UI.Panel();
  5. title.setClass( 'title' );
  6. title.setTextContent( 'Edit' );
  7. container.add( title );
  8. var options = new UI.Panel();
  9. options.setClass( 'options' );
  10. container.add( options );
  11. // Clone
  12. var option = new UI.Panel();
  13. option.setClass( 'option' );
  14. option.setTextContent( 'Clone' );
  15. option.onClick( function () {
  16. var object = editor.selected;
  17. if ( object.parent === undefined ) return; // avoid cloning the camera or scene
  18. object = object.clone();
  19. editor.addObject( object );
  20. editor.select( object );
  21. } );
  22. options.add( option );
  23. // Delete
  24. var option = new UI.Panel();
  25. option.setClass( 'option' );
  26. option.setTextContent( 'Delete' );
  27. option.onClick( function () {
  28. var parent = editor.selected.parent;
  29. editor.removeObject( editor.selected );
  30. editor.select( parent );
  31. } );
  32. options.add( option );
  33. //
  34. options.add( new UI.HorizontalRule() );
  35. // Convert
  36. var option = new UI.Panel();
  37. option.setClass( 'option' );
  38. option.setTextContent( 'Convert' );
  39. option.onClick( function () {
  40. // convert to BufferGeometry
  41. var object = editor.selected;
  42. if ( object.geometry instanceof THREE.Geometry ) {
  43. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  44. if ( confirm( 'Convert ' + object.name + ' to BufferGeometry?' ) === false ) return;
  45. object.geometry = new THREE.BufferGeometry().fromGeometry( object.geometry );
  46. editor.signals.objectChanged.dispatch( object );
  47. }
  48. } );
  49. options.add( option );
  50. // Flatten
  51. var option = new UI.Panel();
  52. option.setClass( 'option' );
  53. option.setTextContent( 'Flatten' );
  54. option.onClick( function () {
  55. var object = editor.selected;
  56. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  57. if ( confirm( 'Flatten ' + object.name + '?' ) === false ) return;
  58. var geometry = object.geometry.clone();
  59. geometry.applyMatrix( object.matrix );
  60. object.geometry = geometry;
  61. object.position.set( 0, 0, 0 );
  62. object.rotation.set( 0, 0, 0 );
  63. object.scale.set( 1, 1, 1 );
  64. object.geometry.buffersNeedUpdate = true;
  65. editor.signals.objectChanged.dispatch( object );
  66. } );
  67. options.add( option );
  68. return container;
  69. };