Sidebar.Geometry.js 4.0 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.Panel();
  7. container.setBorderTop( '0' );
  8. container.setPaddingTop( '20px' );
  9. // Actions
  10. var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
  11. objectActions.setOptions( {
  12. 'Actions': 'Actions',
  13. 'Center': 'Center',
  14. 'Convert': 'Convert',
  15. 'Flatten': 'Flatten'
  16. } );
  17. objectActions.onClick( function ( event ) {
  18. event.stopPropagation(); // Avoid panel collapsing
  19. } );
  20. objectActions.onChange( function ( event ) {
  21. var action = this.getValue();
  22. var object = editor.selected;
  23. var geometry = object.geometry;
  24. if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
  25. switch ( action ) {
  26. case 'Center':
  27. var offset = geometry.center();
  28. var newPosition = object.position.clone();
  29. newPosition.sub( offset );
  30. editor.execute( new SetPositionCommand( object, newPosition ) );
  31. editor.signals.geometryChanged.dispatch( object );
  32. break;
  33. case 'Convert':
  34. if ( geometry instanceof THREE.Geometry ) {
  35. editor.execute( new SetGeometryCommand( object, new THREE.BufferGeometry().fromGeometry( geometry ) ) );
  36. }
  37. break;
  38. case 'Flatten':
  39. var newGeometry = geometry.clone();
  40. newGeometry.uuid = geometry.uuid;
  41. newGeometry.applyMatrix( object.matrix );
  42. var cmds = [ new SetGeometryCommand( object, newGeometry ),
  43. new SetPositionCommand( object, new THREE.Vector3( 0, 0, 0 ) ),
  44. new SetRotationCommand( object, new THREE.Euler( 0, 0, 0 ) ),
  45. new SetScaleCommand( object, new THREE.Vector3( 1, 1, 1 ) ) ];
  46. editor.execute( new MultiCmdsCommand( cmds ), 'Flatten Geometry' );
  47. break;
  48. }
  49. this.setValue( 'Actions' );
  50. } );
  51. // container.addStatic( objectActions );
  52. // type
  53. var geometryTypeRow = new UI.Row();
  54. var geometryType = new UI.Text();
  55. geometryTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
  56. geometryTypeRow.add( geometryType );
  57. container.add( geometryTypeRow );
  58. // uuid
  59. var geometryUUIDRow = new UI.Row();
  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 SetGeometryValueCommand( 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.Row();
  71. var geometryName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  72. editor.execute( new SetGeometryValueCommand( 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.Span();
  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. };