Menubar.Add.js 6.7 KB

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