Sidebar.Geometry.js 4.6 KB

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