Menubar.Add.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Menubar.Add = function ( editor ) {
  5. var container = new UI.Panel();
  6. container.setClass( 'menu' );
  7. var title = new UI.Panel();
  8. title.setClass( 'title' );
  9. title.setTextContent( 'Add' );
  10. container.add( title );
  11. var options = new UI.Panel();
  12. options.setClass( 'options' );
  13. container.add( options );
  14. //
  15. var meshCount = 0;
  16. var lightCount = 0;
  17. // Group
  18. var option = new UI.Panel();
  19. option.setClass( 'option' );
  20. option.setTextContent( 'Group' );
  21. option.onClick( function () {
  22. var mesh = new THREE.Group();
  23. mesh.name = 'Group ' + ( ++ meshCount );
  24. editor.addObject( mesh );
  25. editor.select( mesh );
  26. } );
  27. options.add( option );
  28. //
  29. options.add( new UI.HorizontalRule() );
  30. // Plane
  31. var option = new UI.Panel();
  32. option.setClass( 'option' );
  33. option.setTextContent( 'Plane' );
  34. option.onClick( function () {
  35. var width = 200;
  36. var height = 200;
  37. var widthSegments = 1;
  38. var heightSegments = 1;
  39. var geometry = new THREE.PlaneGeometry( width, height, widthSegments, heightSegments );
  40. var material = new THREE.MeshPhongMaterial();
  41. var mesh = new THREE.Mesh( geometry, material );
  42. mesh.name = 'Plane ' + ( ++ meshCount );
  43. editor.addObject( mesh );
  44. editor.select( mesh );
  45. } );
  46. options.add( option );
  47. // Box
  48. var option = new UI.Panel();
  49. option.setClass( 'option' );
  50. option.setTextContent( 'Box' );
  51. option.onClick( function () {
  52. var width = 100;
  53. var height = 100;
  54. var depth = 100;
  55. var widthSegments = 1;
  56. var heightSegments = 1;
  57. var depthSegments = 1;
  58. var geometry = new THREE.BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments );
  59. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  60. mesh.name = 'Box ' + ( ++ meshCount );
  61. editor.addObject( mesh );
  62. editor.select( mesh );
  63. } );
  64. options.add( option );
  65. // Circle
  66. var option = new UI.Panel();
  67. option.setClass( 'option' );
  68. option.setTextContent( 'Circle' );
  69. option.onClick( function () {
  70. var radius = 20;
  71. var segments = 8;
  72. var geometry = new THREE.CircleGeometry( radius, segments );
  73. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  74. mesh.name = 'Circle ' + ( ++ meshCount );
  75. editor.addObject( mesh );
  76. editor.select( mesh );
  77. } );
  78. options.add( option );
  79. // Cylinder
  80. var option = new UI.Panel();
  81. option.setClass( 'option' );
  82. option.setTextContent( 'Cylinder' );
  83. option.onClick( function () {
  84. var radiusTop = 20;
  85. var radiusBottom = 20;
  86. var height = 100;
  87. var radiusSegments = 8;
  88. var heightSegments = 1;
  89. var openEnded = false;
  90. var geometry = new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  91. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  92. mesh.name = 'Cylinder ' + ( ++ meshCount );
  93. editor.addObject( mesh );
  94. editor.select( mesh );
  95. } );
  96. options.add( option );
  97. // Sphere
  98. var option = new UI.Panel();
  99. option.setClass( 'option' );
  100. option.setTextContent( 'Sphere' );
  101. option.onClick( function () {
  102. var radius = 75;
  103. var widthSegments = 32;
  104. var heightSegments = 16;
  105. var phiStart = 0;
  106. var phiLength = Math.PI * 2;
  107. var thetaStart = 0;
  108. var thetaLength = Math.PI;
  109. var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength );
  110. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  111. mesh.name = 'Sphere ' + ( ++ meshCount );
  112. editor.addObject( mesh );
  113. editor.select( mesh );
  114. } );
  115. options.add( option );
  116. // Icosahedron
  117. var option = new UI.Panel();
  118. option.setClass( 'option' );
  119. option.setTextContent( 'Icosahedron' );
  120. option.onClick( function () {
  121. var radius = 75;
  122. var detail = 2;
  123. var geometry = new THREE.IcosahedronGeometry( radius, detail );
  124. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  125. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  126. editor.addObject( mesh );
  127. editor.select( mesh );
  128. } );
  129. options.add( option );
  130. // Torus
  131. var option = new UI.Panel();
  132. option.setClass( 'option' );
  133. option.setTextContent( 'Torus' );
  134. option.onClick( function () {
  135. var radius = 100;
  136. var tube = 40;
  137. var radialSegments = 8;
  138. var tubularSegments = 6;
  139. var arc = Math.PI * 2;
  140. var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
  141. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  142. mesh.name = 'Torus ' + ( ++ meshCount );
  143. editor.addObject( mesh );
  144. editor.select( mesh );
  145. } );
  146. options.add( option );
  147. // TorusKnot
  148. var option = new UI.Panel();
  149. option.setClass( 'option' );
  150. option.setTextContent( 'TorusKnot' );
  151. option.onClick( function () {
  152. var radius = 100;
  153. var tube = 40;
  154. var radialSegments = 64;
  155. var tubularSegments = 8;
  156. var p = 2;
  157. var q = 3;
  158. var heightScale = 1;
  159. var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
  160. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  161. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  162. editor.addObject( mesh );
  163. editor.select( mesh );
  164. } );
  165. options.add( option );
  166. //
  167. options.add( new UI.HorizontalRule() );
  168. // Sprite
  169. var option = new UI.Panel();
  170. option.setClass( 'option' );
  171. option.setTextContent( 'Sprite' );
  172. option.onClick( function () {
  173. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  174. sprite.name = 'Sprite ' + ( ++ meshCount );
  175. editor.addObject( sprite );
  176. editor.select( sprite );
  177. } );
  178. options.add( option );
  179. //
  180. options.add( new UI.HorizontalRule() );
  181. // PointLight
  182. var option = new UI.Panel();
  183. option.setClass( 'option' );
  184. option.setTextContent( 'PointLight' );
  185. option.onClick( function () {
  186. var color = 0xffffff;
  187. var intensity = 1;
  188. var distance = 0;
  189. var light = new THREE.PointLight( color, intensity, distance );
  190. light.name = 'PointLight ' + ( ++ lightCount );
  191. editor.addObject( light );
  192. editor.select( light );
  193. } );
  194. options.add( option );
  195. // SpotLight
  196. var option = new UI.Panel();
  197. option.setClass( 'option' );
  198. option.setTextContent( 'SpotLight' );
  199. option.onClick( function () {
  200. var color = 0xffffff;
  201. var intensity = 1;
  202. var distance = 0;
  203. var angle = Math.PI * 0.1;
  204. var exponent = 10;
  205. var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
  206. light.name = 'SpotLight ' + ( ++ lightCount );
  207. light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
  208. light.position.set( 0.5, 1, 0.75 ).multiplyScalar( 200 );
  209. editor.addObject( light );
  210. editor.select( light );
  211. } );
  212. options.add( option );
  213. // DirectionalLight
  214. var option = new UI.Panel();
  215. option.setClass( 'option' );
  216. option.setTextContent( 'DirectionalLight' );
  217. option.onClick( function () {
  218. var color = 0xffffff;
  219. var intensity = 1;
  220. var light = new THREE.DirectionalLight( color, intensity );
  221. light.name = 'DirectionalLight ' + ( ++ lightCount );
  222. light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
  223. light.position.set( 0.5, 1, 0.75 ).multiplyScalar( 200 );
  224. editor.addObject( light );
  225. editor.select( light );
  226. } );
  227. options.add( option );
  228. // HemisphereLight
  229. var option = new UI.Panel();
  230. option.setClass( 'option' );
  231. option.setTextContent( 'HemisphereLight' );
  232. option.onClick( function () {
  233. var skyColor = 0x00aaff;
  234. var groundColor = 0xffaa00;
  235. var intensity = 1;
  236. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  237. light.name = 'HemisphereLight ' + ( ++ lightCount );
  238. light.position.set( 0.5, 1, 0.75 ).multiplyScalar( 200 );
  239. editor.addObject( light );
  240. editor.select( light );
  241. } );
  242. options.add( option );
  243. // AmbientLight
  244. var option = new UI.Panel();
  245. option.setClass( 'option' );
  246. option.setTextContent( 'AmbientLight' );
  247. option.onClick( function() {
  248. var color = 0x222222;
  249. var light = new THREE.AmbientLight( color );
  250. light.name = 'AmbientLight ' + ( ++ lightCount );
  251. editor.addObject( light );
  252. editor.select( light );
  253. } );
  254. options.add( option );
  255. return container;
  256. }