Sidebar.Properties.Geometry.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Sidebar.Properties.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.setDisplay( 'none' );
  23. container.add( new UI.Text().setValue( 'GEOMETRY' ).setColor( '#666' ) );
  24. container.add( new UI.Button( 'absolute' ).setRight( '0px' ).setLabel( 'Export' ).onClick( exportGeometry ) );
  25. container.add( new UI.Break(), new UI.Break() );
  26. // name
  27. var geometryNameRow = new UI.Panel();
  28. var geometryName = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  29. geometryNameRow.add( new UI.Text().setValue( 'Name' ).setColor( '#666' ) );
  30. geometryNameRow.add( geometryName );
  31. container.add( geometryNameRow );
  32. // class
  33. var geometryClassRow = new UI.Panel();
  34. var geometryClass = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  35. geometryClassRow.add( new UI.Text().setValue( 'Class' ).setColor( '#666' ) );
  36. geometryClassRow.add( geometryClass );
  37. container.add( geometryClassRow );
  38. // vertices
  39. var geometryVerticesRow = new UI.Panel();
  40. var geometryVertices = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  41. geometryVerticesRow.add( new UI.Text().setValue( 'Vertices' ).setColor( '#666' ) );
  42. geometryVerticesRow.add( geometryVertices );
  43. container.add( geometryVerticesRow );
  44. // faces
  45. var geometryFacesRow = new UI.Panel();
  46. var geometryFaces = new UI.Text( 'absolute' ).setLeft( '100px' ).setColor( '#444' ).setFontSize( '12px' );
  47. geometryFacesRow.add( new UI.Text().setValue( 'Faces' ).setColor( '#666' ) );
  48. geometryFacesRow.add( geometryFaces );
  49. container.add( geometryFacesRow );
  50. container.add( new UI.Break() );
  51. //
  52. var selected = null;
  53. signals.objectSelected.add( function ( object ) {
  54. if ( object && object.geometry ) {
  55. selected = object.geometry;
  56. container.setDisplay( 'block' );
  57. geometryName.setValue( object.geometry.name );
  58. geometryClass.setValue( getGeometryInstanceName( object.geometry ) );
  59. geometryVertices.setValue( object.geometry.vertices.length );
  60. geometryFaces.setValue( object.geometry.faces.length );
  61. } else {
  62. selected = null;
  63. container.setDisplay( 'none' );
  64. }
  65. } );
  66. function getGeometryInstanceName( geometry ) {
  67. for ( var key in geometries ) {
  68. if ( geometry instanceof geometries[ key ] ) return key;
  69. }
  70. }
  71. function exportGeometry() {
  72. var output = new THREE.GeometryExporter().parse( selected );
  73. /*
  74. var blob = new Blob( [ output ], { type: 'text/json' } );
  75. var objectURL = URL.createObjectURL( blob );
  76. */
  77. }
  78. return container;
  79. }