Menubar.Add.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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.Row();
  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.execute( new AddObjectCommand( mesh ) );
  31. } );
  32. options.add( option );
  33. //
  34. options.add( new UI.HorizontalRule() );
  35. // Plane
  36. var option = new UI.Row();
  37. option.setClass( 'option' );
  38. option.setTextContent( 'Plane' );
  39. option.onClick( function () {
  40. var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
  41. var material = new THREE.MeshStandardMaterial();
  42. var mesh = new THREE.Mesh( geometry, material );
  43. mesh.name = 'Plane ' + ( ++ meshCount );
  44. editor.execute( new AddObjectCommand( mesh ) );
  45. } );
  46. options.add( option );
  47. // Box
  48. var option = new UI.Row();
  49. option.setClass( 'option' );
  50. option.setTextContent( 'Box' );
  51. option.onClick( function () {
  52. var geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
  53. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  54. mesh.name = 'Box ' + ( ++ meshCount );
  55. editor.execute( new AddObjectCommand( mesh ) );
  56. } );
  57. options.add( option );
  58. // Circle
  59. var option = new UI.Row();
  60. option.setClass( 'option' );
  61. option.setTextContent( 'Circle' );
  62. option.onClick( function () {
  63. var radius = 1;
  64. var segments = 32;
  65. var geometry = new THREE.CircleBufferGeometry( radius, segments );
  66. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  67. mesh.name = 'Circle ' + ( ++ meshCount );
  68. editor.execute( new AddObjectCommand( mesh ) );
  69. } );
  70. options.add( option );
  71. // Cylinder
  72. var option = new UI.Row();
  73. option.setClass( 'option' );
  74. option.setTextContent( 'Cylinder' );
  75. option.onClick( function () {
  76. var radiusTop = 1;
  77. var radiusBottom = 1;
  78. var height = 2;
  79. var radiusSegments = 32;
  80. var heightSegments = 1;
  81. var openEnded = false;
  82. var geometry = new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  83. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  84. mesh.name = 'Cylinder ' + ( ++ meshCount );
  85. editor.execute( new AddObjectCommand( mesh ) );
  86. } );
  87. options.add( option );
  88. // Sphere
  89. var option = new UI.Row();
  90. option.setClass( 'option' );
  91. option.setTextContent( 'Sphere' );
  92. option.onClick( function () {
  93. var radius = 1;
  94. var widthSegments = 32;
  95. var heightSegments = 16;
  96. var phiStart = 0;
  97. var phiLength = Math.PI * 2;
  98. var thetaStart = 0;
  99. var thetaLength = Math.PI;
  100. var geometry = new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength );
  101. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  102. mesh.name = 'Sphere ' + ( ++ meshCount );
  103. editor.execute( new AddObjectCommand( mesh ) );
  104. } );
  105. options.add( option );
  106. // Icosahedron
  107. var option = new UI.Row();
  108. option.setClass( 'option' );
  109. option.setTextContent( 'Icosahedron' );
  110. option.onClick( function () {
  111. var radius = 1;
  112. var detail = 2;
  113. var geometry = new THREE.IcosahedronGeometry( radius, detail );
  114. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  115. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  116. editor.execute( new AddObjectCommand( mesh ) );
  117. } );
  118. options.add( option );
  119. // Torus
  120. var option = new UI.Row();
  121. option.setClass( 'option' );
  122. option.setTextContent( 'Torus' );
  123. option.onClick( function () {
  124. var radius = 2;
  125. var tube = 1;
  126. var radialSegments = 32;
  127. var tubularSegments = 12;
  128. var arc = Math.PI * 2;
  129. var geometry = new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc );
  130. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  131. mesh.name = 'Torus ' + ( ++ meshCount );
  132. editor.execute( new AddObjectCommand( mesh ) );
  133. } );
  134. options.add( option );
  135. // TorusKnot
  136. var option = new UI.Row();
  137. option.setClass( 'option' );
  138. option.setTextContent( 'TorusKnot' );
  139. option.onClick( function () {
  140. var radius = 2;
  141. var tube = 0.8;
  142. var tubularSegments = 64;
  143. var radialSegments = 12;
  144. var p = 2;
  145. var q = 3;
  146. var geometry = new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q );
  147. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  148. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  149. editor.execute( new AddObjectCommand( mesh ) );
  150. } );
  151. options.add( option );
  152. /*
  153. // Teapot
  154. var option = new UI.Row();
  155. option.setClass( 'option' );
  156. option.setTextContent( 'Teapot' );
  157. option.onClick( function () {
  158. var size = 50;
  159. var segments = 10;
  160. var bottom = true;
  161. var lid = true;
  162. var body = true;
  163. var fitLid = false;
  164. var blinnScale = true;
  165. var material = new THREE.MeshStandardMaterial();
  166. var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
  167. var mesh = new THREE.Mesh( geometry, material );
  168. mesh.name = 'Teapot ' + ( ++ meshCount );
  169. editor.addObject( mesh );
  170. editor.select( mesh );
  171. } );
  172. options.add( option );
  173. */
  174. // Lathe
  175. var option = new UI.Row();
  176. option.setClass( 'option' );
  177. option.setTextContent( 'Lathe' );
  178. option.onClick( function() {
  179. var points = [
  180. new THREE.Vector2( 0, 0 ),
  181. new THREE.Vector2( 4, 0 ),
  182. new THREE.Vector2( 3.5, 0.5 ),
  183. new THREE.Vector2( 1, 0.75 ),
  184. new THREE.Vector2( 0.8, 1 ),
  185. new THREE.Vector2( 0.8, 4 ),
  186. new THREE.Vector2( 1, 4.2 ),
  187. new THREE.Vector2( 1.4, 4.8 ),
  188. new THREE.Vector2( 2, 5 ),
  189. new THREE.Vector2( 2.5, 5.4 ),
  190. new THREE.Vector2( 3, 12 )
  191. ];
  192. var segments = 20;
  193. var phiStart = 0;
  194. var phiLength = 2 * Math.PI;
  195. var geometry = new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength );
  196. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
  197. mesh.name = 'Lathe ' + ( ++ meshCount );
  198. editor.execute( new AddObjectCommand( mesh ) );
  199. } );
  200. options.add( option );
  201. // Sprite
  202. var option = new UI.Row();
  203. option.setClass( 'option' );
  204. option.setTextContent( 'Sprite' );
  205. option.onClick( function () {
  206. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  207. sprite.name = 'Sprite ' + ( ++ meshCount );
  208. editor.execute( new AddObjectCommand( sprite ) );
  209. } );
  210. options.add( option );
  211. //
  212. options.add( new UI.HorizontalRule() );
  213. // PointLight
  214. var option = new UI.Row();
  215. option.setClass( 'option' );
  216. option.setTextContent( 'PointLight' );
  217. option.onClick( function () {
  218. var color = 0xffffff;
  219. var intensity = 1;
  220. var distance = 0;
  221. var light = new THREE.PointLight( color, intensity, distance );
  222. light.name = 'PointLight ' + ( ++ lightCount );
  223. editor.execute( new AddObjectCommand( light ) );
  224. } );
  225. options.add( option );
  226. // SpotLight
  227. var option = new UI.Row();
  228. option.setClass( 'option' );
  229. option.setTextContent( 'SpotLight' );
  230. option.onClick( function () {
  231. var color = 0xffffff;
  232. var intensity = 1;
  233. var distance = 0;
  234. var angle = Math.PI * 0.1;
  235. var penumbra = 0;
  236. var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
  237. light.name = 'SpotLight ' + ( ++ lightCount );
  238. light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
  239. light.position.set( 5, 10, 7.5 );
  240. editor.execute( new AddObjectCommand( light ) );
  241. } );
  242. options.add( option );
  243. // DirectionalLight
  244. var option = new UI.Row();
  245. option.setClass( 'option' );
  246. option.setTextContent( 'DirectionalLight' );
  247. option.onClick( function () {
  248. var color = 0xffffff;
  249. var intensity = 1;
  250. var light = new THREE.DirectionalLight( color, intensity );
  251. light.name = 'DirectionalLight ' + ( ++ lightCount );
  252. light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
  253. light.position.set( 5, 10, 7.5 );
  254. editor.execute( new AddObjectCommand( light ) );
  255. } );
  256. options.add( option );
  257. // HemisphereLight
  258. var option = new UI.Row();
  259. option.setClass( 'option' );
  260. option.setTextContent( 'HemisphereLight' );
  261. option.onClick( function () {
  262. var skyColor = 0x00aaff;
  263. var groundColor = 0xffaa00;
  264. var intensity = 1;
  265. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  266. light.name = 'HemisphereLight ' + ( ++ lightCount );
  267. light.position.set( 0, 10, 0 );
  268. editor.execute( new AddObjectCommand( light ) );
  269. } );
  270. options.add( option );
  271. // AmbientLight
  272. var option = new UI.Row();
  273. option.setClass( 'option' );
  274. option.setTextContent( 'AmbientLight' );
  275. option.onClick( function() {
  276. var color = 0x222222;
  277. var light = new THREE.AmbientLight( color );
  278. light.name = 'AmbientLight ' + ( ++ lightCount );
  279. editor.execute( new AddObjectCommand( light ) );
  280. } );
  281. options.add( option );
  282. //
  283. options.add( new UI.HorizontalRule() );
  284. // PerspectiveCamera
  285. var option = new UI.Row();
  286. option.setClass( 'option' );
  287. option.setTextContent( 'PerspectiveCamera' );
  288. option.onClick( function() {
  289. var camera = new THREE.PerspectiveCamera( 50, 1, 1, 10000 );
  290. camera.name = 'PerspectiveCamera ' + ( ++ cameraCount );
  291. editor.execute( new AddObjectCommand( camera ) );
  292. } );
  293. options.add( option );
  294. return container;
  295. }