Sidebar.Geometry.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. Sidebar.Geometry = function ( signals ) {
  2. var geometries = {
  3. "ConvexGeometry": THREE.ConvexGeometry,
  4. "CubeGeometry": THREE.CubeGeometry,
  5. "CylinderGeometry": THREE.CylinderGeometry,
  6. "ExtrudeGeometry": THREE.ExtrudeGeometry,
  7. "IcosahedronGeometry": THREE.IcosahedronGeometry,
  8. "LatheGeometry": THREE.LatheGeometry,
  9. "OctahedronGeometry": THREE.OctahedronGeometry,
  10. "ParametricGeometry": THREE.ParametricGeometry,
  11. "PlaneGeometry": THREE.PlaneGeometry,
  12. "PolyhedronGeometry": THREE.PolyhedronGeometry,
  13. "SphereGeometry": THREE.SphereGeometry,
  14. "TetrahedronGeometry": THREE.TetrahedronGeometry,
  15. "TextGeometry": THREE.TextGeometry,
  16. "TorusGeometry": THREE.TorusGeometry,
  17. "TorusKnotGeometry": THREE.TorusKnotGeometry,
  18. "TubeGeometry": THREE.TubeGeometry,
  19. "Geometry": THREE.Geometry
  20. };
  21. var container = new UI.Panel();
  22. container.setBorderTop( '1px solid #ccc' );
  23. container.setDisplay( 'none' );
  24. container.setPadding( '10px' );
  25. container.add( new UI.Text().setValue( 'GEOMETRY' ).setColor( '#666' ) );
  26. container.add( new UI.Break(), new UI.Break() );
  27. // name
  28. var geometryNameRow = new UI.Panel();
  29. var geometryName = new UI.Input( 'absolute' ).setLeft( '100px' ).setWidth( '150px' ).setColor( '#444' ).setFontSize( '12px' ).onChange( update );
  30. geometryNameRow.add( new UI.Text().setValue( 'Name' ).setColor( '#666' ) );
  31. geometryNameRow.add( geometryName );
  32. container.add( geometryNameRow );
  33. // class
  34. var geometryClassRow = new UI.Panel();
  35. var geometryClass = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  36. geometryClassRow.add( new UI.Text().setValue( 'Class' ).setColor( '#666' ) );
  37. geometryClassRow.add( geometryClass );
  38. container.add( geometryClassRow );
  39. // vertices
  40. var geometryVerticesRow = new UI.Panel();
  41. var geometryVertices = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  42. geometryVerticesRow.add( new UI.Text().setValue( 'Vertices' ).setColor( '#666' ) );
  43. geometryVerticesRow.add( geometryVertices );
  44. container.add( geometryVerticesRow );
  45. // faces
  46. var geometryFacesRow = new UI.Panel();
  47. var geometryFaces = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  48. geometryFacesRow.add( new UI.Text().setValue( 'Faces' ).setColor( '#666' ) );
  49. geometryFacesRow.add( geometryFaces );
  50. container.add( geometryFacesRow );
  51. //
  52. var selected = null;
  53. function update() {
  54. if ( selected ) {
  55. selected.name = geometryName.getValue();
  56. }
  57. }
  58. signals.objectSelected.add( function ( object ) {
  59. if ( object && object.geometry ) {
  60. selected = object.geometry;
  61. container.setDisplay( 'block' );
  62. geometryName.setValue( object.geometry.name );
  63. geometryClass.setValue( getGeometryInstanceName( object.geometry ) );
  64. geometryVertices.setValue( object.geometry.vertices.length );
  65. geometryFaces.setValue( object.geometry.faces.length );
  66. } else {
  67. selected = null;
  68. container.setDisplay( 'none' );
  69. }
  70. } );
  71. function getGeometryInstanceName( geometry ) {
  72. for ( var key in geometries ) {
  73. if ( geometry instanceof geometries[ key ] ) return key;
  74. }
  75. }
  76. return container;
  77. }