Menubar.Edit.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Menubar.Edit = 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( 'Edit' );
  9. title.setMargin( '0px' );
  10. title.setPadding( '8px' );
  11. container.add( title );
  12. //
  13. var options = new UI.Panel();
  14. options.setClass( 'options' );
  15. options.setDisplay( 'none' );
  16. container.add( options );
  17. // clone
  18. var option = new UI.Panel();
  19. option.setClass( 'option' );
  20. option.setTextContent( 'Clone' );
  21. option.onClick( function () {
  22. var object = editor.selected;
  23. if ( object.parent === undefined ) return; // avoid cloning the camera or scene
  24. object = object.clone();
  25. editor.addObject( object );
  26. editor.select( object );
  27. } );
  28. options.add( option );
  29. // delete
  30. var option = new UI.Panel();
  31. option.setClass( 'option' );
  32. option.setTextContent( 'Delete' );
  33. option.onClick( function () {
  34. editor.removeObject( editor.selected );
  35. editor.deselect();
  36. } );
  37. options.add( option );
  38. options.add( new UI.HorizontalRule() );
  39. // convert to BufferGeometry
  40. var option = new UI.Panel();
  41. option.setClass( 'option' );
  42. option.setTextContent( 'Convert' );
  43. option.onClick( function () {
  44. var object = editor.selected;
  45. if ( object.geometry instanceof THREE.Geometry ) {
  46. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  47. if ( confirm( 'Convert ' + object.name + ' to BufferGeometry?' ) === false ) return;
  48. delete object.__webglInit; // TODO: Remove hack (WebGLRenderer refactoring)
  49. object.geometry = THREE.BufferGeometryUtils.fromGeometry( object.geometry );
  50. editor.signals.objectChanged.dispatch( object );
  51. }
  52. } );
  53. options.add( option );
  54. // flatten
  55. var option = new UI.Panel();
  56. option.setClass( 'option' );
  57. option.setTextContent( 'Flatten' );
  58. option.onClick( function () {
  59. var object = editor.selected;
  60. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  61. if ( confirm( 'Flatten ' + object.name + '?' ) === false ) return;
  62. delete object.__webglInit; // TODO: Remove hack (WebGLRenderer refactoring)
  63. var geometry = object.geometry.clone();
  64. geometry.applyMatrix( object.matrix );
  65. object.geometry = geometry;
  66. object.position.set( 0, 0, 0 );
  67. object.rotation.set( 0, 0, 0 );
  68. object.scale.set( 1, 1, 1 );
  69. editor.signals.objectChanged.dispatch( object );
  70. } );
  71. options.add( option );
  72. //
  73. return container;
  74. }