Menubar.Edit.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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' ).setColor( '#666' );
  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. // flatten
  30. var option = new UI.Panel();
  31. option.setClass( 'option' );
  32. option.setTextContent( 'Flatten' );
  33. option.onClick( function () {
  34. var object = editor.selected;
  35. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  36. if ( confirm( 'Flatten ' + object.name + '?' ) === false ) return;
  37. delete object.__webglInit; // TODO: Remove hack (WebGLRenderer refactoring)
  38. var geometry = object.geometry.clone();
  39. geometry.applyMatrix( object.matrix );
  40. object.geometry = geometry;
  41. object.position.set( 0, 0, 0 );
  42. object.rotation.set( 0, 0, 0 );
  43. object.scale.set( 1, 1, 1 );
  44. editor.signals.objectChanged.dispatch( object );
  45. } );
  46. options.add( option );
  47. // delete
  48. var option = new UI.Panel();
  49. option.setClass( 'option' );
  50. option.setTextContent( 'Delete' );
  51. option.onClick( function () {
  52. editor.removeObject( editor.selected );
  53. editor.deselect();
  54. } );
  55. options.add( option );
  56. //
  57. return container;
  58. }