Menubar.Add.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. var cameraCount = 0;
  18. editor.signals.editorCleared.add( function () {
  19. meshCount = 0;
  20. lightCount = 0;
  21. cameraCount = 0;
  22. } );
  23. // Group
  24. var option = new UI.Panel();
  25. option.setClass( 'option' );
  26. option.setTextContent( 'Group' );
  27. option.onClick( function () {
  28. var mesh = new THREE.Group();
  29. mesh.name = 'Group ' + ( ++ meshCount );
  30. editor.addObject( mesh );
  31. editor.select( mesh );
  32. } );
  33. options.add( option );
  34. //
  35. options.add( new UI.HorizontalRule() );
  36. // Plane
  37. var option = new UI.Panel();
  38. option.setClass( 'option' );
  39. option.setTextContent( 'Plane' );
  40. option.onClick( function () {
  41. var width = 200;
  42. var height = 200;
  43. var widthSegments = 1;
  44. var heightSegments = 1;
  45. var geometry = new THREE.PlaneGeometry( width, height, widthSegments, heightSegments );
  46. var material = new THREE.MeshPhongMaterial();
  47. var mesh = new THREE.Mesh( geometry, material );
  48. mesh.name = 'Plane ' + ( ++ meshCount );
  49. editor.addObject( mesh );
  50. editor.select( mesh );
  51. } );
  52. options.add( option );
  53. // Box
  54. var option = new UI.Panel();
  55. option.setClass( 'option' );
  56. option.setTextContent( 'Box' );
  57. option.onClick( function () {
  58. var width = 100;
  59. var height = 100;
  60. var depth = 100;
  61. var widthSegments = 1;
  62. var heightSegments = 1;
  63. var depthSegments = 1;
  64. var geometry = new THREE.BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments );
  65. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  66. mesh.name = 'Box ' + ( ++ meshCount );
  67. editor.addObject( mesh );
  68. editor.select( mesh );
  69. } );
  70. options.add( option );
  71. // Circle
  72. var option = new UI.Panel();
  73. option.setClass( 'option' );
  74. option.setTextContent( 'Circle' );
  75. option.onClick( function () {
  76. var radius = 20;
  77. var segments = 32;
  78. var geometry = new THREE.CircleGeometry( radius, segments );
  79. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  80. mesh.name = 'Circle ' + ( ++ meshCount );
  81. editor.addObject( mesh );
  82. editor.select( mesh );
  83. } );
  84. options.add( option );
  85. // Cylinder
  86. var option = new UI.Panel();
  87. option.setClass( 'option' );
  88. option.setTextContent( 'Cylinder' );
  89. option.onClick( function () {
  90. var radiusTop = 20;
  91. var radiusBottom = 20;
  92. var height = 100;
  93. var radiusSegments = 32;
  94. var heightSegments = 1;
  95. var openEnded = false;
  96. var geometry = new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  97. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  98. mesh.name = 'Cylinder ' + ( ++ meshCount );
  99. editor.addObject( mesh );
  100. editor.select( mesh );
  101. } );
  102. options.add( option );
  103. // Sphere
  104. var option = new UI.Panel();
  105. option.setClass( 'option' );
  106. option.setTextContent( 'Sphere' );
  107. option.onClick( function () {
  108. var radius = 75;
  109. var widthSegments = 32;
  110. var heightSegments = 16;
  111. var phiStart = 0;
  112. var phiLength = Math.PI * 2;
  113. var thetaStart = 0;
  114. var thetaLength = Math.PI;
  115. var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength );
  116. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  117. mesh.name = 'Sphere ' + ( ++ meshCount );
  118. editor.addObject( mesh );
  119. editor.select( mesh );
  120. } );
  121. options.add( option );
  122. // Icosahedron
  123. var option = new UI.Panel();
  124. option.setClass( 'option' );
  125. option.setTextContent( 'Icosahedron' );
  126. option.onClick( function () {
  127. var radius = 75;
  128. var detail = 2;
  129. var geometry = new THREE.IcosahedronGeometry( radius, detail );
  130. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  131. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  132. editor.addObject( mesh );
  133. editor.select( mesh );
  134. } );
  135. options.add( option );
  136. // Torus
  137. var option = new UI.Panel();
  138. option.setClass( 'option' );
  139. option.setTextContent( 'Torus' );
  140. option.onClick( function () {
  141. var radius = 100;
  142. var tube = 40;
  143. var radialSegments = 8;
  144. var tubularSegments = 6;
  145. var arc = Math.PI * 2;
  146. var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
  147. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  148. mesh.name = 'Torus ' + ( ++ meshCount );
  149. editor.addObject( mesh );
  150. editor.select( mesh );
  151. } );
  152. options.add( option );
  153. // TorusKnot
  154. var option = new UI.Panel();
  155. option.setClass( 'option' );
  156. option.setTextContent( 'TorusKnot' );
  157. option.onClick( function () {
  158. var radius = 100;
  159. var tube = 40;
  160. var radialSegments = 64;
  161. var tubularSegments = 8;
  162. var p = 2;
  163. var q = 3;
  164. var heightScale = 1;
  165. var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
  166. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  167. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  168. editor.addObject( mesh );
  169. editor.select( mesh );
  170. } );
  171. options.add( option );
  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. //
  260. options.add( new UI.HorizontalRule() );
  261. // PerspectiveCamera
  262. var option = new UI.Panel();
  263. option.setClass( 'option' );
  264. option.setTextContent( 'PerspectiveCamera' );
  265. option.onClick( function() {
  266. var camera = new THREE.PerspectiveCamera( 50, 1, 1, 10000 );
  267. camera.name = 'PerspectiveCamera ' + ( ++ cameraCount );
  268. editor.addObject( camera );
  269. editor.select( camera );
  270. } );
  271. options.add( option );
  272. return container;
  273. }