Menubar.Add.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
  103. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  104. mesh.name = 'Sphere ' + ( ++ meshCount );
  105. editor.addObject( mesh );
  106. editor.select( mesh );
  107. } );
  108. options.add( option );
  109. // Icosahedron
  110. var option = new UI.Panel();
  111. option.setClass( 'option' );
  112. option.setTextContent( 'Icosahedron' );
  113. option.onClick( function () {
  114. var radius = 75;
  115. var detail = 2;
  116. var geometry = new THREE.IcosahedronGeometry( radius, detail );
  117. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  118. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  119. editor.addObject( mesh );
  120. editor.select( mesh );
  121. } );
  122. options.add( option );
  123. // Torus
  124. var option = new UI.Panel();
  125. option.setClass( 'option' );
  126. option.setTextContent( 'Torus' );
  127. option.onClick( function () {
  128. var radius = 100;
  129. var tube = 40;
  130. var radialSegments = 8;
  131. var tubularSegments = 6;
  132. var arc = Math.PI * 2;
  133. var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
  134. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  135. mesh.name = 'Torus ' + ( ++ meshCount );
  136. editor.addObject( mesh );
  137. editor.select( mesh );
  138. } );
  139. options.add( option );
  140. // TorusKnot
  141. var option = new UI.Panel();
  142. option.setClass( 'option' );
  143. option.setTextContent( 'TorusKnot' );
  144. option.onClick( function () {
  145. var radius = 100;
  146. var tube = 40;
  147. var radialSegments = 64;
  148. var tubularSegments = 8;
  149. var p = 2;
  150. var q = 3;
  151. var heightScale = 1;
  152. var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
  153. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  154. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  155. editor.addObject( mesh );
  156. editor.select( mesh );
  157. } );
  158. options.add( option );
  159. //
  160. options.add( new UI.HorizontalRule() );
  161. // Sprite
  162. var option = new UI.Panel();
  163. option.setClass( 'option' );
  164. option.setTextContent( 'Sprite' );
  165. option.onClick( function () {
  166. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  167. sprite.name = 'Sprite ' + ( ++ meshCount );
  168. editor.addObject( sprite );
  169. editor.select( sprite );
  170. } );
  171. options.add( option );
  172. //
  173. options.add( new UI.HorizontalRule() );
  174. // PointLight
  175. var option = new UI.Panel();
  176. option.setClass( 'option' );
  177. option.setTextContent( 'PointLight' );
  178. option.onClick( function () {
  179. var color = 0xffffff;
  180. var intensity = 1;
  181. var distance = 0;
  182. var light = new THREE.PointLight( color, intensity, distance );
  183. light.name = 'PointLight ' + ( ++ lightCount );
  184. editor.addObject( light );
  185. editor.select( light );
  186. } );
  187. options.add( option );
  188. // SpotLight
  189. var option = new UI.Panel();
  190. option.setClass( 'option' );
  191. option.setTextContent( 'SpotLight' );
  192. option.onClick( function () {
  193. var color = 0xffffff;
  194. var intensity = 1;
  195. var distance = 0;
  196. var angle = Math.PI * 0.1;
  197. var exponent = 10;
  198. var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
  199. light.name = 'SpotLight ' + ( ++ lightCount );
  200. light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
  201. light.position.set( 0, 1, 0 ).multiplyScalar( 200 );
  202. editor.addObject( light );
  203. editor.select( light );
  204. } );
  205. options.add( option );
  206. // DirectionalLight
  207. var option = new UI.Panel();
  208. option.setClass( 'option' );
  209. option.setTextContent( 'DirectionalLight' );
  210. option.onClick( function () {
  211. var color = 0xffffff;
  212. var intensity = 1;
  213. var light = new THREE.DirectionalLight( color, intensity );
  214. light.name = 'DirectionalLight ' + ( ++ lightCount );
  215. light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
  216. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  217. editor.addObject( light );
  218. editor.select( light );
  219. } );
  220. options.add( option );
  221. // HemisphereLight
  222. var option = new UI.Panel();
  223. option.setClass( 'option' );
  224. option.setTextContent( 'HemisphereLight' );
  225. option.onClick( function () {
  226. var skyColor = 0x00aaff;
  227. var groundColor = 0xffaa00;
  228. var intensity = 1;
  229. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  230. light.name = 'HemisphereLight ' + ( ++ lightCount );
  231. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  232. editor.addObject( light );
  233. editor.select( light );
  234. } );
  235. options.add( option );
  236. // AmbientLight
  237. var option = new UI.Panel();
  238. option.setClass( 'option' );
  239. option.setTextContent( 'AmbientLight' );
  240. option.onClick( function() {
  241. var color = 0x222222;
  242. var light = new THREE.AmbientLight( color );
  243. light.name = 'AmbientLight ' + ( ++ lightCount );
  244. editor.addObject( light );
  245. editor.select( light );
  246. } );
  247. options.add( option );
  248. return container;
  249. }