Sidebar.Geometry.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Sidebar.Geometry = function ( editor ) {
  2. var signals = editor.signals;
  3. var container = new UI.CollapsiblePanel();
  4. container.setDisplay( 'none' );
  5. container.addStatic( new UI.Text().setValue( 'GEOMETRY' ) );
  6. container.add( new UI.Break() );
  7. // uuid
  8. var geometryUUIDRow = new UI.Panel();
  9. var geometryUUID = new UI.Input().setWidth( '115px' ).setColor( '#444' ).setFontSize( '12px' ).setDisabled( true );
  10. var geometryUUIDRenew = new UI.Button( '⟳' ).setMarginLeft( '7px' ).onClick( function () {
  11. geometryUUID.setValue( THREE.Math.generateUUID() );
  12. editor.selected.geometry.uuid = geometryUUID.getValue();
  13. } );
  14. geometryUUIDRow.add( new UI.Text( 'UUID' ).setWidth( '90px' ) );
  15. geometryUUIDRow.add( geometryUUID );
  16. geometryUUIDRow.add( geometryUUIDRenew );
  17. container.add( geometryUUIDRow );
  18. // name
  19. var geometryNameRow = new UI.Panel();
  20. var geometryName = new UI.Input().setWidth( '150px' ).setColor( '#444' ).setFontSize( '12px' ).onChange( function () {
  21. editor.setGeometryName( editor.selected.geometry, geometryName.getValue() );
  22. } );
  23. geometryNameRow.add( new UI.Text( 'Name' ).setWidth( '90px' ) );
  24. geometryNameRow.add( geometryName );
  25. container.add( geometryNameRow );
  26. // class
  27. var geometryTypeRow = new UI.Panel();
  28. var geometryType = new UI.Text().setWidth( '150px' ).setColor( '#444' ).setFontSize( '12px' );
  29. geometryTypeRow.add( new UI.Text( 'Type' ).setWidth( '90px' ) );
  30. geometryTypeRow.add( geometryType );
  31. container.add( geometryTypeRow );
  32. // vertices
  33. var geometryVerticesRow = new UI.Panel();
  34. var geometryVertices = new UI.Text().setColor( '#444' ).setFontSize( '12px' );
  35. geometryVerticesRow.add( new UI.Text( 'Vertices' ).setWidth( '90px' ) );
  36. geometryVerticesRow.add( geometryVertices );
  37. container.add( geometryVerticesRow );
  38. // faces
  39. var geometryFacesRow = new UI.Panel();
  40. var geometryFaces = new UI.Text().setColor( '#444' ).setFontSize( '12px' );
  41. geometryFacesRow.add( new UI.Text( 'Faces' ).setWidth( '90px' ) );
  42. geometryFacesRow.add( geometryFaces );
  43. container.add( geometryFacesRow );
  44. // parameters
  45. var parameters;
  46. //
  47. function build() {
  48. var object = editor.selected;
  49. if ( object && object.geometry ) {
  50. var geometry = object.geometry;
  51. container.setDisplay( 'block' );
  52. geometryType.setValue( editor.getGeometryType( object.geometry ) );
  53. updateFields( geometry );
  54. if ( parameters !== undefined ) {
  55. container.remove( parameters );
  56. parameters = undefined;
  57. }
  58. if ( geometry instanceof THREE.BoxGeometry ) {
  59. parameters = new Sidebar.Geometry.BoxGeometry( signals, object );
  60. container.add( parameters );
  61. } else if ( geometry instanceof THREE.CircleGeometry ) {
  62. parameters = new Sidebar.Geometry.CircleGeometry( signals, object );
  63. container.add( parameters );
  64. } else if ( geometry instanceof THREE.CylinderGeometry ) {
  65. parameters = new Sidebar.Geometry.CylinderGeometry( signals, object );
  66. container.add( parameters );
  67. } else if ( geometry instanceof THREE.SphereGeometry ) {
  68. parameters = new Sidebar.Geometry.SphereGeometry( signals, object );
  69. container.add( parameters );
  70. } else if ( geometry instanceof THREE.IcosahedronGeometry ) {
  71. parameters = new Sidebar.Geometry.IcosahedronGeometry( signals, object );
  72. container.add( parameters );
  73. } else if ( geometry instanceof THREE.PlaneGeometry ) {
  74. parameters = new Sidebar.Geometry.PlaneGeometry( signals, object );
  75. container.add( parameters );
  76. } else if ( geometry instanceof THREE.TorusGeometry ) {
  77. parameters = new Sidebar.Geometry.TorusGeometry( signals, object );
  78. container.add( parameters );
  79. } else if ( geometry instanceof THREE.TorusKnotGeometry ) {
  80. parameters = new Sidebar.Geometry.TorusKnotGeometry( signals, object );
  81. container.add( parameters );
  82. }
  83. } else {
  84. container.setDisplay( 'none' );
  85. }
  86. }
  87. signals.objectSelected.add( build );
  88. signals.objectChanged.add( build );
  89. //
  90. function updateFields( geometry ) {
  91. geometryUUID.setValue( geometry.uuid );
  92. geometryName.setValue( geometry.name );
  93. if ( geometry instanceof THREE.Geometry ) {
  94. geometryVertices.setValue( geometry.vertices.length );
  95. geometryFaces.setValue( geometry.faces.length );
  96. } else if ( geometry instanceof THREE.BufferGeometry ) {
  97. geometryVertices.setValue( geometry.attributes.position.array.length / 3 );
  98. if ( geometry.attributes.index !== undefined ) {
  99. geometryFaces.setValue( geometry.attributes.index.array.length / 3 );
  100. } else {
  101. geometryFaces.setValue( geometry.attributes.position.array.length / 9 );
  102. }
  103. }
  104. }
  105. return container;
  106. }