Menubar.Edit.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Menubar.Edit = function ( editor ) {
  2. // event handlers
  3. // function onUndoOptionClick () {
  4. // console.log( 'UNDO not implemented yet' );
  5. // }
  6. // function onRedoOptionClick () {
  7. // console.log( 'REDO not implemented yet' );
  8. // }
  9. function onCloneOptionClick () {
  10. var object = editor.selected;
  11. if ( object.parent === undefined ) return; // avoid cloning the camera or scene
  12. object = object.clone();
  13. editor.addObject( object );
  14. editor.select( object );
  15. }
  16. function onDeleteOptionClick () {
  17. var parent = editor.selected.parent;
  18. editor.removeObject( editor.selected );
  19. editor.select( parent );
  20. }
  21. function onConvertOptionClick () {
  22. // convert to BufferGeometry
  23. var object = editor.selected;
  24. if ( object.geometry instanceof THREE.Geometry ) {
  25. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  26. if ( confirm( 'Convert ' + object.name + ' to BufferGeometry?' ) === false ) return;
  27. object.geometry = new THREE.BufferGeometry().fromGeometry( object.geometry );
  28. editor.signals.objectChanged.dispatch( object );
  29. }
  30. }
  31. function onFlattenOptionClick () {
  32. var object = editor.selected;
  33. if ( object.parent === undefined ) return; // avoid flattening the camera or scene
  34. if ( confirm( 'Flatten ' + object.name + '?' ) === false ) return;
  35. var geometry = object.geometry.clone();
  36. geometry.applyMatrix( object.matrix );
  37. object.geometry = geometry;
  38. object.position.set( 0, 0, 0 );
  39. object.rotation.set( 0, 0, 0 );
  40. object.scale.set( 1, 1, 1 );
  41. object.geometry.buffersNeedUpdate = true;
  42. editor.signals.objectChanged.dispatch( object );
  43. }
  44. // configure menu contents
  45. var createOption = UI.MenubarHelper.createOption;
  46. var createDivider = UI.MenubarHelper.createDivider;
  47. var menuConfig = [
  48. // createOption( 'Undo', onUndoOptionClick ),
  49. // createOption( 'Redo', onRedoOptionClick ),
  50. // createDivider(),
  51. createOption( 'Clone', onCloneOptionClick ),
  52. createOption( 'Delete', onDeleteOptionClick ),
  53. createDivider(),
  54. createOption( 'Convert', onConvertOptionClick ),
  55. createOption( 'Flatten', onFlattenOptionClick )
  56. ];
  57. var optionsPanel = UI.MenubarHelper.createOptionsPanel( menuConfig );
  58. return UI.MenubarHelper.createMenuContainer( 'Edit', optionsPanel );
  59. }