Menubar.Add.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. Menubar.Add = function ( signals ) {
  2. var container = new UI.Panel();
  3. container.setClass( 'menu' );
  4. container.onMouseOver( function () { options.setDisplay( 'block' ) } );
  5. container.onMouseOut( function () { options.setDisplay( 'none' ) } );
  6. container.onClick( function () { options.setDisplay( 'block' ) } );
  7. var title = new UI.Panel();
  8. title.setTextContent( 'Add' ).setColor( '#666' );
  9. title.setMargin( '0px' );
  10. title.setPadding( '8px' );
  11. container.add( title );
  12. //
  13. var options = new UI.Panel();
  14. options.setClass( 'options' );
  15. options.setDisplay( 'none' );
  16. container.add( options );
  17. // add plane
  18. var option = new UI.Panel();
  19. option.setClass( 'option' );
  20. option.setTextContent( 'Plane' );
  21. option.onClick( function () {
  22. var width = 200;
  23. var height = 200;
  24. var widthSegments = 1;
  25. var heightSegments = 1;
  26. var geometry = new THREE.PlaneGeometry( width, height, widthSegments, heightSegments );
  27. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  28. mesh.name = 'Plane ' + mesh.id;
  29. mesh.rotation.x = - Math.PI/2;
  30. signals.objectAdded.dispatch( mesh );
  31. } );
  32. options.add( option );
  33. // add cube
  34. var option = new UI.Panel();
  35. option.setClass( 'option' );
  36. option.setTextContent( 'Cube' );
  37. option.onClick( function () {
  38. var width = 100;
  39. var height = 100;
  40. var depth = 100;
  41. var widthSegments = 1;
  42. var heightSegments = 1;
  43. var depthSegments = 1;
  44. var geometry = new THREE.CubeGeometry( width, height, depth, widthSegments, heightSegments, depthSegments );
  45. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  46. mesh.name = 'Cube ' + mesh.id;
  47. signals.objectAdded.dispatch( mesh );
  48. } );
  49. options.add( option );
  50. // add cylinder
  51. var option = new UI.Panel();
  52. option.setClass( 'option' );
  53. option.setTextContent( 'Cylinder' );
  54. option.onClick( function () {
  55. var radiusTop = 20;
  56. var radiusBottom = 20;
  57. var height = 100;
  58. var radiusSegments = 8;
  59. var heightSegments = 1;
  60. var openEnded = false;
  61. var geometry = new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  62. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  63. mesh.name = 'Cylinder ' + mesh.id;
  64. signals.objectAdded.dispatch( mesh );
  65. } );
  66. options.add( option );
  67. // add sphere
  68. var option = new UI.Panel();
  69. option.setClass( 'option' );
  70. option.setTextContent( 'Sphere' );
  71. option.onClick( function () {
  72. var radius = 75;
  73. var widthSegments = 32;
  74. var heightSegments = 16;
  75. var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
  76. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  77. mesh.name = 'Sphere ' + mesh.id;
  78. signals.objectAdded.dispatch( mesh );
  79. } );
  80. options.add( option );
  81. // add icosahedron
  82. var option = new UI.Panel();
  83. option.setClass( 'option' );
  84. option.setTextContent( 'Icosahedron' );
  85. option.onClick( function () {
  86. var radius = 75;
  87. var detail = 2;
  88. var geometry = new THREE.IcosahedronGeometry ( radius, detail );
  89. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  90. mesh.name = 'Icosahedron ' + mesh.id;
  91. signals.objectAdded.dispatch( mesh );
  92. } );
  93. options.add( option );
  94. // add torus
  95. var option = new UI.Panel();
  96. option.setClass( 'option' );
  97. option.setTextContent( 'Torus' );
  98. option.onClick( function () {
  99. var radius = 100;
  100. var tube = 40;
  101. var radialSegments = 8;
  102. var tubularSegments = 6;
  103. var arc = Math.PI * 2;
  104. var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
  105. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  106. mesh.name = 'Torus ' + mesh.id;
  107. signals.objectAdded.dispatch( mesh );
  108. } );
  109. options.add( option );
  110. // add torus knot
  111. var option = new UI.Panel();
  112. option.setClass( 'option' );
  113. option.setTextContent( 'TorusKnot' );
  114. option.onClick( function () {
  115. var radius = 100;
  116. var tube = 40;
  117. var radialSegments = 64;
  118. var tubularSegments = 8;
  119. var p = 2;
  120. var q = 3;
  121. var heightScale = 1;
  122. var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
  123. var mesh = new THREE.Mesh( geometry, createDummyMaterial( geometry ) );
  124. mesh.name = 'TorusKnot ' + mesh.id;
  125. signals.objectAdded.dispatch( mesh );
  126. } );
  127. options.add( option );
  128. // divider
  129. options.add( new UI.HorizontalRule() );
  130. // add point light
  131. var option = new UI.Panel();
  132. option.setClass( 'option' );
  133. option.setTextContent( 'Point light' );
  134. option.onClick( function () {
  135. var color = 0xffffff;
  136. var intensity = 1;
  137. var distance = 0;
  138. var light = new THREE.PointLight( color, intensity, distance );
  139. light.name = 'PointLight ' + light.id;
  140. signals.objectAdded.dispatch( light );
  141. } );
  142. options.add( option );
  143. // add spot light
  144. var option = new UI.Panel();
  145. option.setClass( 'option' );
  146. option.setTextContent( 'Spot light' );
  147. option.onClick( function () {
  148. var color = 0xffffff;
  149. var intensity = 1;
  150. var distance = 0;
  151. var angle = Math.PI * 0.1;
  152. var exponent = 10;
  153. var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
  154. light.name = 'SpotLight ' + light.id;
  155. light.target.name = 'SpotLight ' + light.id + ' Target';
  156. light.position.set( 0, 1, 0 ).multiplyScalar( 200 );
  157. signals.objectAdded.dispatch( light );
  158. } );
  159. options.add( option );
  160. // add directional light
  161. var option = new UI.Panel();
  162. option.setClass( 'option' );
  163. option.setTextContent( 'Directional light' );
  164. option.onClick( function () {
  165. var color = 0xffffff;
  166. var intensity = 1;
  167. var light = new THREE.DirectionalLight( color, intensity );
  168. light.name = 'DirectionalLight ' + light.id;
  169. light.target.name = 'DirectionalLight ' + light.id + ' Target';
  170. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  171. signals.objectAdded.dispatch( light );
  172. } );
  173. options.add( option );
  174. // add hemisphere light
  175. var option = new UI.Panel();
  176. option.setClass( 'option' );
  177. option.setTextContent( 'Hemisphere light' );
  178. option.onClick( function () {
  179. var skyColor = 0x00aaff;
  180. var groundColor = 0xffaa00;
  181. var intensity = 1;
  182. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  183. light.name = 'HemisphereLight ' + light.id;
  184. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  185. signals.objectAdded.dispatch( light );
  186. } );
  187. options.add( option );
  188. // add ambient light
  189. var option = new UI.Panel();
  190. option.setClass( 'option' );
  191. option.setTextContent( 'Ambient light' );
  192. option.onClick( function () {
  193. var color = 0x222222;
  194. var light = new THREE.AmbientLight( color );
  195. light.name = 'AmbientLight ' + light.id;
  196. signals.objectAdded.dispatch( light );
  197. } );
  198. options.add( option );
  199. //
  200. function createDummyMaterial() {
  201. return new THREE.MeshPhongMaterial();
  202. };
  203. return container;
  204. }