Menubar.Edit.js 1.8 KB

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