Menubar.Add.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Menubar.Add = function ( editor ) {
  5. var strings = editor.strings;
  6. var container = new UI.Panel();
  7. container.setClass( 'menu' );
  8. var title = new UI.Panel();
  9. title.setClass( 'title' );
  10. title.setTextContent( strings.getKey( 'menubar/add' ) );
  11. container.add( title );
  12. var options = new UI.Panel();
  13. options.setClass( 'options' );
  14. container.add( options );
  15. // Group
  16. var option = new UI.Row();
  17. option.setClass( 'option' );
  18. option.setTextContent( strings.getKey( 'menubar/add/group' ) );
  19. option.onClick( function () {
  20. var mesh = new THREE.Group();
  21. mesh.name = 'Group';
  22. editor.execute( new AddObjectCommand( editor, mesh ) );
  23. } );
  24. options.add( option );
  25. //
  26. options.add( new UI.HorizontalRule() );
  27. // Box
  28. var option = new UI.Row();
  29. option.setClass( 'option' );
  30. option.setTextContent( strings.getKey( 'menubar/add/box' ) );
  31. option.onClick( function () {
  32. var geometry = new THREE.BoxBufferGeometry( 1, 1, 1, 1, 1, 1 );
  33. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  34. mesh.name = 'Box';
  35. editor.execute( new AddObjectCommand( editor, mesh ) );
  36. } );
  37. options.add( option );
  38. // Circle
  39. var option = new UI.Row();
  40. option.setClass( 'option' );
  41. option.setTextContent( strings.getKey( 'menubar/add/circle' ) );
  42. option.onClick( function () {
  43. var geometry = new THREE.CircleBufferGeometry( 1, 8, 0, Math.PI * 2 );
  44. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  45. mesh.name = 'Circle';
  46. editor.execute( new AddObjectCommand( editor, mesh ) );
  47. } );
  48. options.add( option );
  49. // Cylinder
  50. var option = new UI.Row();
  51. option.setClass( 'option' );
  52. option.setTextContent( strings.getKey( 'menubar/add/cylinder' ) );
  53. option.onClick( function () {
  54. var geometry = new THREE.CylinderBufferGeometry( 1, 1, 1, 8, 1, false, 0, Math.PI * 2 );
  55. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  56. mesh.name = 'Cylinder';
  57. editor.execute( new AddObjectCommand( editor, mesh ) );
  58. } );
  59. options.add( option );
  60. // Icosahedron
  61. var option = new UI.Row();
  62. option.setClass( 'option' );
  63. option.setTextContent( strings.getKey( 'menubar/add/icosahedron' ) );
  64. option.onClick( function () {
  65. var geometry = new THREE.IcosahedronBufferGeometry( 1, 0 );
  66. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  67. mesh.name = 'Icosahedron';
  68. editor.execute( new AddObjectCommand( editor, mesh ) );
  69. } );
  70. options.add( option );
  71. // Lathe
  72. var option = new UI.Row();
  73. option.setClass( 'option' );
  74. option.setTextContent( strings.getKey( 'menubar/add/lathe' ) );
  75. option.onClick( function () {
  76. var points = [
  77. new THREE.Vector2( 0, 0 ),
  78. new THREE.Vector2( 0.4, 0 ),
  79. new THREE.Vector2( 0.35, 0.05 ),
  80. new THREE.Vector2( 0.1, 0.075 ),
  81. new THREE.Vector2( 0.08, 0.1 ),
  82. new THREE.Vector2( 0.08, 0.4 ),
  83. new THREE.Vector2( 0.1, 0.42 ),
  84. new THREE.Vector2( 0.14, 0.48 ),
  85. new THREE.Vector2( 0.2, 0.5 ),
  86. new THREE.Vector2( 0.25, 0.54 ),
  87. new THREE.Vector2( 0.3, 1.2 )
  88. ];
  89. var geometry = new THREE.LatheBufferGeometry( points, 12, 0, Math.PI * 2 );
  90. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
  91. mesh.name = 'Lathe';
  92. editor.execute( new AddObjectCommand( editor, mesh ) );
  93. } );
  94. options.add( option );
  95. // Octahedron
  96. var option = new UI.Row();
  97. option.setClass( 'option' );
  98. option.setTextContent( strings.getKey( 'menubar/add/octahedron' ) );
  99. option.onClick( function () {
  100. var geometry = new THREE.OctahedronBufferGeometry( 1, 0 );
  101. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  102. mesh.name = 'Octahedron';
  103. editor.execute( new AddObjectCommand( editor, mesh ) );
  104. } );
  105. options.add( option );
  106. // Plane
  107. var option = new UI.Row();
  108. option.setClass( 'option' );
  109. option.setTextContent( strings.getKey( 'menubar/add/plane' ) );
  110. option.onClick( function () {
  111. var geometry = new THREE.PlaneBufferGeometry( 1, 1, 1, 1 );
  112. var material = new THREE.MeshStandardMaterial();
  113. var mesh = new THREE.Mesh( geometry, material );
  114. mesh.name = 'Plane';
  115. editor.execute( new AddObjectCommand( editor, mesh ) );
  116. } );
  117. options.add( option )
  118. // Ring
  119. var option = new UI.Row();
  120. option.setClass( 'option' );
  121. option.setTextContent( strings.getKey( 'menubar/add/ring' ) );
  122. option.onClick( function () {
  123. var geometry = new THREE.RingBufferGeometry( 0.5, 1, 8, 1, 0, Math.PI * 2 );
  124. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  125. mesh.name = 'Ring';
  126. editor.execute( new AddObjectCommand( editor, mesh ) );
  127. } );
  128. options.add( option );
  129. // Sphere
  130. var option = new UI.Row();
  131. option.setClass( 'option' );
  132. option.setTextContent( strings.getKey( 'menubar/add/sphere' ) );
  133. option.onClick( function () {
  134. var geometry = new THREE.SphereBufferGeometry( 1, 8, 6, 0, Math.PI * 2, 0, Math.PI );
  135. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  136. mesh.name = 'Sphere';
  137. editor.execute( new AddObjectCommand( editor, mesh ) );
  138. } );
  139. options.add( option );
  140. // Sprite
  141. var option = new UI.Row();
  142. option.setClass( 'option' );
  143. option.setTextContent( strings.getKey( 'menubar/add/sprite' ) );
  144. option.onClick( function () {
  145. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  146. sprite.name = 'Sprite';
  147. editor.execute( new AddObjectCommand( editor, sprite ) );
  148. } );
  149. options.add( option );
  150. // Tetrahedron
  151. var option = new UI.Row();
  152. option.setClass( 'option' );
  153. option.setTextContent( strings.getKey( 'menubar/add/tetrahedron' ) );
  154. option.onClick( function () {
  155. var geometry = new THREE.TetrahedronBufferGeometry( 1, 0 );
  156. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  157. mesh.name = 'Tetrahedron';
  158. editor.execute( new AddObjectCommand( editor, mesh ) );
  159. } );
  160. options.add( option );
  161. // Torus
  162. var option = new UI.Row();
  163. option.setClass( 'option' );
  164. option.setTextContent( strings.getKey( 'menubar/add/torus' ) );
  165. option.onClick( function () {
  166. var geometry = new THREE.TorusBufferGeometry( 1, 0.4, 8, 6, Math.PI * 2 );
  167. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  168. mesh.name = 'Torus';
  169. editor.execute( new AddObjectCommand( editor, mesh ) );
  170. } );
  171. options.add( option );
  172. // TorusKnot
  173. var option = new UI.Row();
  174. option.setClass( 'option' );
  175. option.setTextContent( strings.getKey( 'menubar/add/torusknot' ) );
  176. option.onClick( function () {
  177. var geometry = new THREE.TorusKnotBufferGeometry( 1, 0.4, 64, 8, 2, 3 );
  178. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  179. mesh.name = 'TorusKnot';
  180. editor.execute( new AddObjectCommand( editor, mesh ) );
  181. } );
  182. options.add( option );
  183. // Tube
  184. var option = new UI.Row();
  185. option.setClass( 'option' );
  186. option.setTextContent( strings.getKey( 'menubar/add/tube' ) );
  187. option.onClick( function () {
  188. var path = new THREE.CatmullRomCurve3( [
  189. new THREE.Vector3( 2, 2, - 2 ),
  190. new THREE.Vector3( 2, - 2, - 0.6666666666666667 ),
  191. new THREE.Vector3( - 2, - 2, 0.6666666666666667 ),
  192. new THREE.Vector3( - 2, 2, 2 )
  193. ] );
  194. var geometry = new THREE.TubeBufferGeometry( path, 64, 1, 8, false );
  195. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  196. mesh.name = 'Tube';
  197. editor.execute( new AddObjectCommand( editor, mesh ) );
  198. } );
  199. options.add( option );
  200. /*
  201. // Teapot
  202. var option = new UI.Row();
  203. option.setClass( 'option' );
  204. option.setTextContent( 'Teapot' );
  205. option.onClick( function () {
  206. var size = 50;
  207. var segments = 10;
  208. var bottom = true;
  209. var lid = true;
  210. var body = true;
  211. var fitLid = false;
  212. var blinnScale = true;
  213. var material = new THREE.MeshStandardMaterial();
  214. var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
  215. var mesh = new THREE.Mesh( geometry, material );
  216. mesh.name = 'Teapot';
  217. editor.addObject( mesh );
  218. editor.select( mesh );
  219. } );
  220. options.add( option );
  221. */
  222. //
  223. options.add( new UI.HorizontalRule() );
  224. // AmbientLight
  225. var option = new UI.Row();
  226. option.setClass( 'option' );
  227. option.setTextContent( strings.getKey( 'menubar/add/ambientlight' ) );
  228. option.onClick( function () {
  229. var color = 0x222222;
  230. var light = new THREE.AmbientLight( color );
  231. light.name = 'AmbientLight';
  232. editor.execute( new AddObjectCommand( editor, light ) );
  233. } );
  234. options.add( option );
  235. // DirectionalLight
  236. var option = new UI.Row();
  237. option.setClass( 'option' );
  238. option.setTextContent( strings.getKey( 'menubar/add/directionallight' ) );
  239. option.onClick( function () {
  240. var color = 0xffffff;
  241. var intensity = 1;
  242. var light = new THREE.DirectionalLight( color, intensity );
  243. light.name = 'DirectionalLight';
  244. light.target.name = 'DirectionalLight Target';
  245. light.position.set( 5, 10, 7.5 );
  246. editor.execute( new AddObjectCommand( editor, light ) );
  247. } );
  248. options.add( option );
  249. // HemisphereLight
  250. var option = new UI.Row();
  251. option.setClass( 'option' );
  252. option.setTextContent( strings.getKey( 'menubar/add/hemispherelight' ) );
  253. option.onClick( function () {
  254. var skyColor = 0x00aaff;
  255. var groundColor = 0xffaa00;
  256. var intensity = 1;
  257. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  258. light.name = 'HemisphereLight';
  259. light.position.set( 0, 10, 0 );
  260. editor.execute( new AddObjectCommand( editor, light ) );
  261. } );
  262. options.add( option );
  263. // PointLight
  264. var option = new UI.Row();
  265. option.setClass( 'option' );
  266. option.setTextContent( strings.getKey( 'menubar/add/pointlight' ) );
  267. option.onClick( function () {
  268. var color = 0xffffff;
  269. var intensity = 1;
  270. var distance = 0;
  271. var light = new THREE.PointLight( color, intensity, distance );
  272. light.name = 'PointLight';
  273. editor.execute( new AddObjectCommand( editor, light ) );
  274. } );
  275. options.add( option );
  276. // SpotLight
  277. var option = new UI.Row();
  278. option.setClass( 'option' );
  279. option.setTextContent( strings.getKey( 'menubar/add/spotlight' ) );
  280. option.onClick( function () {
  281. var color = 0xffffff;
  282. var intensity = 1;
  283. var distance = 0;
  284. var angle = Math.PI * 0.1;
  285. var penumbra = 0;
  286. var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
  287. light.name = 'SpotLight';
  288. light.target.name = 'SpotLight Target';
  289. light.position.set( 5, 10, 7.5 );
  290. editor.execute( new AddObjectCommand( editor, light ) );
  291. } );
  292. options.add( option );
  293. //
  294. options.add( new UI.HorizontalRule() );
  295. // OrthographicCamera
  296. var option = new UI.Row();
  297. option.setClass( 'option' );
  298. option.setTextContent( strings.getKey( 'menubar/add/orthographiccamera' ) );
  299. option.onClick( function () {
  300. var camera = new THREE.OrthographicCamera();
  301. camera.name = 'OrthographicCamera';
  302. editor.execute( new AddObjectCommand( editor, camera ) );
  303. } );
  304. options.add( option );
  305. // PerspectiveCamera
  306. var option = new UI.Row();
  307. option.setClass( 'option' );
  308. option.setTextContent( strings.getKey( 'menubar/add/perspectivecamera' ) );
  309. option.onClick( function () {
  310. var camera = new THREE.PerspectiveCamera();
  311. camera.name = 'PerspectiveCamera';
  312. editor.execute( new AddObjectCommand( editor, camera ) );
  313. } );
  314. options.add( option );
  315. return container;
  316. };