Menubar.Add.js 8.0 KB

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