Sidebar.Geometry.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Sidebar.Geometry = function ( editor ) {
  5. var signals = editor.signals;
  6. var container = new UI.CollapsiblePanel();
  7. container.setCollapsed( editor.config.getKey( 'ui/sidebar/geometry/collapsed' ) );
  8. container.onCollapsedChange( function ( boolean ) {
  9. editor.config.setKey( 'ui/sidebar/geometry/collapsed', boolean );
  10. } );
  11. container.setDisplay( 'none' );
  12. var geometryType = new UI.Text().setTextTransform( 'uppercase' );
  13. container.addStatic( geometryType );
  14. // Actions
  15. var objectActions = new UI.Select().setPosition('absolute').setRight( '8px' ).setFontSize( '11px' );
  16. objectActions.setOptions( {
  17. 'Actions': 'Actions',
  18. 'Center': 'Center',
  19. 'Convert': 'Convert',
  20. 'Flatten': 'Flatten'
  21. } );
  22. objectActions.onClick( function ( event ) {
  23. event.stopPropagation(); // Avoid panel collapsing
  24. } );
  25. objectActions.onChange( function ( event ) {
  26. var action = this.getValue();
  27. var object = editor.selected;
  28. var geometry = object.geometry;
  29. if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
  30. switch ( action ) {
  31. case 'Center':
  32. var offset = geometry.center();
  33. var newPosition = object.position.clone();
  34. newPosition.sub( offset );
  35. editor.execute( new CmdSetPosition( object, newPosition ) );
  36. editor.signals.geometryChanged.dispatch( object );
  37. break;
  38. case 'Convert':
  39. if ( geometry instanceof THREE.Geometry ) {
  40. editor.execute( new CmdSetGeometry( object, new THREE.BufferGeometry().fromGeometry( geometry ) ) );
  41. }
  42. break;
  43. case 'Flatten':
  44. var newGeometry = geometry.clone();
  45. newGeometry.uuid = geometry.uuid;
  46. newGeometry.applyMatrix( object.matrix );
  47. var cmds = [ new CmdSetGeometry( object, newGeometry ),
  48. new CmdSetPosition( object, new THREE.Vector3( 0, 0, 0 ) ),
  49. new CmdSetRotation( object, new THREE.Euler( 0, 0, 0 ) ),
  50. new CmdSetScale( object, new THREE.Vector3( 1, 1, 1 ) ) ];
  51. editor.execute( new CmdMultiCmds( cmds ), 'Flatten Geometry' );
  52. break;
  53. }
  54. this.setValue( 'Actions' );
  55. } );
  56. container.addStatic( objectActions );
  57. container.add( new UI.Break() );
  58. // uuid
  59. var geometryUUIDRow = new UI.Panel();
  60. var geometryUUID = new UI.Input().setWidth( '115px' ).setFontSize( '12px' ).setDisabled( true );
  61. var geometryUUIDRenew = new UI.Button( '⟳' ).setMarginLeft( '7px' ).onClick( function () {
  62. geometryUUID.setValue( THREE.Math.generateUUID() );
  63. editor.execute( new CmdSetGeometryValue( editor.selected, 'uuid', geometryUUID.getValue() ) );
  64. } );
  65. geometryUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
  66. geometryUUIDRow.add( geometryUUID );
  67. geometryUUIDRow.add( geometryUUIDRenew );
  68. container.add( geometryUUIDRow );
  69. // name
  70. var geometryNameRow = new UI.Panel();
  71. var geometryName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  72. editor.execute( new CmdSetGeometryValue( editor.selected, 'name', geometryName.getValue() ) );
  73. } );
  74. geometryNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
  75. geometryNameRow.add( geometryName );
  76. container.add( geometryNameRow );
  77. // geometry
  78. container.add( new Sidebar.Geometry.Geometry( editor ) );
  79. // buffergeometry
  80. container.add( new Sidebar.Geometry.BufferGeometry( editor ) );
  81. // parameters
  82. var parameters = new UI.Panel();
  83. container.add( parameters );
  84. //
  85. function build() {
  86. var object = editor.selected;
  87. if ( object && object.geometry ) {
  88. var geometry = object.geometry;
  89. container.setDisplay( 'block' );
  90. geometryType.setValue( geometry.type );
  91. geometryUUID.setValue( geometry.uuid );
  92. geometryName.setValue( geometry.name );
  93. //
  94. parameters.clear();
  95. if ( geometry.type === 'BufferGeometry' || geometry.type === 'Geometry' ) {
  96. parameters.add( new Sidebar.Geometry.Modifiers( editor, object ) );
  97. } else if ( Sidebar.Geometry[ geometry.type ] !== undefined ) {
  98. parameters.add( new Sidebar.Geometry[ geometry.type ]( editor, object ) );
  99. }
  100. } else {
  101. container.setDisplay( 'none' );
  102. }
  103. }
  104. signals.objectSelected.add( build );
  105. signals.geometryChanged.add( build );
  106. return container;
  107. }