Menubar.Edit.js 1.7 KB

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