Sidebar.Geometry.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. /*
  11. var objectActions = new UI.Select().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
  12. objectActions.setOptions( {
  13. 'Actions': 'Actions',
  14. 'Center': 'Center',
  15. 'Convert': 'Convert',
  16. 'Flatten': 'Flatten'
  17. } );
  18. objectActions.onClick( function ( event ) {
  19. event.stopPropagation(); // Avoid panel collapsing
  20. } );
  21. objectActions.onChange( function ( event ) {
  22. var action = this.getValue();
  23. var object = editor.selected;
  24. var geometry = object.geometry;
  25. if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
  26. switch ( action ) {
  27. case 'Center':
  28. var offset = geometry.center();
  29. var newPosition = object.position.clone();
  30. newPosition.sub( offset );
  31. editor.execute( new SetPositionCommand( object, newPosition ) );
  32. editor.signals.geometryChanged.dispatch( object );
  33. break;
  34. case 'Convert':
  35. if ( geometry instanceof THREE.Geometry ) {
  36. editor.execute( new SetGeometryCommand( object, new THREE.BufferGeometry().fromGeometry( geometry ) ) );
  37. }
  38. break;
  39. case 'Flatten':
  40. var newGeometry = geometry.clone();
  41. newGeometry.uuid = geometry.uuid;
  42. newGeometry.applyMatrix( object.matrix );
  43. var cmds = [ new SetGeometryCommand( object, newGeometry ),
  44. new SetPositionCommand( object, new THREE.Vector3( 0, 0, 0 ) ),
  45. new SetRotationCommand( object, new THREE.Euler( 0, 0, 0 ) ),
  46. new SetScaleCommand( object, new THREE.Vector3( 1, 1, 1 ) ) ];
  47. editor.execute( new MultiCmdsCommand( cmds ), 'Flatten Geometry' );
  48. break;
  49. }
  50. this.setValue( 'Actions' );
  51. } );
  52. container.addStatic( objectActions );
  53. */
  54. // type
  55. var geometryTypeRow = new UI.Row();
  56. var geometryType = new UI.Text();
  57. geometryTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
  58. geometryTypeRow.add( geometryType );
  59. container.add( geometryTypeRow );
  60. // uuid
  61. var geometryUUIDRow = new UI.Row();
  62. var geometryUUID = new UI.Input().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
  63. var geometryUUIDRenew = new UI.Button( 'New' ).setMarginLeft( '7px' ).onClick( function () {
  64. geometryUUID.setValue( THREE.Math.generateUUID() );
  65. editor.execute( new SetGeometryValueCommand( editor.selected, 'uuid', geometryUUID.getValue() ) );
  66. } );
  67. geometryUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
  68. geometryUUIDRow.add( geometryUUID );
  69. geometryUUIDRow.add( geometryUUIDRenew );
  70. container.add( geometryUUIDRow );
  71. // name
  72. var geometryNameRow = new UI.Row();
  73. var geometryName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  74. editor.execute( new SetGeometryValueCommand( editor.selected, 'name', geometryName.getValue() ) );
  75. } );
  76. geometryNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
  77. geometryNameRow.add( geometryName );
  78. container.add( geometryNameRow );
  79. // parameters
  80. var parameters = new UI.Span();
  81. container.add( parameters );
  82. // geometry
  83. container.add( new Sidebar.Geometry.Geometry( editor ) );
  84. // buffergeometry
  85. container.add( new Sidebar.Geometry.BufferGeometry( editor ) );
  86. // size
  87. var geometryBoundingSphere = new UI.Text();
  88. container.add( new UI.Text( 'Bounds' ).setWidth( '90px' ) );
  89. container.add( geometryBoundingSphere );
  90. //
  91. function build() {
  92. var object = editor.selected;
  93. if ( object && object.geometry ) {
  94. var geometry = object.geometry;
  95. container.setDisplay( 'block' );
  96. geometryType.setValue( geometry.type );
  97. geometryUUID.setValue( geometry.uuid );
  98. geometryName.setValue( geometry.name );
  99. //
  100. parameters.clear();
  101. if ( geometry.type === 'BufferGeometry' || geometry.type === 'Geometry' ) {
  102. parameters.add( new Sidebar.Geometry.Modifiers( editor, object ) );
  103. } else if ( Sidebar.Geometry[ geometry.type ] !== undefined ) {
  104. parameters.add( new Sidebar.Geometry[ geometry.type ]( editor, object ) );
  105. }
  106. geometryBoundingSphere.setValue( Math.floor( geometry.boundingSphere.radius * 1000 ) / 1000 );
  107. } else {
  108. container.setDisplay( 'none' );
  109. }
  110. }
  111. signals.objectSelected.add( build );
  112. signals.geometryChanged.add( build );
  113. return container;
  114. };