Menubar.Edit.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 parent = editor.selected.parent;
  32. editor.removeObject( editor.selected );
  33. editor.select( parent );
  34. } );
  35. options.add( option );
  36. //
  37. options.add( new UI.HorizontalRule() );
  38. // Flatten
  39. var option = new UI.Panel();
  40. option.setClass( 'option' );
  41. option.setTextContent( 'Flatten' );
  42. option.onClick( function () {
  43. var object = editor.selected;
  44. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  45. if ( confirm( 'Flatten ' + object.name + '?' ) === false ) return;
  46. var geometry = object.geometry;
  47. geometry.applyMatrix( object.matrix );
  48. geometry.verticesNeedUpdate = true;
  49. geometry.normalsNeedUpdate = true;
  50. object.position.set( 0, 0, 0 );
  51. object.rotation.set( 0, 0, 0 );
  52. object.scale.set( 1, 1, 1 );
  53. editor.signals.objectChanged.dispatch( object );
  54. } );
  55. options.add( option );
  56. return container;
  57. };