Menubar.Add.js 7.8 KB

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