Menubar.Add.js 7.9 KB

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