Sidebar.Properties.Geometry.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Sidebar.Properties.Geometry = function ( signals ) {
  2. var container = new UI.Panel();
  3. container.setDisplay( 'none' );
  4. container.add( new UI.Text().setText( 'GEOMETRY' ).setColor( '#666' ) );
  5. container.add( new UI.Button( 'absolute' ).setRight( '0px' ).setText( 'Export' ).onClick( exportGeometry ) );
  6. container.add( new UI.Break(), new UI.Break() );
  7. container.add( new UI.Text().setText( 'Name' ).setColor( '#666' ) );
  8. var geometryName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  9. container.add( geometryName );
  10. container.add( new UI.HorizontalRule() );
  11. container.add( new UI.Text().setText( 'Class' ).setColor( '#666' ) );
  12. var geometryClass = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  13. container.add( geometryClass );
  14. container.add( new UI.HorizontalRule() );
  15. container.add( new UI.Text().setText( 'Vertices' ).setColor( '#666' ) );
  16. var verticesCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  17. container.add( verticesCount );
  18. container.add( new UI.HorizontalRule() );
  19. container.add( new UI.Text().setText( 'Faces' ).setColor( '#666' ) );
  20. var facesCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  21. container.add( facesCount );
  22. container.add( new UI.Break(), new UI.Break(), new UI.Break() );
  23. //
  24. var selected = null;
  25. signals.objectSelected.add( function ( object ) {
  26. if ( object && object.geometry ) {
  27. selected = object.geometry;
  28. container.setDisplay( 'block' );
  29. geometryName.setText( object.geometry.name );
  30. geometryClass.setText( getGeometryInstanceName( object.geometry ) );
  31. verticesCount.setText( object.geometry.vertices.length );
  32. facesCount.setText( object.geometry.faces.length );
  33. } else {
  34. selected = null;
  35. container.setDisplay( 'none' );
  36. }
  37. } );
  38. function getGeometryInstanceName( geometry ) {
  39. // TODO: Is there a way of doing this automatically?
  40. if ( geometry instanceof THREE.ConvexGeometry ) return "ConvexGeometry";
  41. if ( geometry instanceof THREE.CubeGeometry ) return "CubeGeometry";
  42. if ( geometry instanceof THREE.CylinderGeometry ) return "CylinderGeometry";
  43. if ( geometry instanceof THREE.ExtrudeGeometry ) return "ExtrudeGeometry";
  44. if ( geometry instanceof THREE.IcosahedronGeometry ) return "IcosahedronGeometry";
  45. if ( geometry instanceof THREE.LatheGeometry ) return "LatheGeometry";
  46. if ( geometry instanceof THREE.OctahedronGeometry ) return "OctahedronGeometry";
  47. if ( geometry instanceof THREE.ParametricGeometry ) return "ParametricGeometry";
  48. if ( geometry instanceof THREE.PlaneGeometry ) return "PlaneGeometry";
  49. if ( geometry instanceof THREE.PolyhedronGeometry ) return "PolyhedronGeometry";
  50. if ( geometry instanceof THREE.SphereGeometry ) return "SphereGeometry";
  51. if ( geometry instanceof THREE.TetrahedronGeometry ) return "TetrahedronGeometry";
  52. if ( geometry instanceof THREE.TextGeometry ) return "TextGeometry";
  53. if ( geometry instanceof THREE.TorusGeometry ) return "TorusGeometry";
  54. if ( geometry instanceof THREE.TorusKnotGeometry ) return "TorusKnotGeometry";
  55. if ( geometry instanceof THREE.TubeGeometry ) return "TubeGeometry";
  56. if ( geometry instanceof THREE.Geometry ) return "Geometry";
  57. }
  58. function exportGeometry() {
  59. console.log( selected );
  60. }
  61. return container;
  62. }