Menubar.Add.js 7.5 KB

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