Menubar.Add.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. Menubar.Add = function ( signals ) {
  2. var container = new UI.Panel();
  3. container.setFloat( 'left' );
  4. container.setWidth( '50px' );
  5. container.setCursor( 'pointer' );
  6. container.onMouseOver( function () { options.setDisplay( '' ) } );
  7. container.onMouseOut( function () { options.setDisplay( 'none' ) } );
  8. container.onClick( function () { options.setDisplay( 'none' ) } );
  9. var title = new UI.Panel();
  10. title.setTextContent( 'Add' ).setColor( '#666' );
  11. title.setMargin( '0px' );
  12. title.setPadding( '8px' )
  13. container.add( title );
  14. //
  15. var options = new UI.Panel();
  16. options.setWidth( '140px' );
  17. options.setBackgroundColor( '#ddd' );
  18. options.setPadding( '0px' );
  19. options.setBorderTop( 'solid 1px #ccc' );
  20. options.setStyle( 'box-shadow', [ '0 3px 6px rgba(0,0,0,0.1), 3px 3px 6px rgba(0,0,0,0.2)' ] );
  21. options.setDisplay( 'none' );
  22. container.add( options );
  23. // add sphere
  24. var option = new UI.Panel();
  25. option.setTextContent( 'Sphere' ).setColor( '#666' ).setPadding( '6px 12px' );
  26. option.onClick( function () {
  27. var radius = 75;
  28. var widthSegments = 32;
  29. var heightSegments = 16;
  30. var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
  31. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  32. mesh.name = 'Sphere ' + mesh.id;
  33. signals.objectAdded.dispatch( mesh );
  34. } );
  35. options.add( option );
  36. addHoverStyle( option );
  37. // add cube
  38. var option = new UI.Panel();
  39. option.setTextContent( 'Cube' ).setColor( '#666' ).setPadding( '6px 12px' );
  40. option.onClick( function () {
  41. var width = 100;
  42. var height = 100;
  43. var depth = 100;
  44. var widthSegments = 1;
  45. var heightSegments = 1;
  46. var depthSegments = 1;
  47. var geometry = new THREE.CubeGeometry( width, height, depth, widthSegments, heightSegments, depthSegments );
  48. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  49. mesh.name = 'Cube ' + mesh.id;
  50. signals.objectAdded.dispatch( mesh );
  51. } );
  52. options.add( option );
  53. addHoverStyle( option );
  54. // add plane
  55. var option = new UI.Panel();
  56. option.setTextContent( 'Plane' ).setColor( '#666' ).setPadding( '6px 12px' );
  57. option.onClick( function () {
  58. var width = 200;
  59. var height = 200;
  60. var widthSegments = 1;
  61. var heightSegments = 1;
  62. var geometry = new THREE.PlaneGeometry( width, height, widthSegments, heightSegments );
  63. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  64. mesh.name = 'Plane ' + mesh.id;
  65. mesh.rotation.x = - Math.PI/2;
  66. signals.objectAdded.dispatch( mesh );
  67. } );
  68. options.add( option );
  69. addHoverStyle( option );
  70. //
  71. function addHoverStyle( element ) {
  72. element.onMouseOver( function () { element.setBackgroundColor( '#356' ).setColor( '#eee' ); } );
  73. element.onMouseOut( function () { element.setBackgroundColor( 'transparent' ).setColor( '#666' ) } );
  74. }
  75. function createDummyMaterial() {
  76. return new THREE.MeshPhongMaterial();
  77. };
  78. return container;
  79. }