Menubar.Edit.js 2.3 KB

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